Permalink
Browse files

Example has a #state

  • Loading branch information...
1 parent 103abf4 commit e6f2bb3894243c40df6b0f0c7309e9878b90a94c @gsterndale gsterndale committed with dchelimsky Apr 17, 2010
Showing with 20 additions and 1 deletion.
  1. +4 −1 lib/rspec/core/example.rb
  2. +16 −0 spec/rspec/core/example_spec.rb
@@ -2,7 +2,7 @@ module Rspec
module Core
class Example
- attr_reader :metadata, :example_block
+ attr_reader :metadata, :example_block, :state
def self.delegate_to_metadata(*keys)
keys.each do |key|
@@ -35,7 +35,9 @@ def run(example_group_instance, reporter)
exception = nil
begin
+ @state = :before
run_before_each
+ @state = :block
pending_declared_in_example = catch(:pending_declared_in_example) do
if @example_group_class.around_eachs.empty?
@example_group_instance.instance_eval(&example_block) unless pending
@@ -51,6 +53,7 @@ def run(example_group_instance, reporter)
end
begin
+ @state = :after
run_after_each
rescue Exception => e
exception ||= e
@@ -25,6 +25,10 @@
it "should have one for it's block" do
example.should respond_to(:example_block)
end
+
+ it "should have one for its state" do
+ example.should respond_to(:state)
+ end
end
describe '#inspect' do
@@ -87,4 +91,16 @@
after_run.should be_true, "expected after(:each) to be run"
end
end
+
+ describe "#state" do
+ before do
+ running_example.state.should == :before
+ end
+ it "should have block state while running actual example block" do
+ running_example.state.should == :block
+ end
+ after do
+ running_example.state.should == :after
+ end
+ end
end

0 comments on commit e6f2bb3

Please sign in to comment.