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

Allow a custom directory for factories be specified

Closes #73
This commit is contained in:
Joshua Clayton 2012-12-07 11:48:05 -05:00
parent f2b5b79dd9
commit 1c6975c185
3 changed files with 39 additions and 6 deletions

View file

@ -29,3 +29,24 @@ Feature:
| spec/factories/users.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
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 |

View file

@ -18,3 +18,13 @@ When /^I set the FactoryGirl :suffix option to "([^"]+)"$/ do |suffix|
RUBY
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

View file

@ -6,9 +6,12 @@ module FactoryGirl
initializer "factory_girl.set_fixture_replacement" do
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
rails_options = generators.options[:rails]
if generators.options[:rails][:test_framework] == :rspec
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
if rails_options[:test_framework] == :rspec
if !rails_options.has_key?(:fixture_replacement)
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
end
else
generators.test_framework :test_unit, :fixture => false, :fixture_replacement => :factory_girl
end
@ -16,9 +19,9 @@ module FactoryGirl
initializer "factory_girl.set_factory_paths" do
FactoryGirl.definition_file_paths = [
File.join(Rails.root, 'factories'),
File.join(Rails.root, 'test', 'factories'),
File.join(Rails.root, 'spec', 'factories')
File.join(Rails.root, 'factories'),
File.join(Rails.root, 'test', 'factories'),
File.join(Rails.root, 'spec', 'factories')
]
end
@ -27,4 +30,3 @@ module FactoryGirl
end
end
end