Rails / Factory Girl: Uninitialized constant FactoryGirl (NameError)

10,997

Solution 1

This must be your answer.

The required addition should be made in spec/support/factory_girl.rb

https://stackoverflow.com/a/25649064/1503970

Solution 2

In spec/spec_helper.rb, try adding

FactoryGirl.find_definitions

under

require 'factory_girl_rails'

or make sure you follow factory_bot's Getting Started guide.

Solution 3

I'm just putting this here for anyone clumsy like me. Everything was fine, but I was calling FactoryGirl in one place, when I only have FactoryBot installed. Newbie error. Hope it might help.

Share:
10,997

Related videos on Youtube

vveare138
Author by

vveare138

Updated on July 08, 2022

Comments

  • vveare138
    vveare138 almost 2 years

    I installed the factory_girl gem, and when I run my tests I get an error:

    `block in ': uninitialized constant FactoryGirl (NameError)

    This is my spec_helper.rb

    RSpec.configure do |config|
      config.include FactoryGirl::Syntax::Methods
      config.expect_with :rspec do |expectations|
        expectations.include_chain_clauses_in_custom_matcher_descriptions = true
      end
      config.mock_with :rspec do |mocks|
        mocks.verify_partial_doubles = true
      end
    end
    

    How can it be fixed?