Skip to content

Commit

Permalink
changed isolate_behaviour to isolate_example_group
Browse files Browse the repository at this point in the history
- also did better job of isolation
  • Loading branch information
dchelimsky committed Jan 10, 2010
1 parent b165953 commit 02c001f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def you_call_this_a_blt?
it "should include the given module into each matching behaviour" do
Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include)

isolate_behaviour do
isolate_example_group do
group = Rspec::Core::ExampleGroup.describe(Object, 'does like, stuff and junk', :magic_key => :include) { }
group.should_not respond_to(:you_call_this_a_blt?)
group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
Expand Down
38 changes: 20 additions & 18 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,29 @@ def empty_example_group(name='Empty ExampleGroup Group')
describe '#name' do

it "uses the first parameter as name" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
end
end

it "accepts a constant as the first parameter" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.name.should == 'Object'
end
end

it "concats nested names" do
behaviour_to_test = nil
group = empty_example_group('test')
group.name.should == 'Object test'
isolate_example_group do
behaviour_to_test = nil
group = empty_example_group('test')
group.name.should == 'Object test'

nested_group_one = group.describe('nested one') { }
nested_group_one.name.should == 'Object test nested one'
nested_group_one = group.describe('nested one') { }
nested_group_one.name.should == 'Object test nested one'

nested_group_two = nested_group_one.describe('nested two') { }
nested_group_two.name.should == 'Object test nested one nested two'
nested_group_two = nested_group_one.describe('nested two') { }
nested_group_two.name.should == 'Object test nested one nested two'
end
end

end
Expand All @@ -54,7 +56,7 @@ def empty_example_group(name='Empty ExampleGroup Group')
context "with a constant as the first parameter" do

it "is that constant" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.describes.should == Object
end
end
Expand All @@ -64,7 +66,7 @@ def empty_example_group(name='Empty ExampleGroup Group')
context "with a string as the first parameter" do

it "is nil" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe("i'm a computer") { }.describes.should be_nil
end
end
Expand All @@ -76,13 +78,13 @@ def empty_example_group(name='Empty ExampleGroup Group')
describe '#description' do

it "exposes the second parameter as description" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object, "my desc") { }.description.should == 'my desc'
end
end

it "allows the second parameter to be nil" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object, nil) { }.description.size.should == 0
end
end
Expand All @@ -92,31 +94,31 @@ def empty_example_group(name='Empty ExampleGroup Group')
describe '#metadata' do

it "adds the third parameter to the metadata" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
end
end

it "adds the caller to metadata" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}/
end
end

it "adds the the file_path to metadata" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
end
end

it "has a reader for file_path" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.file_path.should == __FILE__
end
end

it "adds the line_number to metadata" do
isolate_behaviour do
isolate_example_group do
Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/mocha_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use_formatter(formatter) do

isolate_behaviour do
isolate_example_group do
desc = Rspec::Core::ExampleGroup.describe("my favorite pony") do
example("showing a double fail") do
foo = "string"
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/core/world_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Foo; end
it "should find nothing if all describes match the exclusion filter" do
options = { :network_access => true }

isolate_behaviour do
isolate_example_group do
group1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options) do
it("foo") {}
it("bar") {}
Expand All @@ -109,7 +109,7 @@ class Foo; end
@world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
end

isolate_behaviour do
isolate_example_group do
group2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1") do
it("foo", :network_access => true) {}
it("bar") {}
Expand All @@ -121,7 +121,7 @@ class Foo; end
end

it "should find nothing if a regexp matches the exclusion filter" do
isolate_behaviour do
isolate_example_group do
group = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
it("foo") {}
it("bar") {}
Expand Down
12 changes: 9 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ def remove_last_describe_from_world
Rspec::Core.world.behaviours.pop
end

def isolate_behaviour
def isolate_example_group
if block_given?
yield
Rspec::Core.world.behaviours.pop
example_groups = Rspec::Core.world.behaviours.dup
begin
Rspec::Core.world.behaviours.clear
yield
ensure
Rspec::Core.world.behaviours.clear
Rspec::Core.world.behaviours.concat(example_groups)
end
end
end

Expand Down

0 comments on commit 02c001f

Please sign in to comment.