Improve failure messages for #fail_with_message_including

This improves our internal matcher so that it mirrors
#fail_with_message. In other words, when it fails it will now say:

    Expectation should have failed with:
      Some message goes here
    Actually failed with:
      Some other message goes here
    However, the expectation did not fail.
This commit is contained in:
Elliot Winkler 2015-03-28 18:07:58 -06:00
parent b3113117bd
commit ea50a9ffaf
1 changed files with 9 additions and 8 deletions

View File

@ -20,15 +20,17 @@ module UnitTests
end
def failure_message
msg = "Expectation should have failed with message including '#{expected}'"
lines = ['Expectation should have failed with message including:']
lines << Shoulda::Matchers::Util.indent(expected, 2)
if @actual
msg << ",\nactually failed with '#{@actual}'"
lines << 'Actually failed with:'
lines << Shoulda::Matchers::Util.indent(@actual, 2)
else
msg << ", but did not fail."
lines << 'However, the expectation did not fail.'
end
msg
lines.join("\n")
end
def failure_message_for_should
@ -36,10 +38,9 @@ module UnitTests
end
def failure_message_when_negated
msg = "Expectation should not have failed with message including '#{expected}'"
msg << ", but did."
msg
lines = ['Expectation should not have failed with message including:']
lines << Shoulda::Matchers::Util.indent(expected, 2)
lines.join("\n")
end
def failure_message_for_should_not