Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
7 Changelog.md
View
@@ -1,3 +1,10 @@
+### dev
+
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.4...master)
+
+* Enhancements
+ * Add example.exception (useful for extensions)
+
### 2.6.4 / 2011-06-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.3...v2.6.4)
6 lib/rspec/core/example.rb
View
@@ -4,6 +4,10 @@ class Example
attr_reader :metadata, :options, :example_group_instance
+ # Returns the first exception raised, if any, in the context of running
+ # this example.
+ attr_reader :exception
+
def self.delegate_to_metadata(*keys)
keys.each do |key|
define_method(key) {@metadata[key]}
@@ -23,7 +27,7 @@ def example_group
@example_group_class
end
- def around_hooks
+ def around_hooks # :nodoc:
@around_hooks ||= example_group.around_hooks_for(self)
end
16 spec/rspec/core/example_spec.rb
View
@@ -16,6 +16,21 @@ def metadata_hash(*args)
end
end
+ describe "#exception" do
+ it "supplies the first exception raised, if any" do
+ example = example_group.example { raise "first" }
+ example_group.after { raise "second" }
+ example_group.run
+ example.exception.message.should eq("first")
+ end
+
+ it "returns nil if there is no exception" do
+ example = example_group.example('example') { }
+ example_group.run
+ example.exception.should be_nil
+ end
+ end
+
describe "auto-generated example descriptions" do
let(:generated_description) { "the generated description" }
let(:rspec_example) { example_group.specify { 5.should == 5 } }
@@ -269,4 +284,5 @@ def assert(val)
end
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.