Rails 3:未初始化的恒定FactoryGirl

时间:2012-12-08 20:14:54

标签: ruby-on-rails tdd factory-bot

我正在尝试使用FactoryGirl为我的Rails应用程序创建我的第一个控制器测试,但我一直在检索以下错误:

uninitialized constant FactoryGirl

My Factories.rb文件如下所示:

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

我的控制器测试看起来像这样:

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如下所示:

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

由于FactoryGirl不存在,我可能会错过什么?

1 个答案:

答案 0 :(得分:19)

您可能忘记{{1p>}中需要factory_girl