我正在尝试使用 FactoryGirl 为我的 Rails 应用程序创建我的第一个控制器测试,但我不断检索以下错误:
uninitialized constant FactoryGirl
我的 Factory.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 不存在,我可能会缺少什么?