我有以下rspec:
require 'spec_helper'
describe KnowledgesController do
before (:each) do
@knowledge = FactoryGirl.create(:knowledge)
@professor = FactoryGirl.create(:professor)
sign_in @professor
end
describe "GET 'show'" do
it "should be successful" do
response.should be_success
end
end
end
执行时给我以下错误:
Failure/Error: @professor = FactoryGirl.create(:professor)
ActiveRecord::RecordInvalid:
translation missing: es.activerecord.errors.messages.record_invalid
# ./spec/controllers/knowledge_controller_spec.rb:7:in `block (2 levels) in <top (required)>'
如果我改变这个:
before (:each) do
@knowledge = FactoryGirl.create(:knowledge)
@professor = FactoryGirl.create(:professor)
sign_in @professor
end
为了:
before (:each) do
@professor = FactoryGirl.create(:professor)
@knowledge = FactoryGirl.create(:knowledge)
sign_in @professor
end
我收到此错误:
Failure/Error: @knowledge = FactoryGirl.create(:knowledge)
ActiveRecord::RecordInvalid:
translation missing: es.activerecord.errors.messages.record_invalid
所以,我不认为记录是无效的,因为在一种情况下它取决于知识,在另一种情况下取决于教授。
你们有什么想法会发生什么吗?
这些工厂是:
#Knowledge
FactoryGirl.define do
factory :knowledge do |knowledge|
knowledge.association(:professor)
knowledge.association(:subject)
knowledge.association(:level)
end
end
#Professor
FactoryGirl.define do
factory :professor do
first_name 'Mister'
last_name 'Professor'
...
end
end