ruby-on-rails – Rails 3:未初始化的恒定FactoryGirl
发布时间:2020-12-17 04:27:18 所属栏目:百科 来源:网络整理
导读:我正在尝试使用FactoryGirl为我的Rails应用程序创建我的第一个控制器测试,但我一直在检索以下错误: uninitialized constant FactoryGirl My Factories.rb文件如下所示: FactoryGirl.define do factory :offer,class: "Offer" do |f| f.title "Some title"
我正在尝试使用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.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |