使用Rspec在rails应用程序上测试ruby

时间:2013-01-31 11:57:29

标签: ruby-on-rails ruby ruby-on-rails-3 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
=============================================

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

1 个答案:

答案 0 :(得分:0)

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