0
對於諸如it { should have(1).error_on(:base) }
之類的東西以及特定的Shoulda匹配器,我仍然很困惑。Shoulda/RSpec:確保驗證消息「xxx」處於打開狀態:基地
我想確保:base
包含錯誤消息「xxx」,所以我應該如何做到這一點?
it "should contain error message 'xxx'" do
contact.valid?
contact.errors[:base].should include('xxx')
end
這是「走的路」,還是有更好的?謝謝。
感謝提示與主題和之前的過濾器。 – 2012-07-12 20:19:06
更簡潔:it {subject.errors [:base] .should include'xxx'} – scarver2 2013-10-24 22:35:53
.error [:whatever]現在返回一個數組,所以include不起作用,除非你匹配整個字符串。 – Xavier 2016-07-29 16:17:17