Search code examples
ruby-on-railsrubyshouldafactory-bot

Rails shoulda and factory_girl setup


I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this:

require 'factory_girl'

Factory.define :user do |u|
  u.mail '[email protected]'
  u.pass 'secret'
end

to my test/test_helper.rb I'm getting this error:

/test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)

when I execute rake test:units

I have installed both gems using:

sudo gem install thoughtbot-shoulda --source=http://gems.github.com sudo gem install thoughtbot-factory_girl --source=http://gems.github.com

and can see both of them being installed fine.

  • And by the way, this works fine as well:

script/console Loading development environment (Rails 2.3.8)

require 'factory_girl' => []

so requiring the gems seems to be working


Solution

  • Couple things to check:

    • Don't use --source=http://gems.github.com anymore. This has been deprecated in favor for gemcutter.org
    • Don't use "thoughtbot-gem_name" - again this was deprecated by gemcutter.org. Just do sudo gem install factory_girl shoulda
    • Make sure you have config.gem 'factory_girl' in your config/environments/test.rb file.