我正在尝试使用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
我的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不存在以来我可能会失踪什么?
解决方法
您可能忘记在spec_helper.rb中要求factory_girl.