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
=============================================
有什么建议可以解决这个问题吗?
尝试FactoryGirl.create(:contact)
而不是Factory.create(:contact)
;可能未在您的应用程序上配置出厂快捷方式。