私は自分でカスタムマッチャーを作成しましたが、それ自体は正常に機能します。しかし、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.