RSpec error "Uninitialized constant FactoryGirl (Name Error)"

17,037

You just have to add the following in your spec_helper.rb file

require 'factory_girl_rails'
Share:
17,037

Related videos on Youtube

user3472965
Author by

user3472965

Updated on October 09, 2022

Comments

  • user3472965
    user3472965 over 1 year

    I try running my RSpec test:

    rspec comments.rb
    

    but keep getting the same error (see title). Before anyone asks I have already added require factory_girl to spec_helper.rb.

    The contents of spec/factories/comments.rb file are:

      FactoryGirl.define do
        factory :comment do
          comment "MyString"
          task_id 1
      end
    end
    

    Here is testing group of the gemfile where I included factory_girl_rails:

    source 'http://rubygems.org'
    
    ...
    
    group :development, :test do
      gem 'debugger'
      gem 'factory_girl_rails'
      gem 'rspec-rails'
    end
    
    ...
    
  • Bryan Ash
    Bryan Ash about 8 years
    This answer uses the unknown constant FactoryGirl. How is this supposed to help?
  • oligan
    oligan almost 8 years
    I'm voting to delete this answer as it's not addressing the question that was asked.
  • Feliks Montez
    Feliks Montez over 6 years
    FactoryGirl has changed its name to FactoryBot, so you will now need to use require 'factory_bot_rails'.