Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

后端 未结 27 2273
我在风中等你
我在风中等你 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:54

    Is there any chance you pasted this whole snippet for the support file from the config docs?

    # RSpec
    # spec/support/factory_girl.rb
    RSpec.configure do |config|
      config.include FactoryGirl::Syntax::Methods
    end
    
    # RSpec without Rails
    RSpec.configure do |config|
      config.include FactoryGirl::Syntax::Methods
    
      config.before(:suite) do
        FactoryGirl.find_definitions
      end
    end
    

    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.

提交回复
热议问题