Skip to content
This repository

When no exception is raised in raise_error matcher, include the returned value in the message #34

Merged
merged 1 commit into from over 1 year ago

2 participants

Alex Gaynor Brian Shirai
Alex Gaynor

When no exception is raised, the error message goes from:

Expected ExpectedException (expected)
but no exception was raised

to

Expected ExpectedException (expected)
but no exception was raised (120 was returned)
Brian Shirai brixen merged commit badcf1f into from
Brian Shirai brixen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 31, 2012
Alex Gaynor When no exception is raised in raise_error matcher, include the retur…
…ned value in the error message.
63e0321
This page is out of date. Refresh to see the latest.
4 lib/mspec/matchers/raise_error.rb
@@ -6,7 +6,7 @@ def initialize(exception, message, &block)
6 6 end
7 7
8 8 def matches?(proc)
9   - proc.call
  9 + @result = proc.call
10 10 return false
11 11 rescue Exception => @actual
12 12 return false unless @exception === @actual
@@ -30,7 +30,7 @@ def failure_message
30 30 if @actual then
31 31 message << "but got #{@actual.class}#{%[ (#{@actual.message})] if @actual.message}"
32 32 else
33   - message << "but no exception was raised"
  33 + message << "but no exception was raised (#@result was returned)"
34 34 end
35 35
36 36 message
8 spec/matchers/raise_error_spec.rb
@@ -51,6 +51,14 @@ class UnexpectedException < Exception; end
51 51 ["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"]
52 52 end
53 53
  54 + it "provides a useful failure message when no exception is raised" do
  55 + proc = Proc.new { 120 }
  56 + matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
  57 + matcher.matches?(proc)
  58 + matcher.failure_message.should ==
  59 + ["Expected ExpectedException (expected)", "but no exception was raised (120 was returned)"]
  60 + end
  61 +
54 62 it "provides a useful negative failure message" do
55 63 proc = Proc.new { raise ExpectedException, "expected" }
56 64 matcher = RaiseErrorMatcher.new(ExpectedException, "expected")

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.