Created
November 14, 2011 00:43
-
-
Save jpignata/1362982 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def test_method_explicit_return | |
raise "This should bubble up" | |
ensure | |
return "No problem here" | |
end | |
def test_method_implicit_return | |
raise "This should bubble up" | |
ensure | |
"No problem here" | |
end | |
describe "explicit return" do | |
it "returns 'No problem here?'" do | |
test_method_explicit_return.should == "No problem here" | |
end | |
it "raises an exception?" do | |
expect { | |
test_method_explicit_return | |
}.should raise_exception(RuntimeError, "This should bubble up") | |
end | |
end | |
describe "implicit return" do | |
it "returns 'No problem here?'" do | |
test_method_implicit_return.should == "No problem here" | |
end | |
it "raises an exception?" do | |
expect { | |
test_method_implicit_return | |
}.should raise_exception(RuntimeError, "This should bubble up") | |
end | |
end |
This file contains hidden or 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
jp@usonia:~/workspace/scratch$ rspec --format=doc --color swallowed_exception.rb | |
explicit return | |
returns 'No problem here?' | |
raises an exception? (FAILED - 1) | |
implicit return | |
returns 'No problem here?' (FAILED - 2) | |
raises an exception? | |
Failures: | |
1) explicit return raises an exception? | |
Failure/Error: expect { | |
expected RuntimeError with "This should bubble up" but nothing was raised | |
# ./swallowed_exception.rb:19:in `block (2 levels) in <top (required)>' | |
2) implicit return returns 'No problem here?' | |
Failure/Error: raise "This should bubble up" | |
RuntimeError: | |
This should bubble up | |
# ./swallowed_exception.rb:8:in `test_method_implicit_return' | |
# ./swallowed_exception.rb:27:in `block (2 levels) in <top (required)>' | |
Finished in 0.56132 seconds | |
4 examples, 2 failures | |
Failed examples: | |
rspec ./swallowed_exception.rb:18 # explicit return raises an exception? | |
rspec ./swallowed_exception.rb:26 # implicit return returns 'No problem here?' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment