mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Improve output of fail_with_message matcher
This commit is contained in:
parent
060df9ed13
commit
de111ea5e8
2 changed files with 14 additions and 8 deletions
|
@ -23,6 +23,11 @@ module Shoulda
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.indent(string, width)
|
||||
indentation = ' ' * width
|
||||
string.split(/[\n\r]/).map { |line| indentation + line }.join("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,15 +20,17 @@ module UnitTests
|
|||
end
|
||||
|
||||
def failure_message
|
||||
msg = "Expectation should have failed with message '#{expected}'"
|
||||
lines = ['Expectation should have failed with message:']
|
||||
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 '#{expected}'"
|
||||
msg << ", but did."
|
||||
|
||||
msg
|
||||
lines = ['Expectation should not have failed with message:']
|
||||
lines << Shoulda::Matchers::Util.indent(expected, 2)
|
||||
lines.join("\n")
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
|
|
Loading…
Add table
Reference in a new issue