diff --git a/features/generators.feature b/features/generators.feature index 7fa3963..7dd16db 100644 --- a/features/generators.feature +++ b/features/generators.feature @@ -34,12 +34,18 @@ Feature: end """ And I run `bundle exec rails generate model User name:string` with a clean environment + And I run `bundle exec rails generate model Robot name:string` with a clean environment Then the file "test/factories.rb" should contain exactly: """ FactoryBot.define do + factory :robot do + name { "MyString" } + end + factory :user do name { "MyString" } end + end """ @@ -51,4 +57,4 @@ Feature: end """ And I run `bundle exec rails generate model User name:string` with a clean environment - Then the file "test/factories.rb" should contain "factory :user do" + Then the file "test/factories/users.rb" should not contain "factory :user do" diff --git a/lib/generators/factory_bot/model/model_generator.rb b/lib/generators/factory_bot/model/model_generator.rb index 1abb4d1..6f3e341 100644 --- a/lib/generators/factory_bot/model/model_generator.rb +++ b/lib/generators/factory_bot/model/model_generator.rb @@ -57,13 +57,14 @@ module FactoryBot factory :#{singular_table_name}#{explicit_class_option} do #{factory_attributes.gsub(/^/, ' ')} end + RUBY end def single_file_factory_definition <<~RUBY FactoryBot.define do - #{factory_definition.chomp} + #{factory_definition.rstrip} end RUBY end