我有一个经过验证的Rails模型:
validates_numericality_of(:insert_oz,
:allow_blank=>true,
:greater_than=>0,
:if=>(proc do |note|
!note.insert_pages.nil? &&
note.insert_pages > 0
end))
使用卓越,如何测试使用
:if
选择权?
如果我做了显而易见的事情,并将验证添加到我的规范中,那么将“validates”更改为“should\u validate”:
should_validate_numericality_of(:insert_oz,
:allow_blank=>true,
:greater_than=>0,
:if=>(proc do |note|
!note.insert_pages.nil? &&
note.insert_pages > 0
end))
然后规范失败,并显示以下消息:
'Processingnote should ensure numericality of insert oz is greater than 0 and allowing blank values' FAILED
Expected Processingnote to be invalid when insert oz is less than 1