Description of problem: - I\'ve setup factory_girl_rails however whenever I try and load a factory it\'s trying to load it multiple times.
Envir
Make sure your individual factory files are not ending with _spec.
Call FactoryGirl.define(:user) or FactoryGirl.find_definitions twice you also have this problem.
Try removing the second call or:
FactoryGirl.factories.clear
FactoryGirl.find_definitions
The strangest thing, I got this error with the following syntax error in the code:
before_validation :generate_reference, :on: :create
:on: was causing this error. How or why will remain a mystery.
for me, this issue was coming because was using both gems
gem 'factory_bot_rails'
gem 'factory_girl_rails'
to solve I removed gem 'factory_bot_rails' from gem file.
and also added require 'factory_girl' to spec/factories/track.rb file.
if Rails.env.test?
require 'factory_girl'
FactoryGirl.define do
factory :track do
id 1
name "nurburgring"
surface_type "snow"
time_zone "CET"
end
end
I hope this will help.
Another possible reason is spare call of FactoryGirl.find_definitions.
Try to remove find_definitions if found.
I had exactly the same problem. It occurs when you use the scaffold generator. It automatically creates a factory in test/factories/ So generally just deleting this file solve your issue