-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
When an expect_raises assertion fails, the expected message goes through #pretty_inspect but the actual message doesn't:
crystal/src/spec/expectations.cr
Lines 403 to 419 in 9082692
| ex_to_s = ex.to_s | |
| case message | |
| when Regex | |
| unless (ex_to_s =~ message) | |
| backtrace = ex.backtrace.join('\n') { |f| " # #{f}" } | |
| fail "Expected #{klass} with message matching #{message.pretty_inspect}, " \ | |
| "got #<#{ex.class}: #{ex_to_s}> with backtrace:\n#{backtrace}", file, line | |
| end | |
| when String | |
| unless ex_to_s.includes?(message) | |
| backtrace = ex.backtrace.join('\n') { |f| " # #{f}" } | |
| fail "Expected #{klass} with #{message.pretty_inspect}, got #<#{ex.class}: " \ | |
| "#{ex_to_s}> with backtrace:\n#{backtrace}", file, line | |
| end | |
| when Nil | |
| # No need to check the message | |
| end |
This leads to some confusing situations where the two messages look identical if, for example, the actual message is already the #inspect form of the expected message:
require "spec"
it do
expect_raises(Exception, %q(a\tb\nc)) do
raise %q(a\tb\nc).inspect
end
endFailures:
1) assert
Failure/Error: expect_raises(Exception, %q(a\tb\nc)) do
Expected Exception with "a\\tb\\nc", got #<Exception: "a\\tb\\nc"> with backtrace:
...
We should make the failure less ambiguous here.
straight-shoota