Created
April 8, 2014 05:17
-
-
Save mieko/10093681 to your computer and use it in GitHub Desktop.
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
describe "The raise method" do | |
it "should clear $! and $@ if no exception is active" do | |
$!.should be_nil | |
$@.should be_nil | |
end | |
it "sets $! and $@ during the body of each rescue clause" do | |
begin | |
raise "ERROR" | |
rescue | |
$!.should_not be_nil | |
$@.should_not be_nil | |
end | |
end | |
it "clears $! and $@ after processing rescue clauses" do | |
begin | |
raise "ERROR" | |
rescue | |
end | |
$!.should be_nil | |
$@.should be_nil | |
end | |
it "clears $! and $@ before executing ensure clauses if the exception was handled" do | |
begin | |
raise "ERROR" | |
rescue | |
# nothing | |
ensure | |
$!.should be_nil | |
$@.should be_nil | |
end | |
end | |
it "clears $! and $@ if no exception was raised" do | |
begin | |
# nothing | |
ensure | |
$!.should be_nil | |
$@.should be_nil | |
end | |
end | |
it "sets $! and $@ in ensure clauses while propogating an exception up the stack" do | |
begin | |
begin | |
raise "ERROR" | |
ensure | |
$!.should_not be_nil | |
$@.should_not be_nil | |
end | |
rescue | |
# eat exceptions | |
ensure | |
# Because of the rescue above, we should now be unset. | |
$!.should be_nil | |
$@.should be_nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment