Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created June 5, 2011 17:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natritmeyer/1009181 to your computer and use it in GitHub Desktop.
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
class RSpec::Core::Example
def passed?
@exception.nil?
end
def failed?
!passed?
end
end
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
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