1

rspec spec/models/contact_spec.rb==> 在我的终端中运行此代码时,我收到以下错误消息:uninitialized constant Factory.

# spec/factories/contacts.rb
=============================================
require 'faker'

FactoryGirl.define do
  factory :contact do |f|
    f.firstname { Faker::Name.first_name }
    f.lastname { Faker::Name.last_name }
  end
end
=============================================

# spec/models/contact_spec.rb
=============================================
require 'spec_helper'
require 'factory_girl_rails'
describe Contact do
  it "has a valid factory" do
    Factory.create(:contact).should be_valid
  end
  it "is invalid without a firstname"
  it "is invalid without a lastname"
  it "returns a contact's full name as a string"
end
=============================================

任何建议如何解决这个问题?

4

1 回答 1

0

尝试FactoryGirl.create(:contact)代替Factory.create(:contact); 工厂快捷方式可能未在您的应用上配置。

于 2013-01-31T12:39:53.083 回答