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 => false
end

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)