Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add ExampleGroup.create, which decouples creation of an ExampleGroup

class from registration in the world (making spec'ing much easier).
  • Loading branch information...
commit 11d053f21919b911a4e2a914564bc5c2fed167b9 1 parent 5089a32
@dchelimsky dchelimsky authored
View
45 lib/rspec/core/example_group.rb
@@ -58,8 +58,12 @@ def self.examples_to_run
@_examples_to_run ||= []
end
+ def self.superclass_metadata
+ self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
+ end
+
def self.set_it_up(*args)
- @metadata = Rspec::Core::Metadata.process(self.superclass.metadata, *args)
+ @metadata = Rspec::Core::Metadata.process(superclass_metadata, *args)
Rspec::Core.configuration.find_modules(self).each do |include_or_extend, mod, opts|
if include_or_extend == :extend
@@ -97,15 +101,24 @@ def self.file_path
def self.describe(*args, &example_group_block)
raise(ArgumentError, "No arguments given. You must a least supply a type or description") if args.empty?
raise(ArgumentError, "You must supply a block when calling describe") if example_group_block.nil?
+ @_subclass_count ||= 0
+ @_subclass_count += 1
+ const_set(
+ "NestedLevel_#{@_subclass_count}",
+ _build(Class.new(self), caller, args, &example_group_block)
+ )
+ end
- # TODO: Pull out the below into a metadata object, that we can defer the subclassing if necessary
- # describe 'foo', :shared => true will need this to be completed first
- subclass('NestedLevel') do
- args << {} unless args.last.is_a?(Hash)
- args.last.update(:example_group_block => example_group_block, :caller => caller)
- set_it_up(*args)
- module_eval(&example_group_block)
- end
+ def self.create(*args, &example_group_block)
+ _build(dup, caller, args, &example_group_block)
+ end
+
+ def self._build(klass, given_caller, args, &example_group_block)
+ args << {} unless args.last.is_a?(Hash)
+ args.last.update(:example_group_block => example_group_block, :caller => given_caller)
+ klass.set_it_up(*args)
+ klass.module_eval(&example_group_block) if example_group_block
+ klass
end
class << self
@@ -137,7 +150,9 @@ def self.before_all_ivars
end
def self.eval_before_alls(running_example)
- superclass.before_all_ivars.each { |ivar, val| running_example.instance_variable_set(ivar, val) }
+ if superclass.respond_to?(:before_all_ivars)
+ superclass.before_all_ivars.each { |ivar, val| running_example.instance_variable_set(ivar, val) }
+ end
Rspec::Core.configuration.find_advice(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }
before_alls.each { |blk| running_example.instance_eval(&blk) }
@@ -180,16 +195,6 @@ def self.run_examples(example_world, reporter)
end.all?
end
- def self.subclass(base_name, &body) # :nodoc:
- @_subclass_count ||= 0
- @_subclass_count += 1
- klass = Class.new(self)
- class_name = "#{base_name}_#{@_subclass_count}"
- const_set(class_name, klass)
- klass.instance_eval(&body)
- klass
- end
-
def self.to_s
self == Rspec::Core::ExampleGroup ? 'Rspec::Core::ExampleGroup' : name
end
View
6 spec/rspec/core/configuration_spec.rb
@@ -133,7 +133,7 @@ def you_call_this_a_blt?
it "should include the given module into each matching example group" do
Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include)
- group = isolated_example_group('does like, stuff and junk', :magic_key => :include) { }
+ group = Rspec::Core::ExampleGroup.create('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?!?!?"
end
@@ -151,10 +151,8 @@ def that_thing
it "should extend the given module into each matching example group" do
Rspec::Core.configuration.extend(ThatThingISentYou, :magic_key => :extend)
- group = Rspec::Core::ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
-
+ group = Rspec::Core::ExampleGroup.create(ThatThingISentYou, :magic_key => :extend) { }
group.should respond_to(:that_thing)
- remove_last_example_group_from_world
end
end
View
555 spec/rspec/core/example_group_spec.rb
@@ -1,414 +1,385 @@
require 'spec_helper'
-describe Rspec::Core::ExampleGroup do
+module Rspec::Core
- describe "#describe" do
+ describe ExampleGroup do
- it "raises an ArgumentError if no type or description is given" do
- lambda { Rspec::Core::ExampleGroup.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
- end
+ describe "#describe" do
- it "raises an ArgumentError if no block is given" do
- lambda { Rspec::Core::ExampleGroup.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
- end
+ it "raises an ArgumentError if no type or description is given" do
+ lambda { ExampleGroup.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
+ end
- end
+ it "raises an ArgumentError if no block is given" do
+ lambda { ExampleGroup.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
+ end
+
+ end
- describe '#name' do
+ describe '#name' do
- it "uses the first parameter as name" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
+ it "uses the first parameter as name" do
+ ExampleGroup.create("my favorite pony") { }.name.should == 'my favorite pony'
end
- end
- it "accepts a constant as the first parameter" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.name.should == 'Object'
+ it "accepts a constant as the first parameter" do
+ ExampleGroup.create(Object) { }.name.should == 'Object'
end
- end
- it "concats nested names" do
- group = isolated_example_group(Object, 'test')
- group.name.should == 'Object test'
+ it "concats nested names" do
+ group = ExampleGroup.create(Object, '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'
- end
+ nested_group_two = nested_group_one.describe('nested two') { }
+ nested_group_two.name.should == 'Object test nested one nested two'
+ end
- end
+ end
- describe '#describes' do
+ describe '#describes' do
- context "with a constant as the first parameter" do
+ context "with a constant as the first parameter" do
- it "is that constant" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.describes.should == Object
+ it "is that constant" do
+ ExampleGroup.create(Object) { }.describes.should == Object
end
- end
- end
+ end
- context "with a string as the first parameter" do
+ context "with a string as the first parameter" do
- it "is nil" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe("i'm a computer") { }.describes.should be_nil
+ it "is nil" do
+ ExampleGroup.create("i'm a computer") { }.describes.should be_nil
end
+
end
end
- end
-
- describe '#description' do
+ describe '#description' do
- it "exposes the second parameter as description" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object, "my desc") { }.description.should == 'my desc'
+ it "exposes the second parameter as description" do
+ ExampleGroup.create(Object, "my desc") { }.description.should == 'my desc'
end
- end
- it "allows the second parameter to be nil" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object, nil) { }.description.should == ""
+ it "allows the second parameter to be nil" do
+ ExampleGroup.create(Object, nil) { }.description.should == ""
end
- end
- end
+ end
- describe '#metadata' do
+ describe '#metadata' do
- it "adds the third parameter to the metadata" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
+ it "adds the third parameter to the metadata" do
+ ExampleGroup.create(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
end
- end
- it "adds the caller to metadata" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:example_group][:caller].any? {|f|
+ it "adds the caller to metadata" do
+ ExampleGroup.create(Object) { }.metadata[:example_group][:caller].any? {|f|
f =~ /#{__FILE__}/
}.should be_true
end
- end
- it "adds the the file_path to metadata" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should == __FILE__
+ it "adds the the file_path to metadata" do
+ ExampleGroup.create(Object) { }.metadata[:example_group][:file_path].should == __FILE__
end
- end
- it "has a reader for file_path" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.file_path.should == __FILE__
+ it "has a reader for file_path" do
+ ExampleGroup.create(Object) { }.file_path.should == __FILE__
end
- end
- it "adds the line_number to metadata" do
- disconnect_from_world do
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
+ it "adds the line_number to metadata" do
+ ExampleGroup.create(Object) { }.metadata[:example_group][:line_number].should == __LINE__
end
+
end
- it "adds file path and line number metadata for arbitrarily nested describes" do
- Rspec::Core::ExampleGroup.describe(Object) do
- Rspec::Core::ExampleGroup.describe("foo") do
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should == __FILE__
- Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
- end
- end
+ describe "adding before, after, and around hooks" do
- 4.times { remove_last_example_group_from_world }
- end
+ it "should expose the before each blocks at before_eachs" do
+ group = ExampleGroup.create
+ group.before(:each) { 'foo' }
+ group.should have(1).before_eachs
+ end
- end
+ it "should maintain the before each block order" do
+ group = ExampleGroup.create
+ group.before(:each) { 15 }
+ group.before(:each) { 'A' }
+ group.before(:each) { 33.5 }
- describe "adding before, after, and around hooks" do
+ group.before_eachs[0].call.should == 15
+ group.before_eachs[1].call.should == 'A'
+ group.before_eachs[2].call.should == 33.5
+ end
- it "should expose the before each blocks at before_eachs" do
- group = isolated_example_group
- group.before(:each) { 'foo' }
- group.should have(1).before_eachs
- end
+ it "should expose the before all blocks at before_alls" do
+ group = ExampleGroup.create
+ group.before(:all) { 'foo' }
+ group.should have(1).before_alls
+ end
- it "should maintain the before each block order" do
- group = isolated_example_group
- group.before(:each) { 15 }
- group.before(:each) { 'A' }
- group.before(:each) { 33.5 }
+ it "should maintain the before all block order" do
+ group = ExampleGroup.create
+ group.before(:all) { 15 }
+ group.before(:all) { 'A' }
+ group.before(:all) { 33.5 }
- group.before_eachs[0].call.should == 15
- group.before_eachs[1].call.should == 'A'
- group.before_eachs[2].call.should == 33.5
- end
+ group.before_alls[0].call.should == 15
+ group.before_alls[1].call.should == 'A'
+ group.before_alls[2].call.should == 33.5
+ end
- it "should expose the before all blocks at before_alls" do
- group = isolated_example_group
- group.before(:all) { 'foo' }
- group.should have(1).before_alls
- end
+ it "should expose the after each blocks at after_eachs" do
+ group = ExampleGroup.create
+ group.after(:each) { 'foo' }
+ group.should have(1).after_eachs
+ end
- it "should maintain the before all block order" do
- group = isolated_example_group
- group.before(:all) { 15 }
- group.before(:all) { 'A' }
- group.before(:all) { 33.5 }
+ it "should maintain the after each block order" do
+ group = ExampleGroup.create
+ group.after(:each) { 15 }
+ group.after(:each) { 'A' }
+ group.after(:each) { 33.5 }
- group.before_alls[0].call.should == 15
- group.before_alls[1].call.should == 'A'
- group.before_alls[2].call.should == 33.5
- end
+ group.after_eachs[0].call.should == 15
+ group.after_eachs[1].call.should == 'A'
+ group.after_eachs[2].call.should == 33.5
+ end
- it "should expose the after each blocks at after_eachs" do
- group = isolated_example_group
- group.after(:each) { 'foo' }
- group.should have(1).after_eachs
- end
+ it "should expose the after all blocks at after_alls" do
+ group = ExampleGroup.create
+ group.after(:all) { 'foo' }
+ group.should have(1).after_alls
+ end
- it "should maintain the after each block order" do
- group = isolated_example_group
- group.after(:each) { 15 }
- group.after(:each) { 'A' }
- group.after(:each) { 33.5 }
+ it "should maintain the after each block order" do
+ group = ExampleGroup.create
+ group.after(:all) { 15 }
+ group.after(:all) { 'A' }
+ group.after(:all) { 33.5 }
- group.after_eachs[0].call.should == 15
- group.after_eachs[1].call.should == 'A'
- group.after_eachs[2].call.should == 33.5
- end
+ group.after_alls[0].call.should == 15
+ group.after_alls[1].call.should == 'A'
+ group.after_alls[2].call.should == 33.5
+ end
- it "should expose the after all blocks at after_alls" do
- group = isolated_example_group
- group.after(:all) { 'foo' }
- group.should have(1).after_alls
+ it "should expose the around each blocks at after_alls" do
+ group = ExampleGroup.create
+ group.around(:each) { 'foo' }
+ group.should have(1).around_eachs
+ end
+
end
- it "should maintain the after each block order" do
- group = isolated_example_group
- group.after(:all) { 15 }
- group.after(:all) { 'A' }
- group.after(:all) { 33.5 }
+ describe "adding examples" do
- group.after_alls[0].call.should == 15
- group.after_alls[1].call.should == 'A'
- group.after_alls[2].call.should == 33.5
- end
+ it "should allow adding an example using 'it'" do
+ group = ExampleGroup.create
+ group.it("should do something") { }
+ group.examples.size.should == 1
+ end
- it "should expose the around each blocks at after_alls" do
- group = isolated_example_group
- group.around(:each) { 'foo' }
- group.should have(1).around_eachs
- end
-
- end
+ it "should expose all examples at examples" do
+ group = ExampleGroup.create
+ group.it("should do something 1") { }
+ group.it("should do something 2") { }
+ group.it("should do something 3") { }
+ group.examples.size.should == 3
+ end
- describe "adding examples" do
+ it "should maintain the example order" do
+ group = ExampleGroup.create
+ group.it("should 1") { }
+ group.it("should 2") { }
+ group.it("should 3") { }
+ group.examples[0].description.should == 'should 1'
+ group.examples[1].description.should == 'should 2'
+ group.examples[2].description.should == 'should 3'
+ end
- it "should allow adding an example using 'it'" do
- group = isolated_example_group
- group.it("should do something") { }
- group.examples.size.should == 1
end
- it "should expose all examples at examples" do
- group = isolated_example_group
- group.it("should do something 1") { }
- group.it("should do something 2") { }
- group.it("should do something 3") { }
- group.examples.size.should == 3
- end
+ describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
- it "should maintain the example order" do
- group = isolated_example_group
- group.it("should 1") { }
- group.it("should 2") { }
- group.it("should 3") { }
- group.examples[0].description.should == 'should 1'
- group.examples[1].description.should == 'should 2'
- group.examples[2].description.should == 'should 3'
- end
+ 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
+ end
- end
+ it "sets the description to 'A sample nested describe'" do
+ running_example.example_group.description.should == 'A sample nested group'
+ end
- describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
+ 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')
+ end
- 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
+ it "exposes the parent metadata to the contained examples" do
+ running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
+ end
end
- it "sets the description to 'A sample nested describe'" do
- running_example.example_group.description.should == 'A sample nested group'
+ end
+
+ describe "#run_examples" do
+ before do
+ @fake_formatter = Formatters::BaseFormatter.new
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')
+ def stub_example_group
+ stub('example_group',
+ :metadata => Metadata.new.process(
+ 'example_group_name',
+ :caller => ['foo_spec.rb:37']
+ )
+ ).as_null_object
end
- it "exposes the parent metadata to the contained examples" do
- running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
+ it "should return true if all examples pass" do
+ use_formatter(@fake_formatter) do
+ passing_example1 = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
+ passing_example2 = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
+ ExampleGroup.stub(:examples_to_run).and_return([passing_example1, passing_example2])
+
+ ExampleGroup.run_examples(stub_example_group, mock('reporter').as_null_object).should be_true
+ end
end
- end
- end
+ it "should return false if any of the examples return false" do
+ use_formatter(@fake_formatter) do
+ failing_example = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 2 }))
+ passing_example = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
+ ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
- describe "#run_examples" do
- before do
- @fake_formatter = Rspec::Core::Formatters::BaseFormatter.new
- end
+ ExampleGroup.run_examples(stub_example_group, mock('reporter').as_null_object).should be_false
+ end
+ end
- def stub_example_group
- stub('example_group',
- :metadata => Rspec::Core::Metadata.new.process(
- 'example_group_name',
- :caller => ['foo_spec.rb:37']
- )
- ).as_null_object
- end
+ it "should run all examples, regardless of any of them failing" do
+ use_formatter(@fake_formatter) do
+ failing_example = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 2 }))
+ passing_example = Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
+ ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
- it "should return true if all examples pass" do
- use_formatter(@fake_formatter) do
- passing_example1 = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
- passing_example2 = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
- Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([passing_example1, passing_example2])
+ passing_example.should_receive(:run)
- Rspec::Core::ExampleGroup.run_examples(stub_example_group, mock('reporter').as_null_object).should be_true
+ ExampleGroup.run_examples(stub_example_group, mock('reporter', :null_object => true))
+ end
end
+
end
- it "should return false if any of the examples return false" do
- use_formatter(@fake_formatter) do
- failing_example = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 2 }))
- passing_example = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
- Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
+ describe "how instance variables inherit" do
+ before(:all) do
+ @before_all_top_level = 'before_all_top_level'
+ end
- Rspec::Core::ExampleGroup.run_examples(stub_example_group, mock('reporter').as_null_object).should be_false
+ before(:each) do
+ @before_each_top_level = 'before_each_top_level'
end
- end
- it "should run all examples, regardless of any of them failing" do
- use_formatter(@fake_formatter) do
- failing_example = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 2 }))
- passing_example = Rspec::Core::Example.new(stub_example_group, 'description', {}, (lambda { 1.should == 1 }))
- Rspec::Core::ExampleGroup.stub!(:examples_to_run).and_return([failing_example, passing_example])
+ it "should be able to access a before each ivar at the same level" do
+ @before_each_top_level.should == 'before_each_top_level'
+ end
- passing_example.should_receive(:run)
+ it "should be able to access a before all ivar at the same level" do
+ @before_all_top_level.should == 'before_all_top_level'
+ end
- Rspec::Core::ExampleGroup.run_examples(stub_example_group, mock('reporter', :null_object => true))
+ it "should be able to access the before all ivars in the before_all_ivars hash" do
+ with_ruby('1.8') do
+ running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
+ end
+ with_ruby('1.9') do
+ running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
+ end
end
- end
- end
+ describe "but now I am nested" do
+ it "should be able to access a parent example groups before each ivar at a nested level" do
+ @before_each_top_level.should == 'before_each_top_level'
+ end
- describe "how instance variables inherit" do
- before(:all) do
- @before_all_top_level = 'before_all_top_level'
- end
+ it "should be able to access a parent example groups before all ivar at a nested level" do
+ @before_all_top_level.should == "before_all_top_level"
+ end
- before(:each) do
- @before_each_top_level = 'before_each_top_level'
- end
+ it "changes to before all ivars from within an example do not persist outside the current describe" do
+ @before_all_top_level = "ive been changed"
+ end
- it "should be able to access a before each ivar at the same level" do
- @before_each_top_level.should == 'before_each_top_level'
- end
+ describe "accessing a before_all ivar that was changed in a parent example_group" do
+ it "does not have access to the modified version" do
+ @before_all_top_level.should == 'before_all_top_level'
+ end
+ end
+ end
- it "should be able to access a before all ivar at the same level" do
- @before_all_top_level.should == 'before_all_top_level'
end
- it "should be able to access the before all ivars in the before_all_ivars hash" do
- with_ruby('1.8') do
- running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
+ describe "ivars are not shared across examples" do
+ it "(first example)" do
+ @a = 1
+ @b.should be_nil
end
- with_ruby('1.9') do
- running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
- end
- end
- describe "but now I am nested" do
- it "should be able to access a parent example groups before each ivar at a nested level" do
- @before_each_top_level.should == 'before_each_top_level'
+ it "(second example)" do
+ @b = 2
+ @a.should be_nil
end
+ end
- it "should be able to access a parent example groups before all ivar at a nested level" do
- @before_all_top_level.should == "before_all_top_level"
+ describe "#let" do
+ let(:counter) do
+ Class.new do
+ def initialize
+ @count = 0
+ end
+ def count
+ @count += 1
+ end
+ end.new
end
- it "changes to before all ivars from within an example do not persist outside the current describe" do
- @before_all_top_level = "ive been changed"
+ it "generates an instance method" do
+ counter.count.should == 1
end
- describe "accessing a before_all ivar that was changed in a parent example_group" do
- it "does not have access to the modified version" do
- @before_all_top_level.should == 'before_all_top_level'
- end
+ it "caches the value" do
+ counter.count.should == 1
+ counter.count.should == 2
end
end
- end
-
- describe "ivars are not shared across examples" do
- it "(first example)" do
- @a = 1
- @b.should be_nil
- end
-
- it "(second example)" do
- @b = 2
- @a.should be_nil
- end
- end
+ describe "#around" do
+ class Thing
+ def self.cache
+ @cache ||= []
+ end
- describe "#let" do
- let(:counter) do
- Class.new do
def initialize
- @count = 0
- end
- def count
- @count += 1
+ self.class.cache << self
end
- end.new
- end
-
- it "generates an instance method" do
- counter.count.should == 1
- end
-
- it "caches the value" do
- counter.count.should == 1
- counter.count.should == 2
- end
- end
-
- describe "#around" do
- class Thing
- def self.cache
- @cache ||= []
end
- def initialize
- self.class.cache << self
+ around(:each) do |example|
+ Thing.new
+ example.run
+ Thing.cache.clear
end
- end
-
- around(:each) do |example|
- Thing.new
- example.run
- Thing.cache.clear
- end
- it "has 1 Thing (1)" do
- Thing.cache.length.should == 1
- end
+ it "has 1 Thing (1)" do
+ Thing.cache.length.should == 1
+ end
- it "has 1 Thing (2)" do
- Thing.cache.length.should == 1
+ it "has 1 Thing (2)" do
+ Thing.cache.length.should == 1
+ end
end
end
+
end
View
57 spec/rspec/core/example_group_subject_spec.rb
@@ -1,45 +1,40 @@
require 'spec_helper'
-def describe_double(describes=Object)
- group = Rspec::Core::ExampleGroup.describe(describes) {}
- remove_last_example_group_from_world
- yield group if block_given?
- group
-end
+module Rspec::Core
-describe Rspec::Core::ExampleGroupSubject do
+ describe ExampleGroupSubject do
- describe "implicit subject" do
- describe "with a class" do
- it "returns an instance of the class" do
- describe_double(Array).subject.call.should == []
+ describe "implicit subject" do
+ describe "with a class" do
+ it "returns an instance of the class" do
+ ExampleGroup.create(Array).subject.call.should == []
+ end
end
- end
-
- describe "with a Module" do
- it "returns the Module" do
- describe_double(Enumerable).subject.call.should == Enumerable
+
+ describe "with a Module" do
+ it "returns the Module" do
+ ExampleGroup.create(Enumerable).subject.call.should == Enumerable
+ end
end
- end
-
- describe "with a string" do
- it "return the string" do
- describe_double("Foo").subject.call.should == 'Foo'
+
+ describe "with a string" do
+ it "return the string" do
+ ExampleGroup.create("Foo").subject.call.should == 'Foo'
+ end
end
- end
- describe "with a number" do
- it "returns the number" do
- describe_double(15).subject.call.should == 15
+ describe "with a number" do
+ it "returns the number" do
+ ExampleGroup.create(15).subject.call.should == 15
+ end
end
+
end
- end
-
- describe "explicit subject" do
+ describe "explicit subject" do
describe "defined in a top level group" do
it "replaces the implicit subject in that group" do
- group = describe_double(Array)
+ group = ExampleGroup.create(Array)
group.subject { [1,2,3] }
group.subject.call.should == [1,2,3]
end
@@ -47,7 +42,7 @@ def describe_double(describes=Object)
describe "defined in a top level group" do
before do
- @group = describe_double
+ @group = ExampleGroup.create
@group.subject{ [4,5,6] }
end
@@ -63,5 +58,5 @@ def describe_double(describes=Object)
end
end
end
-
+ end
end
View
18 spec/rspec/core/mocha_spec.rb
@@ -10,16 +10,14 @@
use_formatter(formatter) do
- disconnect_from_world do
- group = Rspec::Core::ExampleGroup.describe("my favorite pony") do
- example("showing a double fail") do
- foo = "string"
- foo.expects(:something)
- end
- end
- group.examples_to_run.replace(group.examples)
- group.run(formatter)
- end
+ group = Rspec::Core::ExampleGroup.create("my favorite pony") do
+ example("showing a double fail") do
+ foo = "string"
+ foo.expects(:something)
+ end
+ end
+ group.examples_to_run.replace(group.examples)
+ group.run(formatter)
end
View
2  spec/rspec/core/pending_example_spec.rb
@@ -9,7 +9,7 @@
describe "an example" do
context "with no block" do
it "is listed as pending" do
- group = isolated_example_group do
+ group = Rspec::Core::ExampleGroup.create('group') do
it "has no block"
end
group.run(stub('reporter').as_null_object)
View
249 spec/rspec/core/shared_example_group_spec.rb
@@ -1,185 +1,176 @@
require 'spec_helper'
-describe Rspec::Core::SharedExampleGroup do
+module Rspec::Core
- it "should add the 'share_examples_for' method to the global namespace" do
- Kernel.should respond_to(:share_examples_for)
- end
-
- it "should add the 'shared_examples_for' method to the global namespace" do
- Kernel.should respond_to(:shared_examples_for)
- end
+ describe SharedExampleGroup do
- it "should add the 'share_as' method to the global namespace" do
- Kernel.should respond_to(:share_as)
- end
+ it "should add the 'share_examples_for' method to the global namespace" do
+ Kernel.should respond_to(:share_examples_for)
+ end
- it "should raise an ArgumentError when adding a second shared example group with the same name" do
- group = isolated_example_group('example group')
- group.share_examples_for('really important business value') { }
- lambda do
- group.share_examples_for('really important business value') { }
- end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
- end
+ it "should add the 'shared_examples_for' method to the global namespace" do
+ Kernel.should respond_to(:shared_examples_for)
+ end
- describe "share_examples_for" do
+ it "should add the 'share_as' method to the global namespace" do
+ Kernel.should respond_to(:share_as)
+ end
- it "should capture the given name and block in the Worlds collection of shared example groups" do
- Rspec::Core.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
- share_examples_for(:foo) { }
+ it "should raise an ArgumentError when adding a second shared example group with the same name" do
+ group = ExampleGroup.create('example group')
+ group.share_examples_for('really important business value') { }
+ lambda do
+ group.share_examples_for('really important business value') { }
+ end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
end
- end
+ describe "share_examples_for" do
- describe "including shared example_groups using #it_should_behave_like" do
+ it "should capture the given name and block in the Worlds collection of shared example groups" do
+ Rspec::Core.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
+ share_examples_for(:foo) { }
+ end
- def cleanup_shared_example_groups
- original_shared_example_groups = Rspec::Core.world.shared_example_groups
- yield if block_given?
- Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
end
- it "should module_eval any found shared example_groups" do
- group = isolated_example_group('fake group')
- block1 = lambda {}
- block2 = lambda {
- def extra_helper
- 'extra_helper'
- end
- }
- Rspec::Core.world.stub!(:shared_example_groups).and_return({ :a => block1, :shared_example_group => block2 })
- group.should_receive(:module_eval).once
- group.it_should_behave_like :shared_example_group
- end
+ describe "including shared example_groups using #it_should_behave_like" do
- it "should make any shared example_group available at the correct level" do
- group = isolated_example_group('fake group')
- block = lambda {
- def self.class_helper; end
- def extra_helper; end
- }
- Rspec::Core.world.stub!(:shared_example_groups).and_return({ :shared_example_group => block })
- group.it_should_behave_like :shared_example_group
- with_ruby(1.8) do
- group.instance_methods.should include('extra_helper')
- group.singleton_methods.should include('class_helper')
+ def cleanup_shared_example_groups
+ original_shared_example_groups = Rspec::Core.world.shared_example_groups
+ yield if block_given?
+ Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
end
- with_ruby(1.9) do
- group.instance_methods.should include(:extra_helper)
- group.singleton_methods.should include(:class_helper)
+
+ it "should make any shared example_group available at the correct level" do
+ group = ExampleGroup.create('fake group')
+ block = lambda {
+ def self.class_helper; end
+ def extra_helper; end
+ }
+ Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
+ group.it_should_behave_like :shared_example_group
+ with_ruby(1.8) do
+ group.instance_methods.should include('extra_helper')
+ group.singleton_methods.should include('class_helper')
+ end
+ with_ruby(1.9) do
+ group.instance_methods.should include(:extra_helper)
+ group.singleton_methods.should include(:class_helper)
+ end
end
- end
- it "should raise when named shared example_group can not be found"
+ it "should raise when named shared example_group can not be found"
- it "adds examples to current example_group using it_should_behave_like" do
- cleanup_shared_example_groups do
- group = isolated_example_group("example_group") do
- it("i was already here") {}
- end
+ it "adds examples to current example_group using it_should_behave_like" do
+ cleanup_shared_example_groups do
+ group = ExampleGroup.create("example_group") do
+ it("i was already here") {}
+ end
- group.examples.size.should == 1
+ group.examples.size.should == 1
- group.share_examples_for('shared example_group') do
- it("shared example") {}
- it("shared example 2") {}
- end
+ group.share_examples_for('shared example_group') do
+ it("shared example") {}
+ it("shared example 2") {}
+ end
- group.it_should_behave_like("shared example_group")
+ group.it_should_behave_like("shared example_group")
- group.examples.size.should == 3
+ group.examples.size.should == 3
+ end
end
- end
- it "adds examples to from two shared groups" do
- cleanup_shared_example_groups do
- group = isolated_example_group("example_group") do |g|
- g.it("i was already here") {}
- end
+ it "adds examples to from two shared groups" do
+ cleanup_shared_example_groups do
+ group = ExampleGroup.create("example_group") do |g|
+ g.it("i was already here") {}
+ end
- group.examples.size.should == 1
+ group.examples.size.should == 1
- group.share_examples_for('test 2 shared groups') do
- it("shared example") {}
- it("shared example 2") {}
- end
+ group.share_examples_for('test 2 shared groups') do
+ it("shared example") {}
+ it("shared example 2") {}
+ end
- group.share_examples_for('test 2 shared groups 2') do
- it("shared example 3") {}
- end
+ group.share_examples_for('test 2 shared groups 2') do
+ it("shared example 3") {}
+ end
- group.it_should_behave_like("test 2 shared groups")
- group.it_should_behave_like("test 2 shared groups 2")
+ group.it_should_behave_like("test 2 shared groups")
+ group.it_should_behave_like("test 2 shared groups 2")
- group.examples.size.should == 4
+ group.examples.size.should == 4
+ end
end
- end
- share_as('Cornucopia') do
- it "should do foo" do; end
- end
+ share_as('Cornucopia') do
+ it "is plentiful" do
+ 5.should == 4
+ end
+ end
- pending "adds examples to current example_group using include", :compat => 'rspec-1.2' do
- group = isolated_example_group('group') { include Cornucopia }
- group.examples.length.should == 1
- end
+ it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
+ group = ExampleGroup.create('group') { include Cornucopia }
+ group.examples.length.should == 1
+ group.examples.first.metadata[:description].should == "is plentiful"
+ end
- it "adds examples to current example_group using it_should_behave_like with a module" do
- cleanup_shared_example_groups do
- group = isolated_example_group("example_group") {}
+ it "adds examples to current example_group using it_should_behave_like with a module" do
+ cleanup_shared_example_groups do
+ group = ExampleGroup.create("example_group") {}
- shared_foo = group.share_as(:FooShared) do
- it("shared example") {}
- end
+ shared_foo = group.share_as(:FooShared) do
+ it("shared example") {}
+ end
- group.it_should_behave_like(::FooShared)
+ group.it_should_behave_like(::FooShared)
- group.examples.size.should == 1
+ group.examples.size.should == 1
+ end
end
- end
- describe "running shared examples" do
- module RunningSharedExamplesJustForTesting; end
+ describe "running shared examples" do
+ module RunningSharedExamplesJustForTesting; end
+
+ share_examples_for("it runs shared examples") do
+ include RunningSharedExamplesJustForTesting
- share_examples_for("it runs shared examples") do
- include RunningSharedExamplesJustForTesting
+ def magic
+ @magic ||= {}
+ end
- def magic
- @magic ||= {}
+ before(:each) { magic[:before_each] = 'each' }
+ after(:each) { magic[:after_each] = 'each' }
+ before(:all) { magic[:before_all] = 'all' }
end
- before(:each) { magic[:before_each] = 'each' }
- after(:each) { magic[:after_each] = 'each' }
- before(:all) { magic[:before_all] = 'all' }
- end
+ it_should_behave_like "it runs shared examples"
- it_should_behave_like "it runs shared examples"
+ it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
+ magic[:before_each].should == 'each'
+ end
- it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
- magic[:before_each].should == 'each'
- end
+ it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
- it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
+ it "should run before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
+ magic[:before_all].should == 'all'
+ end
- it "should run before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
- magic[:before_all].should == 'all'
- end
+ it "should run after(:all) only once from shared example_group", :compat => 'rspec-1.2'
- it "should run after(:all) only once from shared example_group", :compat => 'rspec-1.2'
+ it "should include modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
+ running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
+ end
- it "should include modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
- running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
- end
+ it "should make methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
+ magic.should be_a(Hash)
+ end
- it "should make methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
- # TODO: Consider should have_method(...) simple matcher
- with_ruby('1.8') { running_example.example_group.methods.should include('magic') }
- with_ruby('1.9') { running_example.example_group.methods.should include(:magic) }
end
end
end
-
end
View
227 spec/rspec/core/world_spec.rb
@@ -3,146 +3,141 @@
class Bar; end
class Foo; end
-describe Rspec::Core::World do
-
- before do
- @world = Rspec::Core::World.new
- Rspec::Core.stub(:world).and_return(@world)
- end
+module Rspec::Core
- describe "example groups" do
-
- it "should contain all defined example groups" do
- disconnect_from_world do
- example_group = Rspec::Core::ExampleGroup.describe(Bar, 'Empty Example Group') { }
- @world.example_groups.should include(example_group)
- end
- end
-
- end
-
- describe "applying inclusion filters" do
-
- before(:all) do
- options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
- options_2 = { :pending => true, :feature => 'reporting' }
- options_3 = { :array => [1,2,3,4], :color => 'blue' }
- @bg1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options_1) { }
- @bg2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-2", options_2) { }
- @bg3 = Rspec::Core::ExampleGroup.describe(Bar, "find group-3", options_3) { }
- @bg4 = Rspec::Core::ExampleGroup.describe(Foo, "find these examples") do
- it('I have no options') {}
- it("this is awesome", :awesome => true) {}
- it("this is too", :awesome => true) {}
- it("not so awesome", :awesome => false) {}
- it("I also have no options") {}
- end
- @example_groups = [@bg1, @bg2, @bg3, @bg4]
- end
+ describe World do
- after(:all) do
- Rspec::Core.world.example_groups.delete(@bg1)
- Rspec::Core.world.example_groups.delete(@bg2)
- Rspec::Core.world.example_groups.delete(@bg3)
- Rspec::Core.world.example_groups.delete(@bg4)
- end
-
- it "finds no groups when given no search parameters" do
- @world.apply_inclusion_filters([]).should == []
- end
-
- it "finds matching groups when filtering on :describes (described class or module)" do
- @world.apply_inclusion_filters(@example_groups, :example_group => { :describes => Bar }).should == [@bg1, @bg2, @bg3]
- end
-
- it "finds matching groups when filtering on :description with text" do
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => 'find group-1' }).should == [@bg1]
- end
-
- it "finds matching groups when filtering on :description with a lambda" do
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [@bg1, @bg3]
+ before do
+ @world = Rspec::Core::World.new
+ Rspec::Core.stub(:world).and_return(@world)
end
+
+ describe "example_groups" do
- it "finds matching groups when filtering on :description with a regular expression" do
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => /find group/ }).should == [@bg1, @bg2, @bg3]
- end
+ it "should contain all defined example groups" do
+ group = Rspec::Core::ExampleGroup.describe("group") {}
+ @world.example_groups.should include(group)
+ end
- it "finds one group when searching for :pending => true" do
- @world.apply_inclusion_filters(@example_groups, :pending => true ).should == [@bg2]
- end
-
- it "finds matching groups when filtering on arbitrary metadata with a number" do
- @world.apply_inclusion_filters(@example_groups, :foo => 1 ).should == [@bg1]
end
- it "finds matching groups when filtering on arbitrary metadata with an array" do
- @world.apply_inclusion_filters(@example_groups, :array => [1,2,3,4]).should == [@bg3]
- end
-
- it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
- @world.apply_inclusion_filters(@example_groups, :array => [4,3,2,1]).should be_empty
- end
-
- it "finds matching examples when filtering on arbitrary metadata" do
- @world.apply_inclusion_filters(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
- end
+ describe "applying inclusion filters" do
- end
-
- describe "applying exclusion filters" do
+ before(:all) do
+ options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
+ options_2 = { :pending => true, :feature => 'reporting' }
+ options_3 = { :array => [1,2,3,4], :color => 'blue' }
+ @bg1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options_1) { }
+ @bg2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-2", options_2) { }
+ @bg3 = Rspec::Core::ExampleGroup.describe(Bar, "find group-3", options_3) { }
+ @bg4 = Rspec::Core::ExampleGroup.describe(Foo, "find these examples") do
+ it('I have no options') {}
+ it("this is awesome", :awesome => true) {}
+ it("this is too", :awesome => true) {}
+ it("not so awesome", :awesome => false) {}
+ it("I also have no options") {}
+ end
+ @example_groups = [@bg1, @bg2, @bg3, @bg4]
+ end
+
+ it "finds no groups when given no search parameters" do
+ @world.apply_inclusion_filters([]).should == []
+ end
- it "should find nothing if all describes match the exclusion filter" do
- options = { :network_access => true }
+ it "finds matching groups when filtering on :describes (described class or module)" do
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :describes => Bar }).should == [@bg1, @bg2, @bg3]
+ end
- group1 = isolated_example_group(Bar, "find group-1", options) do
- it("foo") {}
- it("bar") {}
+ it "finds matching groups when filtering on :description with text" do
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => 'find group-1' }).should == [@bg1]
end
- @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
+ it "finds matching groups when filtering on :description with a lambda" do
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [@bg1, @bg3]
+ end
- group2 = isolated_example_group(Bar, "find group-1") do
- it("foo", :network_access => true) {}
- it("bar") {}
+ it "finds matching groups when filtering on :description with a regular expression" do
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => /find group/ }).should == [@bg1, @bg2, @bg3]
end
- @world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
-
- end
+ it "finds one group when searching for :pending => true" do
+ @world.apply_inclusion_filters(@example_groups, :pending => true ).should == [@bg2]
+ end
+
+ it "finds matching groups when filtering on arbitrary metadata with a number" do
+ @world.apply_inclusion_filters(@example_groups, :foo => 1 ).should == [@bg1]
+ end
+
+ it "finds matching groups when filtering on arbitrary metadata with an array" do
+ @world.apply_inclusion_filters(@example_groups, :array => [1,2,3,4]).should == [@bg3]
+ end
+
+ it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
+ @world.apply_inclusion_filters(@example_groups, :array => [4,3,2,1]).should be_empty
+ end
- it "should find nothing if a regexp matches the exclusion filter" do
- group = isolated_example_group(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
- it("foo") {}
- it("bar") {}
+ it "finds matching examples when filtering on arbitrary metadata" do
+ @world.apply_inclusion_filters(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
end
- @world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
- :describes => lambda { |b| b == Bar } } ).should == []
- @world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == group.examples
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == group.examples
end
- end
-
- describe "filtering example groups" do
+ describe "applying exclusion filters" do
+
+ it "should find nothing if all describes match the exclusion filter" do
+ options = { :network_access => true }
+
+ group1 = ExampleGroup.create(Bar, "find group-1", options) do
+ it("foo") {}
+ it("bar") {}
+ end
+
+ @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
+
+ group2 = ExampleGroup.create(Bar, "find group-1") do
+ it("foo", :network_access => true) {}
+ it("bar") {}
+ end
+
+ @world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
- it "should run matches" do
- @group1 = isolated_example_group(Bar, "find these examples") do
- it('I have no options', :color => :red, :awesome => true) {}
- it("I also have no options", :color => :red, :awesome => true) {}
- it("not so awesome", :color => :red, :awesome => false) {}
end
- Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
- Rspec::Core.world.stub(:filter).and_return({ :color => :red })
- Rspec::Core.world.stub(:example_groups).and_return([@group1])
- filtered_example_groups = @world.filter_example_groups
- filtered_example_groups.should == [@group1]
- @group1.examples_to_run.should == @group1.examples[0..1]
+
+ it "should find nothing if a regexp matches the exclusion filter" do
+ group = ExampleGroup.create(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
+ it("foo") {}
+ it("bar") {}
+ end
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
+ :describes => lambda { |b| b == Bar } } ).should == []
+
+ @world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == group.examples
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == group.examples
+ end
+
end
+ describe "filtering example groups" do
+
+ it "should run matches" do
+ @group1 = ExampleGroup.create(Bar, "find these examples") do
+ it('I have no options', :color => :red, :awesome => true) {}
+ it("I also have no options", :color => :red, :awesome => true) {}
+ it("not so awesome", :color => :red, :awesome => false) {}
+ end
+ Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
+ Rspec::Core.world.stub(:filter).and_return({ :color => :red })
+ Rspec::Core.world.stub(:example_groups).and_return([@group1])
+ filtered_example_groups = @world.filter_example_groups
+ filtered_example_groups.should == [@group1]
+ @group1.examples_to_run.should == @group1.examples[0..1]
+ end
+
+ end
+
end
end
View
23 spec/spec_helper.rb
@@ -10,7 +10,7 @@
Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
def with_ruby(version)
- yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
+ yield if RUBY_VERSION.to_s =~ Regexp.compile("^#{version}")
end
module Rspec
@@ -27,27 +27,6 @@ def fail_with(message)
end
end
-def remove_last_example_group_from_world
- Rspec::Core.world.example_groups.pop
-end
-
-def disconnect_from_world
- example_groups = Rspec::Core.world.example_groups.dup
- Rspec::Core.world.example_groups.clear
- yield
-ensure
- Rspec::Core.world.example_groups.clear
- Rspec::Core.world.example_groups.concat(example_groups)
-end
-
-def isolated_example_group(*args, &block)
- block ||= lambda {}
- args << 'example group' if args.empty?
- group = Rspec::Core::ExampleGroup.describe(*args, &block)
- remove_last_example_group_from_world
- group
-end
-
def use_formatter(new_formatter)
original_formatter = Rspec::Core.configuration.formatter
Rspec::Core.configuration.instance_variable_set(:@formatter, new_formatter)
Please sign in to comment.
Something went wrong with that request. Please try again.