spec/generators/api_generator_spec.rb in gris-0.3.4 vs spec/generators/api_generator_spec.rb in gris-0.3.6
- old
+ new
@@ -1,10 +1,10 @@
require 'spec_helper'
describe Gris::Generators::ApiGenerator do
include_context 'with generator'
- let(:api_name) { 'foo' }
+ let(:api_name) { 'article' }
before do
endpoints_directory_path = "#{generator_tmp_directory}/app/endpoints"
presenters_directory_path = "#{generator_tmp_directory}/app/presenters"
FileUtils.mkdir_p endpoints_directory_path
@@ -14,80 +14,81 @@
Gris::CLI::Base.new.generate('api', api_name)
end
describe 'app' do
it 'creates an endpoint class' do
- expected_api_file = File.join(generator_tmp_directory, 'app/endpoints/foos_endpoint.rb')
+ expected_api_file = File.join(generator_tmp_directory, 'app/endpoints/articles_endpoint.rb')
api_code = File.read(expected_api_file)
- expect(api_code).to match(/class FoosEndpoint/)
+ expect(api_code).to match(/class ArticlesEndpoint/)
end
it 'creates a model class' do
- expected_model_file = File.join(generator_tmp_directory, 'app/models/foo.rb')
+ expected_model_file = File.join(generator_tmp_directory, 'app/models/article.rb')
model_code = File.read(expected_model_file)
- expect(model_code).to match(/class Foo/)
+ expect(model_code).to match(/class Article/)
end
it 'creates an item presenter module' do
- expected_presenter_file = File.join(generator_tmp_directory, 'app/presenters/foo_presenter.rb')
+ expected_presenter_file = File.join(generator_tmp_directory, 'app/presenters/article_presenter.rb')
presenter_code = File.read(expected_presenter_file)
- expect(presenter_code).to match(/module FooPresenter/)
+ expect(presenter_code).to match(/module ArticlePresenter/)
end
it 'item presenter includes Gris::Presenter' do
- presenter_file = File.join(generator_tmp_directory, 'app/presenters/foo_presenter.rb')
+ presenter_file = File.join(generator_tmp_directory, 'app/presenters/article_presenter.rb')
require "./#{presenter_file}"
- expect(FooPresenter).to include(Gris::Presenter)
+ expect(ArticlePresenter).to include(Gris::Presenter)
end
it 'creates a collection presenter module' do
- expected_presenter_file = File.join(generator_tmp_directory, 'app/presenters/foos_presenter.rb')
+ expected_presenter_file = File.join(generator_tmp_directory, 'app/presenters/articles_presenter.rb')
presenter_code = File.read(expected_presenter_file)
- expect(presenter_code).to match(/module FoosPresenter/)
+ expect(presenter_code).to match(/module ArticlesPresenter/)
end
it 'collection presenter includes Gris::Presenter' do
- presenter_file = File.join(generator_tmp_directory, 'app/presenters/foos_presenter.rb')
+ presenter_file = File.join(generator_tmp_directory, 'app/presenters/articles_presenter.rb')
require "./#{presenter_file}"
- expect(FoosPresenter).to include(Gris::Presenter)
+ expect(ArticlesPresenter).to include(Gris::Presenter)
end
it 'collection presenter includes Gris::PaginatedPresenter' do
- presenter_file = File.join(generator_tmp_directory, 'app/presenters/foos_presenter.rb')
+ presenter_file = File.join(generator_tmp_directory, 'app/presenters/articles_presenter.rb')
require "./#{presenter_file}"
- expect(FoosPresenter).to include(Gris::PaginatedPresenter)
+ expect(ArticlesPresenter).to include(Gris::PaginatedPresenter)
end
it 'mounts new endpoint in ApplicationEndpoint' do
expected_endpoint_file = File.join(generator_tmp_directory, 'app/endpoints/application_endpoint.rb')
endpoint_file = File.read(expected_endpoint_file)
- expect(endpoint_file).to match(/mount FoosEndpoint/)
+ expect(endpoint_file).to match(/mount ArticlesEndpoint/)
end
it 'adds links to RootPresenter' do
expected_root_presenter_file = File.join(generator_tmp_directory, 'app/presenters/root_presenter.rb')
presenter_file = File.read(expected_root_presenter_file)
- expect(presenter_file).to match(/link :foo do |opts|/)
- expect(presenter_file).to match(/link :foos do |opts|/)
+ expect(presenter_file).to match(/link :article do |opts|/)
+ expect(presenter_file).to match(/link :articles do |opts|/)
end
end
describe 'spec' do
it 'creates an api spec' do
- expected_api_file = File.join(generator_tmp_directory, 'spec/endpoints/foos_endpoint_spec.rb')
+ expected_api_file = File.join(generator_tmp_directory, 'spec/endpoints/articles_endpoint_spec.rb')
api_code = File.read(expected_api_file)
- expect(api_code).to match(/describe FoosEndpoint/)
+ expect(api_code).to match(/describe ArticlesEndpoint/)
+ expect(api_code).to match(/returns an article/)
end
it 'creates a fabricator' do
- expected_fabricator_file = File.join(generator_tmp_directory, 'spec/fabricators/foos_fabricator.rb')
+ expected_fabricator_file = File.join(generator_tmp_directory, 'spec/fabricators/articles_fabricator.rb')
fabricator_code = File.read(expected_fabricator_file)
- expect(fabricator_code).to include 'Fabricator(:foo) do'
+ expect(fabricator_code).to include 'Fabricator(:article) do'
end
it 'creates a model spec' do
- expected_model_file = File.join(generator_tmp_directory, 'spec/models/foo_spec.rb')
+ expected_model_file = File.join(generator_tmp_directory, 'spec/models/article_spec.rb')
model_code = File.read(expected_model_file)
- expect(model_code).to match(/describe Foo/)
+ expect(model_code).to match(/describe Article/)
end
end
end