Permalink
Browse files

store the exception rescued in match_against_raises

  • Loading branch information...
1 parent 94591f2 commit 88d6ecfd5532da10a9f77ef9b4ce1954781c42f8 @dchelimsky dchelimsky committed Nov 24, 2011
Showing with 8 additions and 3 deletions.
  1. +2 −2 lib/rspec/matchers/base_matcher.rb
  2. +6 −1 spec/rspec/matchers/base_matcher_spec.rb
@@ -11,7 +11,7 @@ module Matchers
module BaseMatcher
include RSpec::Matchers::Pretty
- attr_reader :actual, :expected
+ attr_reader :actual, :expected, :rescued_exception
def initialize(expected=nil)
@expected = expected
@@ -25,7 +25,7 @@ def match_unless_raises(exception=Exception)
begin
yield
true
- rescue exception => e
+ rescue exception => @rescued_exception
false
end
end
@@ -25,7 +25,12 @@ module RSpec::Matchers
matcher.match_unless_raises(ArgumentError){ raise "foo" }
end.to raise_error
end
+
+ it "stores the rescued exception for use in messages" do
+ matcher.match_unless_raises(RuntimeError){ raise "foo" }
+ matcher.rescued_exception.should be_a(RuntimeError)
+ matcher.rescued_exception.message.should eq("foo")
+ end
end
end
-
end

0 comments on commit 88d6ecf

Please sign in to comment.