This is my Gemfile config:
group :development, :test do
gem \'rspec-rails\'
gem \'factory_girl\', \'~>2.0.0.beta1\'
gem \'factory_girl_rails\'
I had the same issue, but it turns out that I simply named my file wrong (factories.rb.rb, thanks to Netbeans). I discovered a few things that would be useful to this page, though.
From the getting started page. Factory girl should automatically load the following files if they exist:
test/factories.rb
spec/factories.rb
test/factories/*.rb
spec/factories/*.rb
Putting the following in test_helper.rb can cause double loading:
require 'factory_girl' Factory.find_definitions
This caused me to get a `add_as': Already defined: <factory name>
error.
The factory_girl_rails gem automatically loads factory_girl. It's unnecessary, but doesn't appear to have any side effects.
I discovered that the FactoryGirl syntax has changed quite a bit since I first learned it in March 2011. I highly recommend everyone check out the getting started page to see some of the changes.
I think problem is related to the loading of your factory. Just write this in your test_helper.rb file
require 'factory_girl'
Dir.glob(File.dirname(__FILE__) + "/factories/*").each do |factory|
require factory
end
OR
require 'factory_girl'
FactoryGirl.find_definitions