1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00

Fix when use fixture_replacement with suffix option.

Fix #113
This commit is contained in:
Rodolfo Spalenza 2015-02-26 21:36:06 -03:00 committed by Joshua Clayton
parent 3a050736f3
commit c761d47c93
3 changed files with 26 additions and 2 deletions

View file

@ -32,6 +32,23 @@ Feature:
And the following files should not exist: And the following files should not exist:
| spec/fixtures/users.yml | | spec/fixtures/users.yml |
Scenario: Using Factory Girl and Factory Girl Rails with RSpec and suffix configuration should generate a factory file with suffix
When I add "rspec-rails" as a dependency
And I configure the factories as:
"""
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :factory_girl, suffix: 'factory'
end
"""
And I run `bundle install` with a clean environment
Then the output should contain "rspec-rails"
And I run `bundle exec rails generate model User name:string` with a clean environment
Then the following files should exist:
| spec/factories/users_factory.rb |
And the following files should not exist:
| spec/fixtures/users.yml |
Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using RSpec Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using RSpec
When I add "rspec-rails" as a dependency When I add "rspec-rails" as a dependency
And I configure the factories directory as "custom/dir" And I configure the factories directory as "custom/dir"

View file

@ -65,7 +65,7 @@ Feature: automatically load step definitions
When I write to "lib/some_railtie/factories.rb" with: When I write to "lib/some_railtie/factories.rb" with:
""" """
FactoryGirl.define do FactoryGirl.define do
factory :factory_from_some_railtie, :class => 'User' do factory :factory_from_some_railtie, class: 'User' do
name 'Artem' name 'Artem'
end end
end end

View file

@ -18,6 +18,13 @@ module FactoryGirl
desc: "The directory or file root where factories belong" desc: "The directory or file root where factories belong"
) )
class_option(
:suffix,
type: :string,
default: nil,
desc: "Suffix to add factory file"
)
def create_fixture_file def create_fixture_file
if File.exist?(factories_file) if File.exist?(factories_file)
insert_factory_into_existing_file insert_factory_into_existing_file
@ -69,7 +76,7 @@ RUBY
end end
def filename_suffix def filename_suffix
factory_girl_options[:suffix] factory_girl_options[:suffix] || options[:suffix]
end end
def factory_girl_options def factory_girl_options