rspec-core 2.0.0.a5 → 2.0.0.a6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/example_specs/failing/diffing_spec.rb +3 -1
  2. data/example_specs/spec_helper.rb +1 -1
  3. data/features/configuration/spec_opts.feature +7 -7
  4. data/features/example_groups/describe_aliases.feature +1 -1
  5. data/features/example_groups/nested_groups.feature +3 -6
  6. data/features/{before_and_after_blocks/around.feature → hooks/around_hook.feature} +1 -1
  7. data/features/{before_and_after_blocks/before_and_after_blocks.feature → hooks/before_and_after_hooks.feature} +3 -3
  8. data/features/hooks/halt.feature +27 -0
  9. data/features/mock_framework_integration/use_flexmock.feature +1 -1
  10. data/features/mock_framework_integration/use_mocha.feature +1 -1
  11. data/features/mock_framework_integration/use_rr.feature +1 -1
  12. data/features/mock_framework_integration/use_rspec.feature +1 -1
  13. data/features/mocks/block_local_expectations.feature +2 -2
  14. data/features/mocks/mix_stubs_and_mocks.feature +1 -1
  15. data/lib/rspec/core.rb +6 -0
  16. data/lib/rspec/core/around_proxy.rb +14 -0
  17. data/lib/rspec/core/deprecation.rb +25 -26
  18. data/lib/rspec/core/example.rb +11 -21
  19. data/lib/rspec/core/example_group.rb +27 -22
  20. data/lib/rspec/core/runner.rb +12 -12
  21. data/lib/rspec/core/version.rb +1 -1
  22. data/rspec-core.gemspec +13 -11
  23. data/spec/rspec/core/configuration_spec.rb +2 -4
  24. data/spec/rspec/core/example_group_spec.rb +263 -292
  25. data/spec/rspec/core/example_group_subject_spec.rb +26 -31
  26. data/spec/rspec/core/mocha_spec.rb +8 -10
  27. data/spec/rspec/core/pending_example_spec.rb +1 -1
  28. data/spec/rspec/core/runner_spec.rb +2 -2
  29. data/spec/rspec/core/shared_example_group_spec.rb +120 -129
  30. data/spec/rspec/core/world_spec.rb +111 -116
  31. data/spec/rspec/core_spec.rb +2 -2
  32. data/spec/spec_helper.rb +2 -23
  33. metadata +9 -7
@@ -1,45 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
- def describe_double(describes=Object)
4
- group = Rspec::Core::ExampleGroup.describe(describes) {}
5
- remove_last_example_group_from_world
6
- yield group if block_given?
7
- group
8
- end
3
+ module Rspec::Core
9
4
 
10
- describe Rspec::Core::ExampleGroupSubject do
5
+ describe ExampleGroupSubject do
11
6
 
12
- describe "implicit subject" do
13
- describe "with a class" do
14
- it "returns an instance of the class" do
15
- describe_double(Array).subject.call.should == []
7
+ describe "implicit subject" do
8
+ describe "with a class" do
9
+ it "returns an instance of the class" do
10
+ ExampleGroup.create(Array).subject.call.should == []
11
+ end
16
12
  end
17
- end
18
-
19
- describe "with a Module" do
20
- it "returns the Module" do
21
- describe_double(Enumerable).subject.call.should == Enumerable
13
+
14
+ describe "with a Module" do
15
+ it "returns the Module" do
16
+ ExampleGroup.create(Enumerable).subject.call.should == Enumerable
17
+ end
22
18
  end
23
- end
24
-
25
- describe "with a string" do
26
- it "return the string" do
27
- describe_double("Foo").subject.call.should == 'Foo'
19
+
20
+ describe "with a string" do
21
+ it "return the string" do
22
+ ExampleGroup.create("Foo").subject.call.should == 'Foo'
23
+ end
28
24
  end
29
- end
30
25
 
31
- describe "with a number" do
32
- it "returns the number" do
33
- describe_double(15).subject.call.should == 15
26
+ describe "with a number" do
27
+ it "returns the number" do
28
+ ExampleGroup.create(15).subject.call.should == 15
29
+ end
34
30
  end
31
+
35
32
  end
36
33
 
37
- end
38
-
39
- describe "explicit subject" do
34
+ describe "explicit subject" do
40
35
  describe "defined in a top level group" do
41
36
  it "replaces the implicit subject in that group" do
42
- group = describe_double(Array)
37
+ group = ExampleGroup.create(Array)
43
38
  group.subject { [1,2,3] }
44
39
  group.subject.call.should == [1,2,3]
45
40
  end
@@ -47,7 +42,7 @@ describe Rspec::Core::ExampleGroupSubject do
47
42
 
48
43
  describe "defined in a top level group" do
49
44
  before do
50
- @group = describe_double
45
+ @group = ExampleGroup.create
51
46
  @group.subject{ [4,5,6] }
52
47
  end
53
48
 
@@ -63,5 +58,5 @@ describe Rspec::Core::ExampleGroupSubject do
63
58
  end
64
59
  end
65
60
  end
66
-
61
+ end
67
62
  end
@@ -10,16 +10,14 @@ describe "Mocha Regression involving double reporting of errors" do
10
10
 
11
11
  use_formatter(formatter) do
12
12
 
13
- disconnect_from_world do
14
- group = Rspec::Core::ExampleGroup.describe("my favorite pony") do
15
- example("showing a double fail") do
16
- foo = "string"
17
- foo.expects(:something)
18
- end
19
- end
20
- group.examples_to_run.replace(group.examples)
21
- group.run(formatter)
22
- end
13
+ group = Rspec::Core::ExampleGroup.create("my favorite pony") do
14
+ example("showing a double fail") do
15
+ foo = "string"
16
+ foo.expects(:something)
17
+ end
18
+ end
19
+ group.examples_to_run.replace(group.examples)
20
+ group.run(formatter)
23
21
 
24
22
  end
25
23
 
@@ -9,7 +9,7 @@ end
9
9
  describe "an example" do
10
10
  context "with no block" do
11
11
  it "is listed as pending" do
12
- group = isolated_example_group do
12
+ group = Rspec::Core::ExampleGroup.create('group') do
13
13
  it "has no block"
14
14
  end
15
15
  group.run(stub('reporter').as_null_object)
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Runner do
4
4
 
5
- describe 'formatter' do
5
+ describe 'reporter' do
6
6
 
7
7
  it 'should return the configured formatter' do
8
- Rspec::Core::Runner.new.formatter.should == Rspec::Core.configuration.formatter
8
+ Rspec::Core::Runner.new.reporter.should == Rspec::Core.configuration.formatter
9
9
  end
10
10
 
11
11
  end
@@ -1,185 +1,176 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rspec::Core::SharedExampleGroup do
3
+ module Rspec::Core
4
4
 
5
- it "should add the 'share_examples_for' method to the global namespace" do
6
- Kernel.should respond_to(:share_examples_for)
7
- end
8
-
9
- it "should add the 'shared_examples_for' method to the global namespace" do
10
- Kernel.should respond_to(:shared_examples_for)
11
- end
5
+ describe SharedExampleGroup do
12
6
 
13
- it "should add the 'share_as' method to the global namespace" do
14
- Kernel.should respond_to(:share_as)
15
- end
7
+ it "should add the 'share_examples_for' method to the global namespace" do
8
+ Kernel.should respond_to(:share_examples_for)
9
+ end
16
10
 
17
- it "should raise an ArgumentError when adding a second shared example group with the same name" do
18
- group = isolated_example_group('example group')
19
- group.share_examples_for('really important business value') { }
20
- lambda do
21
- group.share_examples_for('really important business value') { }
22
- end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
23
- end
11
+ it "should add the 'shared_examples_for' method to the global namespace" do
12
+ Kernel.should respond_to(:shared_examples_for)
13
+ end
24
14
 
25
- describe "share_examples_for" do
15
+ it "should add the 'share_as' method to the global namespace" do
16
+ Kernel.should respond_to(:share_as)
17
+ end
26
18
 
27
- it "should capture the given name and block in the Worlds collection of shared example groups" do
28
- Rspec::Core.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
29
- share_examples_for(:foo) { }
19
+ it "should raise an ArgumentError when adding a second shared example group with the same name" do
20
+ group = ExampleGroup.create('example group')
21
+ group.share_examples_for('really important business value') { }
22
+ lambda do
23
+ group.share_examples_for('really important business value') { }
24
+ end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
30
25
  end
31
26
 
32
- end
27
+ describe "share_examples_for" do
33
28
 
34
- describe "including shared example_groups using #it_should_behave_like" do
29
+ it "should capture the given name and block in the Worlds collection of shared example groups" do
30
+ Rspec::Core.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
31
+ share_examples_for(:foo) { }
32
+ end
35
33
 
36
- def cleanup_shared_example_groups
37
- original_shared_example_groups = Rspec::Core.world.shared_example_groups
38
- yield if block_given?
39
- Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
40
34
  end
41
35
 
42
- it "should module_eval any found shared example_groups" do
43
- group = isolated_example_group('fake group')
44
- block1 = lambda {}
45
- block2 = lambda {
46
- def extra_helper
47
- 'extra_helper'
48
- end
49
- }
50
- Rspec::Core.world.stub!(:shared_example_groups).and_return({ :a => block1, :shared_example_group => block2 })
51
- group.should_receive(:module_eval).once
52
- group.it_should_behave_like :shared_example_group
53
- end
36
+ describe "including shared example_groups using #it_should_behave_like" do
54
37
 
55
- it "should make any shared example_group available at the correct level" do
56
- group = isolated_example_group('fake group')
57
- block = lambda {
58
- def self.class_helper; end
59
- def extra_helper; end
60
- }
61
- Rspec::Core.world.stub!(:shared_example_groups).and_return({ :shared_example_group => block })
62
- group.it_should_behave_like :shared_example_group
63
- with_ruby(1.8) do
64
- group.instance_methods.should include('extra_helper')
65
- group.singleton_methods.should include('class_helper')
38
+ def cleanup_shared_example_groups
39
+ original_shared_example_groups = Rspec::Core.world.shared_example_groups
40
+ yield if block_given?
41
+ Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
66
42
  end
67
- with_ruby(1.9) do
68
- group.instance_methods.should include(:extra_helper)
69
- group.singleton_methods.should include(:class_helper)
43
+
44
+ it "should make any shared example_group available at the correct level" do
45
+ group = ExampleGroup.create('fake group')
46
+ block = lambda {
47
+ def self.class_helper; end
48
+ def extra_helper; end
49
+ }
50
+ Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
51
+ group.it_should_behave_like :shared_example_group
52
+ with_ruby(1.8) do
53
+ group.instance_methods.should include('extra_helper')
54
+ group.singleton_methods.should include('class_helper')
55
+ end
56
+ with_ruby(1.9) do
57
+ group.instance_methods.should include(:extra_helper)
58
+ group.singleton_methods.should include(:class_helper)
59
+ end
70
60
  end
71
- end
72
61
 
73
- it "should raise when named shared example_group can not be found"
62
+ it "should raise when named shared example_group can not be found"
74
63
 
75
- it "adds examples to current example_group using it_should_behave_like" do
76
- cleanup_shared_example_groups do
77
- group = isolated_example_group("example_group") do
78
- it("i was already here") {}
79
- end
64
+ it "adds examples to current example_group using it_should_behave_like" do
65
+ cleanup_shared_example_groups do
66
+ group = ExampleGroup.create("example_group") do
67
+ it("i was already here") {}
68
+ end
80
69
 
81
- group.examples.size.should == 1
70
+ group.examples.size.should == 1
82
71
 
83
- group.share_examples_for('shared example_group') do
84
- it("shared example") {}
85
- it("shared example 2") {}
86
- end
72
+ group.share_examples_for('shared example_group') do
73
+ it("shared example") {}
74
+ it("shared example 2") {}
75
+ end
87
76
 
88
- group.it_should_behave_like("shared example_group")
77
+ group.it_should_behave_like("shared example_group")
89
78
 
90
- group.examples.size.should == 3
79
+ group.examples.size.should == 3
80
+ end
91
81
  end
92
- end
93
82
 
94
- it "adds examples to from two shared groups" do
95
- cleanup_shared_example_groups do
96
- group = isolated_example_group("example_group") do |g|
97
- g.it("i was already here") {}
98
- end
83
+ it "adds examples to from two shared groups" do
84
+ cleanup_shared_example_groups do
85
+ group = ExampleGroup.create("example_group") do |g|
86
+ g.it("i was already here") {}
87
+ end
99
88
 
100
- group.examples.size.should == 1
89
+ group.examples.size.should == 1
101
90
 
102
- group.share_examples_for('test 2 shared groups') do
103
- it("shared example") {}
104
- it("shared example 2") {}
105
- end
91
+ group.share_examples_for('test 2 shared groups') do
92
+ it("shared example") {}
93
+ it("shared example 2") {}
94
+ end
106
95
 
107
- group.share_examples_for('test 2 shared groups 2') do
108
- it("shared example 3") {}
109
- end
96
+ group.share_examples_for('test 2 shared groups 2') do
97
+ it("shared example 3") {}
98
+ end
110
99
 
111
- group.it_should_behave_like("test 2 shared groups")
112
- group.it_should_behave_like("test 2 shared groups 2")
100
+ group.it_should_behave_like("test 2 shared groups")
101
+ group.it_should_behave_like("test 2 shared groups 2")
113
102
 
114
- group.examples.size.should == 4
103
+ group.examples.size.should == 4
104
+ end
115
105
  end
116
- end
117
106
 
118
- share_as('Cornucopia') do
119
- it "should do foo" do; end
120
- end
107
+ share_as('Cornucopia') do
108
+ it "is plentiful" do
109
+ 5.should == 4
110
+ end
111
+ end
121
112
 
122
- pending "adds examples to current example_group using include", :compat => 'rspec-1.2' do
123
- group = isolated_example_group('group') { include Cornucopia }
124
- group.examples.length.should == 1
125
- end
113
+ it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
114
+ group = ExampleGroup.create('group') { include Cornucopia }
115
+ group.examples.length.should == 1
116
+ group.examples.first.metadata[:description].should == "is plentiful"
117
+ end
126
118
 
127
- it "adds examples to current example_group using it_should_behave_like with a module" do
128
- cleanup_shared_example_groups do
129
- group = isolated_example_group("example_group") {}
119
+ it "adds examples to current example_group using it_should_behave_like with a module" do
120
+ cleanup_shared_example_groups do
121
+ group = ExampleGroup.create("example_group") {}
130
122
 
131
- shared_foo = group.share_as(:FooShared) do
132
- it("shared example") {}
133
- end
123
+ shared_foo = group.share_as(:FooShared) do
124
+ it("shared example") {}
125
+ end
134
126
 
135
- group.it_should_behave_like(::FooShared)
127
+ group.it_should_behave_like(::FooShared)
136
128
 
137
- group.examples.size.should == 1
129
+ group.examples.size.should == 1
130
+ end
138
131
  end
139
- end
140
132
 
141
- describe "running shared examples" do
142
- module RunningSharedExamplesJustForTesting; end
133
+ describe "running shared examples" do
134
+ module RunningSharedExamplesJustForTesting; end
135
+
136
+ share_examples_for("it runs shared examples") do
137
+ include RunningSharedExamplesJustForTesting
143
138
 
144
- share_examples_for("it runs shared examples") do
145
- include RunningSharedExamplesJustForTesting
139
+ def magic
140
+ @magic ||= {}
141
+ end
146
142
 
147
- def magic
148
- @magic ||= {}
143
+ before(:each) { magic[:before_each] = 'each' }
144
+ after(:each) { magic[:after_each] = 'each' }
145
+ before(:all) { magic[:before_all] = 'all' }
149
146
  end
150
147
 
151
- before(:each) { magic[:before_each] = 'each' }
152
- after(:each) { magic[:after_each] = 'each' }
153
- before(:all) { magic[:before_all] = 'all' }
154
- end
148
+ it_should_behave_like "it runs shared examples"
155
149
 
156
- it_should_behave_like "it runs shared examples"
150
+ it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
151
+ magic[:before_each].should == 'each'
152
+ end
157
153
 
158
- it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
159
- magic[:before_each].should == 'each'
160
- end
154
+ it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
161
155
 
162
- it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
156
+ it "should run before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
157
+ magic[:before_all].should == 'all'
158
+ end
163
159
 
164
- it "should run before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
165
- magic[:before_all].should == 'all'
166
- end
160
+ it "should run after(:all) only once from shared example_group", :compat => 'rspec-1.2'
167
161
 
168
- it "should run after(:all) only once from shared example_group", :compat => 'rspec-1.2'
162
+ it "should include modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
163
+ running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
164
+ end
169
165
 
170
- it "should include modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
171
- running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
172
- end
166
+ it "should make methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
167
+ magic.should be_a(Hash)
168
+ end
173
169
 
174
- it "should make methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
175
- # TODO: Consider should have_method(...) simple matcher
176
- with_ruby('1.8') { running_example.example_group.methods.should include('magic') }
177
- with_ruby('1.9') { running_example.example_group.methods.should include(:magic) }
178
170
  end
179
171
 
180
172
  end
181
173
 
182
174
  end
183
175
 
184
-
185
176
  end
@@ -3,146 +3,141 @@ require 'spec_helper'
3
3
  class Bar; end
4
4
  class Foo; end
5
5
 
6
- describe Rspec::Core::World do
7
-
8
- before do
9
- @world = Rspec::Core::World.new
10
- Rspec::Core.stub(:world).and_return(@world)
11
- end
6
+ module Rspec::Core
12
7
 
13
- describe "example groups" do
14
-
15
- it "should contain all defined example groups" do
16
- disconnect_from_world do
17
- example_group = Rspec::Core::ExampleGroup.describe(Bar, 'Empty Example Group') { }
18
- @world.example_groups.should include(example_group)
19
- end
20
- end
21
-
22
- end
23
-
24
- describe "applying inclusion filters" do
25
-
26
- before(:all) do
27
- options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
28
- options_2 = { :pending => true, :feature => 'reporting' }
29
- options_3 = { :array => [1,2,3,4], :color => 'blue' }
30
- @bg1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options_1) { }
31
- @bg2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-2", options_2) { }
32
- @bg3 = Rspec::Core::ExampleGroup.describe(Bar, "find group-3", options_3) { }
33
- @bg4 = Rspec::Core::ExampleGroup.describe(Foo, "find these examples") do
34
- it('I have no options') {}
35
- it("this is awesome", :awesome => true) {}
36
- it("this is too", :awesome => true) {}
37
- it("not so awesome", :awesome => false) {}
38
- it("I also have no options") {}
39
- end
40
- @example_groups = [@bg1, @bg2, @bg3, @bg4]
41
- end
8
+ describe World do
42
9
 
43
- after(:all) do
44
- Rspec::Core.world.example_groups.delete(@bg1)
45
- Rspec::Core.world.example_groups.delete(@bg2)
46
- Rspec::Core.world.example_groups.delete(@bg3)
47
- Rspec::Core.world.example_groups.delete(@bg4)
48
- end
49
-
50
- it "finds no groups when given no search parameters" do
51
- @world.apply_inclusion_filters([]).should == []
52
- end
53
-
54
- it "finds matching groups when filtering on :describes (described class or module)" do
55
- @world.apply_inclusion_filters(@example_groups, :example_group => { :describes => Bar }).should == [@bg1, @bg2, @bg3]
56
- end
57
-
58
- it "finds matching groups when filtering on :description with text" do
59
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => 'find group-1' }).should == [@bg1]
60
- end
61
-
62
- it "finds matching groups when filtering on :description with a lambda" do
63
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [@bg1, @bg3]
10
+ before do
11
+ @world = Rspec::Core::World.new
12
+ Rspec::Core.stub(:world).and_return(@world)
64
13
  end
14
+
15
+ describe "example_groups" do
65
16
 
66
- it "finds matching groups when filtering on :description with a regular expression" do
67
- @world.apply_inclusion_filters(@example_groups, :example_group => { :description => /find group/ }).should == [@bg1, @bg2, @bg3]
68
- end
17
+ it "should contain all defined example groups" do
18
+ group = Rspec::Core::ExampleGroup.describe("group") {}
19
+ @world.example_groups.should include(group)
20
+ end
69
21
 
70
- it "finds one group when searching for :pending => true" do
71
- @world.apply_inclusion_filters(@example_groups, :pending => true ).should == [@bg2]
72
- end
73
-
74
- it "finds matching groups when filtering on arbitrary metadata with a number" do
75
- @world.apply_inclusion_filters(@example_groups, :foo => 1 ).should == [@bg1]
76
22
  end
77
23
 
78
- it "finds matching groups when filtering on arbitrary metadata with an array" do
79
- @world.apply_inclusion_filters(@example_groups, :array => [1,2,3,4]).should == [@bg3]
80
- end
81
-
82
- it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
83
- @world.apply_inclusion_filters(@example_groups, :array => [4,3,2,1]).should be_empty
84
- end
85
-
86
- it "finds matching examples when filtering on arbitrary metadata" do
87
- @world.apply_inclusion_filters(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
88
- end
24
+ describe "applying inclusion filters" do
89
25
 
90
- end
91
-
92
- describe "applying exclusion filters" do
26
+ before(:all) do
27
+ options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
28
+ options_2 = { :pending => true, :feature => 'reporting' }
29
+ options_3 = { :array => [1,2,3,4], :color => 'blue' }
30
+ @bg1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options_1) { }
31
+ @bg2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-2", options_2) { }
32
+ @bg3 = Rspec::Core::ExampleGroup.describe(Bar, "find group-3", options_3) { }
33
+ @bg4 = Rspec::Core::ExampleGroup.describe(Foo, "find these examples") do
34
+ it('I have no options') {}
35
+ it("this is awesome", :awesome => true) {}
36
+ it("this is too", :awesome => true) {}
37
+ it("not so awesome", :awesome => false) {}
38
+ it("I also have no options") {}
39
+ end
40
+ @example_groups = [@bg1, @bg2, @bg3, @bg4]
41
+ end
42
+
43
+ it "finds no groups when given no search parameters" do
44
+ @world.apply_inclusion_filters([]).should == []
45
+ end
93
46
 
94
- it "should find nothing if all describes match the exclusion filter" do
95
- options = { :network_access => true }
47
+ it "finds matching groups when filtering on :describes (described class or module)" do
48
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :describes => Bar }).should == [@bg1, @bg2, @bg3]
49
+ end
96
50
 
97
- group1 = isolated_example_group(Bar, "find group-1", options) do
98
- it("foo") {}
99
- it("bar") {}
51
+ it "finds matching groups when filtering on :description with text" do
52
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => 'find group-1' }).should == [@bg1]
100
53
  end
101
54
 
102
- @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
55
+ it "finds matching groups when filtering on :description with a lambda" do
56
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [@bg1, @bg3]
57
+ end
103
58
 
104
- group2 = isolated_example_group(Bar, "find group-1") do
105
- it("foo", :network_access => true) {}
106
- it("bar") {}
59
+ it "finds matching groups when filtering on :description with a regular expression" do
60
+ @world.apply_inclusion_filters(@example_groups, :example_group => { :description => /find group/ }).should == [@bg1, @bg2, @bg3]
107
61
  end
108
62
 
109
- @world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
110
-
111
- end
63
+ it "finds one group when searching for :pending => true" do
64
+ @world.apply_inclusion_filters(@example_groups, :pending => true ).should == [@bg2]
65
+ end
66
+
67
+ it "finds matching groups when filtering on arbitrary metadata with a number" do
68
+ @world.apply_inclusion_filters(@example_groups, :foo => 1 ).should == [@bg1]
69
+ end
70
+
71
+ it "finds matching groups when filtering on arbitrary metadata with an array" do
72
+ @world.apply_inclusion_filters(@example_groups, :array => [1,2,3,4]).should == [@bg3]
73
+ end
74
+
75
+ it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
76
+ @world.apply_inclusion_filters(@example_groups, :array => [4,3,2,1]).should be_empty
77
+ end
112
78
 
113
- it "should find nothing if a regexp matches the exclusion filter" do
114
- group = isolated_example_group(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
115
- it("foo") {}
116
- it("bar") {}
79
+ it "finds matching examples when filtering on arbitrary metadata" do
80
+ @world.apply_inclusion_filters(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
117
81
  end
118
- @world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
119
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
120
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
121
- :describes => lambda { |b| b == Bar } } ).should == []
122
82
 
123
- @world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
124
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == group.examples
125
- @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == group.examples
126
83
  end
127
84
 
128
- end
129
-
130
- describe "filtering example groups" do
85
+ describe "applying exclusion filters" do
86
+
87
+ it "should find nothing if all describes match the exclusion filter" do
88
+ options = { :network_access => true }
89
+
90
+ group1 = ExampleGroup.create(Bar, "find group-1", options) do
91
+ it("foo") {}
92
+ it("bar") {}
93
+ end
94
+
95
+ @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
96
+
97
+ group2 = ExampleGroup.create(Bar, "find group-1") do
98
+ it("foo", :network_access => true) {}
99
+ it("bar") {}
100
+ end
101
+
102
+ @world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
131
103
 
132
- it "should run matches" do
133
- @group1 = isolated_example_group(Bar, "find these examples") do
134
- it('I have no options', :color => :red, :awesome => true) {}
135
- it("I also have no options", :color => :red, :awesome => true) {}
136
- it("not so awesome", :color => :red, :awesome => false) {}
137
104
  end
138
- Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
139
- Rspec::Core.world.stub(:filter).and_return({ :color => :red })
140
- Rspec::Core.world.stub(:example_groups).and_return([@group1])
141
- filtered_example_groups = @world.filter_example_groups
142
- filtered_example_groups.should == [@group1]
143
- @group1.examples_to_run.should == @group1.examples[0..1]
105
+
106
+ it "should find nothing if a regexp matches the exclusion filter" do
107
+ group = ExampleGroup.create(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
108
+ it("foo") {}
109
+ it("bar") {}
110
+ end
111
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
112
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
113
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
114
+ :describes => lambda { |b| b == Bar } } ).should == []
115
+
116
+ @world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
117
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == group.examples
118
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == group.examples
119
+ end
120
+
144
121
  end
145
122
 
123
+ describe "filtering example groups" do
124
+
125
+ it "should run matches" do
126
+ @group1 = ExampleGroup.create(Bar, "find these examples") do
127
+ it('I have no options', :color => :red, :awesome => true) {}
128
+ it("I also have no options", :color => :red, :awesome => true) {}
129
+ it("not so awesome", :color => :red, :awesome => false) {}
130
+ end
131
+ Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
132
+ Rspec::Core.world.stub(:filter).and_return({ :color => :red })
133
+ Rspec::Core.world.stub(:example_groups).and_return([@group1])
134
+ filtered_example_groups = @world.filter_example_groups
135
+ filtered_example_groups.should == [@group1]
136
+ @group1.examples_to_run.should == @group1.examples[0..1]
137
+ end
138
+
139
+ end
140
+
146
141
  end
147
142
 
148
143
  end