Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec error "Uninitialized constant FactoryGirl (Name Error)"

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

...
like image 665
user3472965 Avatar asked Sep 11 '25 03:09

user3472965


1 Answers

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

require 'factory_girl_rails'
like image 159
Mutuma Avatar answered Sep 12 '25 16:09

Mutuma