-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
raise(Exception): Setup callstack on raise only if not already set. F…
…ixes #4482. It's useful for reraising of exceptions in `rescue` blocks. As proposed by #4482 (comment). /cc @asterite, @straight-shoota.
- Loading branch information
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "spec" | ||
|
||
struct CallStack # allow clone and equality | ||
def_clone | ||
def_equals @callstack | ||
end | ||
|
||
describe "raise" do | ||
it "should throw exception with existing callstack if already set" do | ||
ex = Exception.new "with callstack" | ||
ex.callstack = CallStack.new | ||
callstack_to_match = ex.callstack.clone | ||
new_ex = expect_raises Exception, "with callstack" do | ||
raise ex | ||
end | ||
new_ex.callstack.should eq(callstack_to_match) | ||
end | ||
|
||
it "should throw exception with new callstack if not already set" do | ||
new_ex = expect_raises Exception, "without callstack" do | ||
raise Exception.new("without callstack") | ||
end | ||
new_ex.callstack.should_not be_nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters