mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
Fix bug when configuring FactoryGirl and RSpec fixture dir
Closes #90, #88, #84
This commit is contained in:
parent
7ce3ca02c6
commit
9d3df8ce94
6 changed files with 35 additions and 14 deletions
|
@ -17,6 +17,13 @@ Feature:
|
|||
|
||||
Scenario: Using Factory Girl and Factory Girl Rails with RSpec should generate a factory file
|
||||
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
|
||||
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
|
||||
|
|
|
@ -19,6 +19,14 @@ When /^I set the FactoryGirl :suffix option to "([^"]+)"$/ do |suffix|
|
|||
|
||||
end
|
||||
|
||||
When /^I configure the factories as:$/ do |string|
|
||||
append_to_file File.join('config', 'application.rb'), <<-END
|
||||
class Testapp::Application
|
||||
#{string}
|
||||
end
|
||||
END
|
||||
end
|
||||
|
||||
When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir|
|
||||
append_to_file File.join('config', 'application.rb'), <<-END
|
||||
class Testapp::Application
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PATH
|
||||
remote: /Users/mjankowski/Development/OpenSource/factory_girl_rails
|
||||
remote: /Users/joshuaclayton/dev/gems/factory_girl_rails
|
||||
specs:
|
||||
factory_girl_rails (4.2.0)
|
||||
factory_girl (~> 4.2.0)
|
||||
|
@ -57,8 +57,8 @@ GEM
|
|||
factory_girl (4.2.0)
|
||||
activesupport (>= 3.0.0)
|
||||
ffi (1.3.1)
|
||||
gherkin (2.11.5)
|
||||
json (>= 1.4.6)
|
||||
gherkin (2.11.6)
|
||||
json (>= 1.7.6)
|
||||
i18n (0.5.0)
|
||||
jquery-rails (2.2.0)
|
||||
railties (>= 3.0, < 5.0)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PATH
|
||||
remote: /Users/mjankowski/Development/OpenSource/factory_girl_rails
|
||||
remote: /Users/joshuaclayton/dev/gems/factory_girl_rails
|
||||
specs:
|
||||
factory_girl_rails (4.2.0)
|
||||
factory_girl (~> 4.2.0)
|
||||
|
@ -66,8 +66,8 @@ GEM
|
|||
factory_girl (4.2.0)
|
||||
activesupport (>= 3.0.0)
|
||||
ffi (1.3.1)
|
||||
gherkin (2.11.5)
|
||||
json (>= 1.4.6)
|
||||
gherkin (2.11.6)
|
||||
json (>= 1.7.6)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.1)
|
||||
jquery-rails (2.2.0)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PATH
|
||||
remote: /Users/mjankowski/Development/OpenSource/factory_girl_rails
|
||||
remote: /Users/joshuaclayton/dev/gems/factory_girl_rails
|
||||
specs:
|
||||
factory_girl_rails (4.2.0)
|
||||
factory_girl (~> 4.2.0)
|
||||
|
@ -65,8 +65,8 @@ GEM
|
|||
factory_girl (4.2.0)
|
||||
activesupport (>= 3.0.0)
|
||||
ffi (1.3.1)
|
||||
gherkin (2.11.5)
|
||||
json (>= 1.4.6)
|
||||
gherkin (2.11.6)
|
||||
json (>= 1.7.6)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
|
|
|
@ -8,9 +8,15 @@ module FactoryGirl
|
|||
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
||||
rails_options = generators.options[:rails]
|
||||
|
||||
puts generators.options
|
||||
puts rails_options
|
||||
if rails_options[:test_framework] == :rspec
|
||||
if !rails_options.has_key?(:fixture_replacement)
|
||||
generators.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
||||
factory_girl_dir = generators.options.fetch(:factory_girl, { :dir => 'spec/factories' })[:dir]
|
||||
|
||||
if rails_options.has_key?(:fixture_replacement)
|
||||
generators.fixture_replacement rails_options[:fixture_replacement], :dir => factory_girl_dir
|
||||
else
|
||||
generators.fixture_replacement :factory_girl, :dir => factory_girl_dir
|
||||
end
|
||||
else
|
||||
generators.test_framework rails_options[:test_framework], :fixture => false, :fixture_replacement => :factory_girl
|
||||
|
@ -19,9 +25,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')
|
||||
Rails.root.join('factories'),
|
||||
Rails.root.join('test', 'factories'),
|
||||
Rails.root.join('spec', 'factories')
|
||||
]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue