test/commands/generator_test.rb in pliny-0.2.1 vs test/commands/generator_test.rb in pliny-0.3.0
- old
+ new
@@ -1,197 +1,158 @@
-require "test_helper"
+require 'pliny/commands/generator'
+require 'pliny/commands/generator/base'
+require 'test_helper'
describe Pliny::Commands::Generator do
+subject { Pliny::Commands::Generator.new }
+
before do
- @gen = Pliny::Commands::Generator.new({}, {}, StringIO.new)
- end
+ FileUtils.mkdir_p('/tmp/plinytest')
+ Dir.chdir('/tmp/plinytest')
+ Timecop.freeze(@t = Time.now)
- describe "#field_name" do
- it "uses the singular form" do
- @gen.args = ["model", "resource_histories"]
- assert_equal "resource_history", @gen.field_name
+ any_instance_of(Pliny::Commands::Generator::Base) do |klass|
+ stub(klass).display
end
-
- it "handles hyphens as underscores" do
- @gen.args = ["model", "resource-histories"]
- assert_equal "resource_history", @gen.field_name
- end
end
- describe "#plural_class_name" do
- it "builds a class name for a model" do
- @gen.args = ["model", "resource_histories"]
- assert_equal "ResourceHistories", @gen.plural_class_name
- end
-
- it "handles hyphens as underscores" do
- @gen.args = ["model", "resource-histories"]
- assert_equal "ResourceHistories", @gen.plural_class_name
- end
+ after do
+ FileUtils.rmdir('/tmp/plinytest')
+ Timecop.return
end
- describe "#singular_class_name" do
- it "builds a class name for an endpoint" do
- @gen.args = ["model", "resource_histories"]
- assert_equal "ResourceHistory", @gen.singular_class_name
+ describe '#endpoint' do
+ before do
+ subject.endpoint('artists')
end
- it "handles hyphens as underscores" do
- @gen.args = ["model", "resource-histories"]
- assert_equal "ResourceHistory", @gen.singular_class_name
+ it 'creates a new endpoint module' do
+ assert File.exist?('lib/endpoints/artists.rb')
end
- end
- describe "#table_name" do
- it "uses the plural form" do
- @gen.args = ["model", "resource_history"]
- assert_equal "resource_histories", @gen.table_name
+ it 'creates an endpoint test' do
+ assert File.exist?('spec/endpoints/artists_spec.rb')
end
- it "handles hyphens as underscores" do
- @gen.args = ["model", "resource-history"]
- assert_equal "resource_histories", @gen.table_name
+ it 'creates an endpoint acceptance test' do
+ assert File.exist?('spec/acceptance/artists_spec.rb')
end
end
- describe "#run!" do
+ describe '#mediator' do
before do
- FileUtils.mkdir_p("/tmp/plinytest")
- Dir.chdir("/tmp/plinytest")
- Timecop.freeze(@t=Time.now)
+ subject.mediator('artists/creator')
end
- after do
- FileUtils.rmdir("/tmp/plinytest")
- Timecop.return
+ it 'creates a new mediator module' do
+ assert File.exist?('lib/mediators/artists/creator.rb')
end
- describe "generating endpoints" do
+ it 'creates a test' do
+ assert File.exist?('spec/mediators/artists/creator_spec.rb')
+ end
+ end
+
+ describe '#model' do
+ describe 'simple model' do
before do
- @gen.args = ["endpoint", "artists"]
- @gen.run!
+ subject.model('artist')
end
- it "creates a new endpoint module" do
- assert File.exists?("lib/endpoints/artists.rb")
+ it 'creates a migration' do
+ assert File.exist?("db/migrate/#{@t.to_i}_create_artists.rb")
end
- it "creates an endpoint test" do
- assert File.exists?("spec/endpoints/artists_spec.rb")
+ it 'creates the actual model' do
+ assert File.exist?('lib/models/artist.rb')
end
- it "creates an endpoint acceptance test" do
- assert File.exists?("spec/acceptance/artists_spec.rb")
+ it 'creates a test' do
+ assert File.exist?('spec/models/artist_spec.rb')
end
end
- describe "generating mediators" do
+ describe 'model in nested class' do
before do
- @gen.args = ["mediator", "artists/creator"]
- @gen.run!
+ subject.model('administration/user')
end
- it "creates a new mediator module" do
- assert File.exists?("lib/mediators/artists/creator.rb")
+ it 'creates a migration' do
+ assert File.exist?("db/migrate/#{@t.to_i}_create_administration_users.rb")
end
- it "creates a test" do
- assert File.exists?("spec/mediators/artists/creator_spec.rb")
+ it 'creates the actual model' do
+ assert File.exist?('lib/models/administration/user.rb')
end
- end
- describe "generating models" do
- before do
- @gen.args = ["model", "artist"]
- @gen.run!
+ it 'creates a test' do
+ assert File.exist?('spec/models/administration/user_spec.rb')
end
+ end
+ end
- it "creates a migration" do
- assert File.exists?("db/migrate/#{@t.to_i}_create_artists.rb")
- end
+ describe '#scaffold' do
+ before do
+ subject.scaffold('artist')
+ end
- it "creates the actual model" do
- assert File.exists?("lib/models/artist.rb")
- end
+ it 'creates a new endpoint module' do
+ assert File.exist?('lib/endpoints/artists.rb')
+ end
- it "creates a test" do
- assert File.exists?("spec/models/artist_spec.rb")
- end
+ it 'creates an endpoint test' do
+ assert File.exist?('spec/endpoints/artists_spec.rb')
end
- describe "generating scaffolds" do
- before do
- @gen.args = ["scaffold", "artist"]
- @gen.run!
- end
+ it 'creates an endpoint acceptance test' do
+ assert File.exist?('spec/acceptance/artists_spec.rb')
+ end
- it "creates a new endpoint module" do
- assert File.exists?("lib/endpoints/artists.rb")
- end
+ it 'creates a migration' do
+ assert File.exist?("db/migrate/#{@t.to_i}_create_artists.rb")
+ end
- it "creates an endpoint test" do
- assert File.exists?("spec/endpoints/artists_spec.rb")
- end
+ it 'creates the actual model' do
+ assert File.exist?('lib/models/artist.rb')
+ end
- it "creates an endpoint acceptance test" do
- assert File.exists?("spec/acceptance/artists_spec.rb")
- end
+ it 'creates a test' do
+ assert File.exist?('spec/models/artist_spec.rb')
+ end
- it "creates a migration" do
- assert File.exists?("db/migrate/#{@t.to_i}_create_artists.rb")
- end
+ it 'creates a schema' do
+ assert File.exist?('docs/schema/schemata/artist.yaml')
+ end
- it "creates the actual model" do
- assert File.exists?("lib/models/artist.rb")
- end
+ it 'creates a new serializer module' do
+ assert File.exist?('lib/serializers/artist.rb')
+ end
- it "creates a test" do
- assert File.exists?("spec/models/artist_spec.rb")
- end
+ it 'creates a test' do
+ assert File.exist?('spec/serializers/artist_spec.rb')
+ end
+ end
- it "creates a schema" do
- assert File.exists?("docs/schema/schemata/artist.yaml")
- end
+ describe '#schema' do
+ before do
+ subject.schema('artist')
+ end
- it "creates a new serializer module" do
- assert File.exists?("lib/serializers/artist_serializer.rb")
- end
-
- it "creates a test" do
- assert File.exists?("spec/serializers/artist_serializer_spec.rb")
- end
+ it 'creates a schema' do
+ assert File.exist?('docs/schema/schemata/artist.yaml')
end
+ end
- describe "generating schemas" do
- before do
- @gen.args = ["schema", "artist"]
- @gen.run!
- end
-
- it "creates a schema" do
- assert File.exists?("docs/schema/schemata/artist.yaml")
- end
+ describe '#serializer' do
+ before do
+ subject.serializer('artist')
end
- describe "generating serializers" do
- before do
- @gen.args = ["serializer", "artist"]
- @gen.run!
- end
-
- it "creates a new serializer module" do
- assert File.exists?("lib/serializers/artist_serializer.rb")
- end
-
- it "creates a test" do
- assert File.exists?("spec/serializers/artist_serializer_spec.rb")
- end
+ it 'creates a new serializer module' do
+ assert File.exist?('lib/serializers/artist.rb')
end
- end
- describe "#url_path" do
- it "builds a URL path" do
- @gen.args = ["endpoint", "resource_history"]
- assert_equal "/resource-histories", @gen.url_path
+ it 'creates a test' do
+ assert File.exist?('spec/serializers/artist_spec.rb')
end
end
end