Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factories generated in 'test/' not 'spec/' with RSpec in 4.2.0 #88

Closed
DanielKehoe opened this issue Jan 30, 2013 · 7 comments
Closed

factories generated in 'test/' not 'spec/' with RSpec in 4.2.0 #88

DanielKehoe opened this issue Jan 30, 2013 · 7 comments

Comments

@DanielKehoe
Copy link

The behavior of factory_girl_rails has changed from 4.1.0 to 4.2.0 when used with RSpec.

Prior to 4.2.0, specifying a generator in config/application.rb would create a factory file in the 'spec/factories' directory.

config.generators do |g|
    g.test_framework :rspec, fixture: true
    g.fixture_replacement :factory_girl
end

After updating to factory_girl_rails 4.2.0, the generator creates a factory file in the 'test/factories' directory.

The expected behavior can be forced by specifying the directory like this:

config.generators do |g|
    g.test_framework :rspec, fixture: true
    g.fixture_replacement :factory_girl, dir: "spec/factories"
end

I don't know whether the change in configuration requirements is intentional or whether 4.2.0 introduced an anomaly.

Here are the steps to reproduce the behavior.

$ rvm gemset create fgtest
$ rvm gemset use fgtest
$ gem list
*** LOCAL GEMS ***
bundler (1.2.3)
rake (10.0.3)
rubygems-bundler (1.1.0)
rubygems-update (1.8.25)
rvm (1.11.3.6, 1.11.3.5)
$ gem install rails
$ rails new myapp
$ cd myapp
add factory_girl_rails 4.1.0 to the Gemfile:
gem "factory_girl_rails", "4.1.0", :group = [:development, :test]
$ bundle install
$ rails generate model foo
creates test/factories/foos.rb (expected behavior)
add rspec-rails to the Gemfile:
gem "rspec-rails", ">= 2.12.2", :group = [:development, :test]
$ bundle install
edit config/application.rb to add:

config.generators do |g|
  g.test_framework :rspec, fixture: true
  g.fixture_replacement :factory_girl
end

$ rails generate model bar
creates spec/factories/bars.rb (expected behavior with factory_girl_rails 4.1.0)
update Gemfile from factory_girl_rails 4.1.0 to 4.2.0
gem "factory_girl_rails", "4.2.0", :group = [:development, :test]
$ bundle update
$ rails generate model baz
creates test/factories/bazs.rb (unexpected behavior with factory_girl_rails 4.2.0)
$ rails generate model baz
invoke active_record
create db/migrate/20130130201940_create_bazs.rb
create app/models/baz.rb
invoke rspec
create spec/models/baz_spec.rb
invoke factory_girl
create test/factories/bazs.rb
edit config/application.rb to add:

    config.generators do |g|
      g.test_framework :rspec, fixture: true
      g.fixture_replacement :factory_girl, dir: "spec/factories"
    end

$ rails generate model qux
creates spec/factories/quxes.rb (expected behavior)

@joshuaclayton
Copy link
Contributor

Thanks for reporting this @DanielKehoe; I'll dig in to this tomorrow and see if I can get it fixed. I just recently pulled in some code to handle a certain edge case; my guess is that it broke this; sorry about that! I'll update the ticket once I find a fix.

@joshuaclayton
Copy link
Contributor

@DanielKehoe could you update your Gemfile to point to the GitHub repository and ensure that it works? This should fix it but I'd like to verify in your project since you were having issues. Thanks!

@joshuaclayton
Copy link
Contributor

@DanielKehoe Closing this for now - I cut version 4.2.1 of the gem which should fix this, but please reopen the ticket if you're still seeing issues. Thanks!

@taavo
Copy link

taavo commented Jul 3, 2013

Just learned this the hard way: You can get the same problem by having factory_girl_rails in the :test group of your gemfile, but not the :development group.

@alagos
Copy link

alagos commented Aug 21, 2013

@taavo Having the same problem, thanks 👍

@danishsatkut
Copy link

@taavo Thanks for pointing it out.

@equivalent
Copy link

equivalent commented Jun 23, 2016

@taavo good spot

so recommending to do RAILS_ENV=test rails g factory_girl:model foo if one wants to keep factory_girl_rails only in test group

xander-miller added a commit to xander-miller/factory_girl_rails that referenced this issue Jul 16, 2016
Recommends adding to `factory_girl_rails` to both your `:test` and `:development` groups so generators will work in development. As per issue thoughtbot#88 thoughtbot#88
joshuaclayton pushed a commit that referenced this issue Jul 18, 2016
Recommends adding to `factory_girl_rails` to both your `:test` and `:development` groups so generators will work in development. As per issue #88 #88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants