2012-06-14 26 views
2

有没有更好的方式来编写此规范?这个作品但是我不喜欢这个事实,我不得不打电话f.valid?得到f.errors填充。Rspec检查ActiveModel ::错误

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 

回答

4
it "fails to save the record because the name is blank" do 
    Foo.create.errors.should include :name 
end 
+0

感谢。更干净 –

相关问题