mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
parent
f2b5b79dd9
commit
1c6975c185
3 changed files with 39 additions and 6 deletions
|
@ -29,3 +29,24 @@ Feature:
|
||||||
| spec/factories/users.rb |
|
| spec/factories/users.rb |
|
||||||
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 does not override a manually-configured factories directory using RSpec
|
||||||
|
When I add "rspec-rails" as a dependency
|
||||||
|
And I configure the factories directory as "custom/dir"
|
||||||
|
And I successfully run `bundle install`
|
||||||
|
And I successfully run `bundle exec rails generate model User name:string`
|
||||||
|
Then the following files should not exist:
|
||||||
|
| test/factories/users.rb |
|
||||||
|
| spec/factories/users.rb |
|
||||||
|
But the following files should exist:
|
||||||
|
| custom/dir/users.rb |
|
||||||
|
|
||||||
|
Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using Test::Unit
|
||||||
|
When I configure the factories directory as "custom/dir"
|
||||||
|
And I successfully run `bundle install`
|
||||||
|
And I successfully run `bundle exec rails generate model User name:string`
|
||||||
|
Then the following files should not exist:
|
||||||
|
| test/factories/users.rb |
|
||||||
|
| spec/factories/users.rb |
|
||||||
|
But the following files should exist:
|
||||||
|
| custom/dir/users.rb |
|
||||||
|
|
|
@ -18,3 +18,13 @@ When /^I set the FactoryGirl :suffix option to "([^"]+)"$/ do |suffix|
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir|
|
||||||
|
append_to_file File.join('config', 'application.rb'), <<-END
|
||||||
|
class Testapp::Application
|
||||||
|
config.generators do |g|
|
||||||
|
g.fixture_replacement :factory_girl, :dir => "#{factory_dir}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
END
|
||||||
|
end
|
||||||
|
|
|
@ -6,9 +6,12 @@ module FactoryGirl
|
||||||
|
|
||||||
initializer "factory_girl.set_fixture_replacement" do
|
initializer "factory_girl.set_fixture_replacement" do
|
||||||
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
||||||
|
rails_options = generators.options[:rails]
|
||||||
|
|
||||||
if generators.options[:rails][:test_framework] == :rspec
|
if rails_options[:test_framework] == :rspec
|
||||||
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
if !rails_options.has_key?(:fixture_replacement)
|
||||||
|
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
||||||
|
end
|
||||||
else
|
else
|
||||||
generators.test_framework :test_unit, :fixture => false, :fixture_replacement => :factory_girl
|
generators.test_framework :test_unit, :fixture => false, :fixture_replacement => :factory_girl
|
||||||
end
|
end
|
||||||
|
@ -16,9 +19,9 @@ module FactoryGirl
|
||||||
|
|
||||||
initializer "factory_girl.set_factory_paths" do
|
initializer "factory_girl.set_factory_paths" do
|
||||||
FactoryGirl.definition_file_paths = [
|
FactoryGirl.definition_file_paths = [
|
||||||
File.join(Rails.root, 'factories'),
|
File.join(Rails.root, 'factories'),
|
||||||
File.join(Rails.root, 'test', 'factories'),
|
File.join(Rails.root, 'test', 'factories'),
|
||||||
File.join(Rails.root, 'spec', 'factories')
|
File.join(Rails.root, 'spec', 'factories')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,4 +30,3 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue