Rails 3: uninitialized FactoryGirl constant

I am trying to create my first test case with FactoryGirl for my Rails application, but I continue to get the following error:

uninitialized constant FactoryGirl 

The file My Factories.rb looks like this:

 FactoryGirl.define do factory :offer, class: "Offer" do |f| f.title "Some title" f.description "SomeDescription" end end 

And my controller test looks like this:

 require 'spec_helper' describe OffersController do def valid_session {} end describe "GET index" do before { @offer = FactoryGirl.create(:offer) } it "assigns all offers as @offers" do get :index, {}, valid_session assigns(:offers).should eq([@offer]) end end end 

My gemfile looks like this:

 group :development, :test do gem 'sqlite3' gem 'rspec-rails' gem 'capybara', '1.1.2' gem 'factory_girl_rails', '>= 4.1.0', :require => false end 

What am I missing because FactoryGirl is not present?

+7
source share
1 answer

You may have forgotten to require factory_girl in spec_helper.rb .

+19
source

All Articles