Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Fix raise error when the expectation target is an error instance.
Browse files Browse the repository at this point in the history
This closes #232

Signed-off-by: Sam Phippen <[email protected]>
  • Loading branch information
Sam Phippen committed Apr 15, 2013
1 parent 20e3f24 commit 94bcf0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Bug fixes
integers (Sam Phippen).
* Fix `have` matcher to handle the fact that on ruby 2.0,
`Enumerator#size` may return nil (Kenta Murata).
* Fix `expect { raise s }.to raise_error(s)` where s is an error instance
(Sam Phippen).

### 2.13.0 / 2013-02-23
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0)
Expand Down
6 changes: 5 additions & 1 deletion lib/rspec/matchers/built_in/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def matches?(given_proc, negative_expectation = false)
@eval_block_passed = false
begin
given_proc.call
rescue @expected_error => @actual_error
rescue expected_error_class => @actual_error
@raised_expected_error = true
@with_expected_message = verify_message
rescue Exception => @actual_error
Expand Down Expand Up @@ -76,6 +76,10 @@ def description

private

def expected_error_class
(@expected_error.is_a? Class) ? @expected_error : @expected_error.class
end

def expected_error
case @expected_message
when nil
Expand Down
5 changes: 5 additions & 0 deletions spec/rspec/matchers/raise_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
expect {raise}.to raise_error
end

it "passes if an error instance is expected" do
s = StandardError.new
expect {raise s}.to raise_error(s)
end

it "fails if nothing is raised" do
expect {
expect {}.to raise_error
Expand Down

0 comments on commit 94bcf0c

Please sign in to comment.