Skip to content

Commit

Permalink
Fix bug when configuring FactoryGirl and RSpec fixture dir
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Feb 5, 2013
1 parent 7ce3ca0 commit 9d3df8c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
7 changes: 7 additions & 0 deletions features/fixture_replacement_config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class Application < Rails::Application

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
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/rails3.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/rails3.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/rails3.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions lib/factory_girl_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ class Railtie < Rails::Railtie
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
Expand All @@ -19,9 +25,9 @@ class Railtie < Rails::Railtie

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

Expand Down

0 comments on commit 9d3df8c

Please sign in to comment.