Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: uninitialized constant FactoryGirl

I am trying to create my first controller test using FactoryGirl for my Rails application, but I keep retrieving the following error:

uninitialized constant FactoryGirl

My Factories.rb file 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 might I be missing since FactoryGirl isn't present?

like image 597
Dofs Avatar asked Dec 08 '12 20:12

Dofs


1 Answers

You propably forgotten to require factory_girl in spec_helper.rb.

like image 95
Hauleth Avatar answered Oct 12 '22 11:10

Hauleth