Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format spec results with pretty inspect #11635

Prev Previous commit
Next Next commit
Merge branch 'master' into format-spec-results-with-pretty-inspect
  • Loading branch information
beta-ziliani authored Dec 20, 2022
commit bde8f5c49d7f08a28d89a40ff3e486010a0cd7a0
33 changes: 9 additions & 24 deletions src/spec/expectations.cr
Original file line number Diff line number Diff line change
@@ -386,29 +386,14 @@ module Spec
def expect_raises(klass : T.class, message : String | Regex | Nil = nil, file = __FILE__, line = __LINE__, &) forall T
# TODO: Enable "expect_raises" for wasm32 after exceptions are working.
end

# `NestingSpecError` is treated as the same above.
if ex.is_a?(Spec::NestingSpecError) && klass != Spec::NestingSpecError
raise ex
end

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
{% else %}
def expect_raises(klass : T.class, message : String | Regex | Nil = nil, file = __FILE__, line = __LINE__) forall T
yield
rescue ex : T
# We usually bubble Spec::AssertionFailed, unless this is the expected exception
if ex.is_a?(Spec::AssertionFailed) && klass != Spec::AssertionFailed
raise ex
end
when Nil
# No need to check the message
end

# `NestingSpecError` is treated as the same above.
if ex.is_a?(Spec::NestingSpecError) && klass != Spec::NestingSpecError
@@ -420,13 +405,13 @@ module Spec
when Regex
unless (ex_to_s =~ message)
backtrace = ex.backtrace.join('\n') { |f| " # #{f}" }
fail "Expected #{klass} with message matching #{message.inspect}, " \
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.inspect}, got #<#{ex.class}: " \
fail "Expected #{klass} with #{message.pretty_inspect}, got #<#{ex.class}: " \
"#{ex_to_s}> with backtrace:\n#{backtrace}", file, line
end
when Nil
You are viewing a condensed version of this merge commit. You can view the full changes here.