2013-01-31 41 views
1

rspec spec/models/contact_spec.rb ==>當運行在我的終端這段代碼測試Rails應用程序的紅寶石,我收到以下錯誤信息:uninitialized constant Factory.使用Rspec的

# 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 
============================================= 

任何建議如何解決這一問題?

+0

嘗試'FactoryGirl.create(:contact)'而不是'Factory.create(:contact)'; 「Factory」快捷方式可能未在您的應用中配置。 –

+0

@PrakashMurthy謝謝。它現在正在工作。, –

+0

太棒了。將添加相同的答案,以便幫助他人。 –

回答

0

嘗試FactoryGirl.create(:contact)而不是Factory.create(:contact);工廠快捷方式可能未在您的應用程序上配置。