Rspec 匹配器未使用自定义错误消息
我有一个自定义匹配器:
RSpec::Matchers.define :have_value do |attribute, expected|
match do |obj|
obj.send(attribute) == expected
end
description do
"have attribute #{attribute} with value #{expected}"
end
end
这是我如何使用它的示例:
context "description" do
subject { create_obj_from_file(file_name) }
h = {
:attribute1 => 6,
:attribute2 => 3,
:attribute3 => "PL" }
}
h.each do |k,v| it { should have_value k, v} end
end
这正在正确运行我的测试。但是当我收到错误时,这不是自定义错误,而是“预期 {masssive object dump} 有值:属性和值”关于我做错了什么有什么想法吗?
I have a custom matcher:
RSpec::Matchers.define :have_value do |attribute, expected|
match do |obj|
obj.send(attribute) == expected
end
description do
"have attribute #{attribute} with value #{expected}"
end
end
And this is an example of how I am using it:
context "description" do
subject { create_obj_from_file(file_name) }
h = {
:attribute1 => 6,
:attribute2 => 3,
:attribute3 => "PL" }
}
h.each do |k,v| it { should have_value k, v} end
end
This is running my tests correctly. But when I get an error, it's not the custom error, it is "expected {masssive object dump} to have value :atttribute and value" Any ideas as to what I"m doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您使用我的代码来回答您的上一个问题。以下是此示例所需的内容:
Thanks for using my code in response to your last question. Here is what you need for this example:
您需要指定自定义失败消息。来自 wiki 的示例:
You need to specify custom failure messages. An example from the wiki: