Created
June 5, 2011 17:17
-
-
Save natritmeyer/1009181 to your computer and use it in GitHub Desktop.
RSpec monkeypatch to expose scenario outcome in after block with Example#passed? and Example#failed? methods
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
class RSpec::Core::Example | |
def passed? | |
@exception.nil? | |
end | |
def failed? | |
!passed? | |
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
describe "something" do | |
it "should pass" do | |
1.should == 1 | |
end | |
it "should fail" do | |
1/0 | |
end | |
after(:each) do | |
puts "Passed!" if example.passed? | |
puts "Failed!" if example.failed? | |
puts example.exception if example.failed? | |
end | |
end | |
=begin | |
Here's what you get when you run the above file: | |
$ rspec rspec_test_result.rb | |
Passed! | |
.Failed! | |
divided by 0 | |
F | |
=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
describe "something else" do | |
it "should fail" do | |
1/0 | |
end | |
after(:each) do | |
puts example.exception | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment