Skip to content

Commit

Permalink
Rename "running_example" to "example"
Browse files Browse the repository at this point in the history
  • Loading branch information
wincent authored and dchelimsky committed Jun 18, 2010
1 parent f9bcb44 commit 39d692b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion features/hooks/halt.feature
Expand Up @@ -10,7 +10,7 @@ Feature: halt
"""
RSpec.configure do |c|
c.after(:each) do
running_example.halt(:group, :status => 'failed')
example.halt(:group, :status => 'failed')
end
end
describe "something" do
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/core/example.rb
Expand Up @@ -33,7 +33,7 @@ def in_block?
def run(example_group_instance, reporter)
@in_block = false
@example_group_instance = example_group_instance
@example_group_instance.running_example = self
@example_group_instance.example = self

run_started

Expand Down Expand Up @@ -62,7 +62,7 @@ def run(example_group_instance, reporter)
rescue Exception => e
exception ||= e
ensure
@example_group_instance.running_example = nil
@example_group_instance.example = nil
end

if exception
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/example_group.rb
Expand Up @@ -6,7 +6,7 @@ class ExampleGroup
include Let
include Pending

attr_accessor :running_example
attr_accessor :example

def self.world
RSpec.world
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/pending.rb
Expand Up @@ -2,12 +2,12 @@ module RSpec
module Core
module Pending
def pending(message = 'No reason given')
running_example.metadata[:pending] = true
running_example.metadata[:execution_result][:pending_message] = message
example.metadata[:pending] = true
example.metadata[:execution_result][:pending_message] = message
if block_given?
begin
result = yield
running_example.metadata[:pending] = false
example.metadata[:pending] = false
rescue Exception => e
end
raise RSpec::Core::PendingExampleFixedError.new if result
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/subject.rb
Expand Up @@ -80,12 +80,12 @@ def original_subject
end

def attribute_of_subject
original_subject.send(running_example.description) if using_attribute?
original_subject.send(example.description) if using_attribute?
end

def using_attribute?
running_example.in_block? &&
running_example.metadata[:attribute_of_subject]
example.in_block? &&
example.metadata[:attribute_of_subject]
end

end
Expand Down
14 changes: 7 additions & 7 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -20,7 +20,7 @@ module RSpec::Core
group = ExampleGroup.describe("parent") do
describe("child") do
it "does something" do
examples_run << running_example
examples_run << example
end
end
end
Expand Down Expand Up @@ -308,19 +308,19 @@ module RSpec::Core

describe "A sample nested group", :nested_describe => "yep" do
it "sets the described class to the constant Object" do
running_example.example_group.describes.should == Object
example.example_group.describes.should == Object
end

it "sets the description to 'A sample nested describe'" do
running_example.example_group.description.should == 'A sample nested group'
example.example_group.description.should == 'A sample nested group'
end

it "has top level metadata from the example_group and its ancestors" do
running_example.example_group.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
example.example_group.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
end

it "exposes the parent metadata to the contained examples" do
running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
end
end

Expand Down Expand Up @@ -379,11 +379,11 @@ module RSpec::Core
end

it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
end

it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
end

describe "but now I am nested" do
Expand Down
34 changes: 17 additions & 17 deletions spec/rspec/core/example_spec.rb
Expand Up @@ -5,37 +5,37 @@
RSpec::Core::ExampleGroup.describe('group description')
end

let(:example) do
let(:example_instance) do
example_group.example('example description')
end

describe "attr readers" do
it "should have one for the parent example group" do
example.should respond_to(:example_group)
example_instance.should respond_to(:example_group)
end

it "should have one for it's description" do
example.should respond_to(:description)
it "should have one for its description" do
example_instance.should respond_to(:description)
end

it "should have one for it's metadata" do
example.should respond_to(:metadata)
it "should have one for its metadata" do
example_instance.should respond_to(:metadata)
end

it "should have one for it's block" do
example.should respond_to(:example_block)
it "should have one for its block" do
example_instance.should respond_to(:example_block)
end
end

describe '#inspect' do
it "should return 'group description - description'" do
example.inspect.should == 'group description example description'
example_instance.inspect.should == 'group description example description'
end
end

describe '#to_s' do
it "should return #inspect" do
example.to_s.should == example.inspect
example_instance.to_s.should == example_instance.inspect
end
end

Expand All @@ -47,12 +47,12 @@

describe "accessing metadata within a running example" do
it "should have a reference to itself when running" do
running_example.description.should == "should have a reference to itself when running"
example.description.should == "should have a reference to itself when running"
end

it "should be able to access the example group's top level metadata as if it were its own" do
running_example.example_group.metadata.should include(:parent_metadata => 'sample')
running_example.metadata.should include(:parent_metadata => 'sample')
example.example_group.metadata.should include(:parent_metadata => 'sample')
example.metadata.should include(:parent_metadata => 'sample')
end
end

Expand Down Expand Up @@ -81,7 +81,7 @@
after_run = false
group = RSpec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { raise "this error" }
example('example') { raise "this error" }
end
group.run_all
after_run.should be_true, "expected after(:each) to be run"
Expand All @@ -90,13 +90,13 @@

describe "#in_block?" do
before do
running_example.should_not be_in_block
example.should_not be_in_block
end
it "is only true during the example (but not before or after)" do
running_example.should be_in_block
example.should be_in_block
end
after do
running_example.should_not be_in_block
example.should_not be_in_block
end
end
end
2 changes: 1 addition & 1 deletion spec/rspec/core/shared_example_group_spec.rb
Expand Up @@ -172,7 +172,7 @@ def count(scope)
it "has one example" do; end
it "has another example" do; end
it "includes modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
raise "FAIL" unless running_example.example_group.included_modules.include?(RunningSharedExamplesJustForTesting)
raise "FAIL" unless example.example_group.included_modules.include?(RunningSharedExamplesJustForTesting)
end
end
end
Expand Down

0 comments on commit 39d692b

Please sign in to comment.