1
在测试模型字段的有效性之前,我尝试在主题中设置实例变量。我需要设置此变量,因为验证是有条件的(仅用于某些类型的用户)。所以,我有这样的事情:Shoulda和RSpec之前
context "as a user" do
before(:each) do
subject = Organization.new
subject.editor = "user"
end
it { subject.should validate_presence_of :name }
end
但预期它不工作:
Failure/Error: it { subject.should validate_presence_of :description }
RuntimeError:
Organization#editor attr is not set
我错过了什么?