Reputation: 703
I try to put Factory_girl in my Rails apps for testing.
Here is part of the Gemfile:
gem 'rspec-rails', :group => [:development, :test]
group :development do
gem 'annotate'
gem 'faker', '0.3.1', :require => false
gem 'populator', '1.0.0'
gem 'ruby-debug19'
end
group :test do
gem "capybara"
gem 'factory_girl_rails', '~> 3.5.0'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
gem 'rb-inotify'
gem 'libnotify'
end
group :development, :test do
gem 'sqlite3-ruby', :require=>'sqlite3'
end
Then I go in the console to test the install of Factory_Girl by, rails c
:
To call the find_definitions
method for instance:
Loading development environment (Rails 3.0.5)
irb(main):002:0> FactoryGirl.find_definitions
NameError: uninitialized constant FactoryGirl
from (irb):2
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
So I assume that I have to require the gem: I do so and:
irb(main):003:0> require 'factory_girl_rails'
SystemStackError: stack level too deep
from /usr/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!!
I got this strange error.
What am I doing wrong?
For information, I'm on Rails 3.0.5 with ruby 1.9.2.
The gem config is:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i686-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/izambard/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
Upvotes: 1
Views: 2438
Reputation: 703
Actually, I had a require factory_girl_rails
in the spec_helper.rb and in the factories.rb file. I remove the one in factories.rb and it is now working... :-s
Upvotes: 1
Reputation: 30434
You are running the development environment while including FactoryGirl in your test environment. If you run a console in the test environment, FactoryGirl will get included.
RAILS_ENV=test rails c
I am not quite sure why require 'factory_girl_rails'
in development leads to an infinite recursion. May be a bug in factory girl or an old rails version.
Upvotes: 2