Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

后端 未结 27 2254
我在风中等你
我在风中等你 2021-02-06 21:18

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         


        
27条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 21:42

    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.

提交回复
热议问题