将更多信息附加到 RSpec 的默认失败消息中? [英] Append more info to RSpec's default failure message?
本文介绍了将更多信息附加到 RSpec 的默认失败消息中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这样的验证中测试了很多错误的字符串:
I'm testing a lot of bad strings on a validation like this:
['0', '3:a', 'xx:11', '-1', '-3:00', 'h', 'h2', 'h2h', 'm', 'm10', 'm10m', '2hm', 'h2m', 'hm2', '2m10h', '2m10m', '2h10h'].each do |input|
FactoryGirl.build(:time_record, duration_string: input).should have(1).error_on('duration_string'), "Tested value was '#{input}'"
end
遗憾的是,当其中一个失败时,消息 expected 1 error on :duration_string, got 0
没有告诉我,哪个失败了.我知道我可以传递显示的第二个参数,而不是像这样的默认消息:
Sadly, when one of them fails, the message expected 1 error on :duration_string, got 0
doesn't tell me, which one failed. I know that I can pass a second argument that is displayed instead of the default message like this:
x.should have(1).error_on('duration_string'), "Tested value was '#{input}'"
但这隐藏了原始消息.有没有办法只将我自己的消息附加到原始消息而不是替换它?
But this hides the original message. Is there a way to only append my own message to the original instead of replacing it?
谢谢.
推荐答案
我是这样解决的:
['0', '3:a', 'xx:11', '-1', '-3:00', 'h', 'h2', 'h2h', 'm', 'm10', 'm10m', '2hm', 'h2m', 'hm2', '2m10h', '2m10m', '2h10h'].each do |input|
it "does not accept #{input}" do
FactoryGirl.build(:time_record, duration_string: input).should have(1).error_on('duration_string'), "Tested value was '#{input}'"
end
end
通过这种方式,您还可以廉价地获得更高规格的统计数据.;)
This way you also get cheaply a higher specs count for your statistics. ;)
这篇关于将更多信息附加到 RSpec 的默认失败消息中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文