ruby-on-rails – Rails 3:未初始化的恒定FactoryGirl

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3:未初始化的恒定FactoryGirl前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用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.
原文链接:https://www.f2er.com/ruby/268969.html

猜你在找的Ruby相关文章