有没有更好的方法来编写此规范?这可以 但是 我不喜欢我必须调用f.valid?
来填充f.errors。
it "fails to save the record because the name is blank" do
f = Foo.new
f.valid?
f.errors.include?(:name).should be_true
end
答案 0 :(得分:4)
it "fails to save the record because the name is blank" do
Foo.create.errors.should include :name
end