Factory already registered: user (FactoryGirl::DuplicateDefinitionError)
The gem factory_girl_rails
should be required in the spec_helper.rb
rather than the gemfile - it is possible that you are requiring FactoryGirl twice which is why you are getting the duplicate.
Try this in your gem file:
group :test do gem "rspec" gem 'factory_girl_rails', :require => falseend
Then make sure that factory girl is required in the spec_helper with:
require 'factory_girl_rails'
By the way - you don't need both rspec
and rpsec-rails
in your gemfile. You can replace both with the following:
group :development, :test do gem 'rspec-rails'end
You need rspec in both groups so that the rake tasks will work in development and the core testing will work in test.
I had the same problem recently. In my case one of the files in /factories had a _spec.rb ending (result of creative cp use). It was loading twice, first by rspec and then as a factory.
Is there any chance you pasted this whole snippet for the support file from the config docs?
# RSpec# spec/support/factory_girl.rbRSpec.configure do |config| config.include FactoryGirl::Syntax::Methodsend# RSpec without RailsRSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.before(:suite) do FactoryGirl.find_definitions endend
If you read the comments you'll see you only want one block or the other. I made this mistake and got the error stated in the question.