簡體   English   中英

使用Rspec在Rails應用程序上測試ruby

[英]testing ruby on rails application using Rspec

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) ; 您的應用可能未配置出廠快捷方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM