我给自己写了一个自定义匹配器,它本身工作得很好。但是failure_message_for_should
不起作用,我仍然收到默认的失败消息。作品...should_not
!
我的匹配器:
RSpec::Matchers.define :be_same_dom do |expected|
match do |actual|
assert_dom_equal(expected, actual)
end
failure_message_for_should do |actual|
"Expected the same DOM as #{expected}, but got #{actual}"
end
failure_message_for_should_not do |actual|
"Expected a different DOM than #{expected}"
end
end
失败消息:
Failure/Error: helper.link_to("Dictionary", dictionaries_path).should_not be_same_dom('<a href="/dictionaries">Dictionary</a>')
Expected a different DOM than <a href="/dictionaries">Dictionary</a>
Failure/Error: helper.link_to("Dictionary", dictionaries_path).should be_same_dom('<a class="x" href="/dictionaries">Dictionary</a>')
MiniTest::Assertion:
<"<a class=\"x\" href=\"/dictionaries\">Dictionary</a>"> expected to be == to
<"<a href=\"/dictionaries\">Dictionary</a>">..
Expected block to return true value.