Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

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

    I had same problem. This happens becouse of you using gem 'refinerycms-testing'? wich requires factory-girl, so you should commit this gem, or commit gem 'factory_girl_rails', don't use all of this gems.

        #gem 'refinerycms-testing', '~> 2.0.9', :group => :test
        gem 'factory_girl_rails', :group => :test
    

    or

        #gem 'factory_girl_rails', :group => :test
        gem 'refinerycms-testing', '~> 2.0.9', :group => :test 
    
    0 讨论(0)
  • 2021-02-06 21:54

    try to run

    rake db:test:prepare

    0 讨论(0)
  • 2021-02-06 21:54

    In my case,

    First my co-worker has setup the project with factory_girl gem with

    Dir[Rails.root.join('spec/factories/**/*.rb')].each { |f| require f }
    

    in rails_helper.

    After some days, I replaced the gem with factory_girl_rails. Since this new gem also does that internally so factories were registered twice. This was causing the error.

    Removed that line from rails_helper and it worked.

    0 讨论(0)
提交回复
热议问题