dchelimsky-rspec 1.1.12 → 1.1.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. data/History.txt +35 -0
  2. data/License.txt +1 -1
  3. data/Manifest.txt +22 -73
  4. data/README.txt +2 -2
  5. data/Rakefile +32 -7
  6. data/TODO.txt +9 -4
  7. data/bin/spec +1 -1
  8. data/cucumber.yml +2 -0
  9. data/examples/failing/spec_helper.rb +1 -1
  10. data/examples/passing/filtered_formatter.rb +18 -0
  11. data/examples/passing/filtered_formatter_example.rb +31 -0
  12. data/examples/passing/spec_helper.rb +1 -1
  13. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
  14. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  15. data/features/example_groups/autogenerated_docstrings.feature +2 -2
  16. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  17. data/features/example_groups/nested_groups.feature +1 -1
  18. data/features/interop/examples_and_tests_together.feature +1 -1
  19. data/features/interop/test_but_not_test_unit.feature +1 -1
  20. data/features/interop/test_case_with_should_methods.feature +1 -1
  21. data/features/mock_framework_integration/use_flexmock.feature +22 -4
  22. data/features/mock_framework_integration/use_mocha.feature +27 -0
  23. data/features/mock_framework_integration/use_rr.feature +27 -0
  24. data/features/step_definitions/running_rspec.rb +5 -3
  25. data/features/support/env.rb +1 -1
  26. data/features-pending/cli/conditional_exclusion.feature +39 -0
  27. data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +1 -0
  28. data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +1 -0
  29. data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +1 -0
  30. data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
  31. data/lib/spec/autorun.rb +3 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +5 -20
  33. data/lib/spec/example/example_description.rb +15 -0
  34. data/lib/spec/example/example_group.rb +0 -15
  35. data/lib/spec/example/example_group_factory.rb +34 -46
  36. data/lib/spec/example/example_group_hierarchy.rb +53 -0
  37. data/lib/spec/example/example_group_methods.rb +96 -211
  38. data/lib/spec/example/example_methods.rb +62 -81
  39. data/lib/spec/example/module_reopening_fix.rb +23 -1
  40. data/lib/spec/example/predicate_matchers.rb +47 -0
  41. data/lib/spec/example/subject.rb +91 -0
  42. data/lib/spec/example.rb +4 -0
  43. data/lib/spec/expectations/extensions.rb +0 -1
  44. data/lib/spec/expectations/handler.rb +6 -1
  45. data/lib/spec/expectations.rb +1 -1
  46. data/lib/spec/interop/test/unit/testcase.rb +5 -22
  47. data/lib/spec/interop/test.rb +1 -0
  48. data/lib/spec/matchers/be.rb +2 -7
  49. data/lib/spec/matchers/be_close.rb +20 -5
  50. data/lib/spec/matchers/change.rb +5 -3
  51. data/lib/spec/matchers/eql.rb +24 -6
  52. data/lib/spec/matchers/equal.rb +24 -6
  53. data/lib/spec/matchers/exist.rb +21 -5
  54. data/lib/spec/matchers/generated_descriptions.rb +2 -2
  55. data/lib/spec/matchers/has.rb +28 -11
  56. data/lib/spec/matchers/match.rb +25 -7
  57. data/lib/spec/matchers/match_array.rb +1 -1
  58. data/lib/spec/matchers/method_missing.rb +2 -2
  59. data/lib/spec/matchers/operator_matcher.rb +12 -5
  60. data/lib/spec/matchers/raise_error.rb +1 -1
  61. data/lib/spec/matchers/respond_to.rb +1 -1
  62. data/lib/spec/matchers/satisfy.rb +5 -5
  63. data/lib/spec/matchers/throw_symbol.rb +1 -3
  64. data/lib/spec/mocks/argument_expectation.rb +1 -1
  65. data/lib/spec/mocks/argument_matchers.rb +233 -0
  66. data/lib/spec/mocks/error_generator.rb +2 -6
  67. data/lib/spec/mocks/message_expectation.rb +3 -11
  68. data/lib/spec/mocks/mock.rb +1 -1
  69. data/lib/spec/mocks/proxy.rb +5 -1
  70. data/lib/spec/runner/configuration.rb +3 -3
  71. data/lib/spec/runner/drb_command_line.rb +2 -1
  72. data/lib/spec/runner/example_group_runner.rb +2 -1
  73. data/lib/spec/runner/formatter/base_text_formatter.rb +28 -17
  74. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
  75. data/lib/spec/runner/formatter/html_formatter.rb +2 -3
  76. data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
  77. data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
  78. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
  79. data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
  80. data/lib/spec/runner/option_parser.rb +16 -19
  81. data/lib/spec/runner/options.rb +28 -26
  82. data/lib/spec/runner/reporter.rb +8 -9
  83. data/lib/spec/runner.rb +6 -28
  84. data/lib/spec/test/unit.rb +10 -0
  85. data/lib/spec/version.rb +2 -2
  86. data/{features/support → resources}/helpers/cmdline.rb +2 -2
  87. data/resources/rake/verify_rcov.rake +1 -1
  88. data/resources/spec/example_group_with_should_methods.rb +1 -1
  89. data/resources/spec/simple_spec.rb +1 -1
  90. data/resources/test/spec_and_test_together.rb +2 -3
  91. data/resources/test/spec_including_test_but_not_unit.rb +1 -1
  92. data/resources/test/test_case_with_should_methods.rb +2 -3
  93. data/rspec.gemspec +5 -5
  94. data/spec/spec/dsl/main_spec.rb +3 -3
  95. data/spec/spec/example/example_group_class_definition_spec.rb +11 -14
  96. data/spec/spec/example/example_group_factory_spec.rb +31 -44
  97. data/spec/spec/example/example_group_methods_spec.rb +86 -52
  98. data/spec/spec/example/example_group_spec.rb +16 -75
  99. data/spec/spec/example/example_matcher_spec.rb +10 -10
  100. data/spec/spec/example/example_methods_spec.rb +101 -241
  101. data/spec/spec/example/nested_example_group_spec.rb +2 -2
  102. data/spec/spec/example/pending_module_spec.rb +1 -1
  103. data/spec/spec/example/shared_example_group_spec.rb +2 -2
  104. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
  105. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
  106. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
  107. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
  108. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
  109. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
  110. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
  111. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
  112. data/spec/spec/matchers/change_spec.rb +8 -0
  113. data/spec/spec/matchers/exist_spec.rb +8 -4
  114. data/spec/spec/matchers/handler_spec.rb +8 -1
  115. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  116. data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
  117. data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
  118. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  119. data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
  120. data/spec/spec/runner/configuration_spec.rb +12 -12
  121. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +72 -1
  122. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
  123. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
  124. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
  125. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
  126. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
  127. data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
  128. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
  129. data/spec/spec/runner/formatter/profile_formatter_spec.rb +1 -1
  130. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +8 -6
  131. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  132. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
  133. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
  134. data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +10 -8
  135. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  136. data/spec/spec/runner/option_parser_spec.rb +15 -13
  137. data/spec/spec/runner/options_spec.rb +34 -0
  138. data/spec/spec/runner/reporter_spec.rb +65 -61
  139. data/spec/spec/runner/spec_drb.opts +1 -0
  140. data/spec/spec/runner_spec.rb +7 -5
  141. data/spec/spec_helper.rb +23 -0
  142. metadata +25 -76
  143. data/examples/passing/legacy_spec.rb +0 -11
  144. data/features/support/helpers/story_helper.rb +0 -13
  145. data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
  146. data/resources/spec/spec_with_flexmock.rb +0 -19
  147. data/spec/spec/spec_spec.rb +0 -21
@@ -6,7 +6,7 @@ module Spec
6
6
  describe "#get" do
7
7
  attr_reader :example_group
8
8
  before(:each) do
9
- @example_group_class = Class.new(ExampleGroup)
9
+ @example_group_class = Class.new(ExampleGroupDouble)
10
10
  ExampleGroupFactory.register(:registered_type, @example_group_class)
11
11
  end
12
12
 
@@ -15,32 +15,28 @@ module Spec
15
15
  end
16
16
 
17
17
  it "should return the default ExampleGroup type for nil" do
18
- ExampleGroupFactory.get(nil).should == ExampleGroup
18
+ ExampleGroupFactory[nil].should == ExampleGroup
19
19
  end
20
20
 
21
21
  it "should return the default ExampleGroup for an unregistered non-nil value" do
22
- ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
22
+ ExampleGroupFactory[:does_not_exist].should == ExampleGroup
23
23
  end
24
24
 
25
25
  it "should return custom type if registered" do
26
- ExampleGroupFactory.get(:registered_type).should == @example_group_class
27
- end
28
-
29
- it "should return the actual type when that is what is submitted" do
30
- ExampleGroupFactory.get(@example_group_class).should == @example_group_class
26
+ ExampleGroupFactory[:registered_type].should == @example_group_class
31
27
  end
32
28
 
33
29
  it "should get the custom type after setting the default" do
34
- @alternate_example_group_class = Class.new(ExampleGroup)
30
+ @alternate_example_group_class = Class.new(ExampleGroupDouble)
35
31
  ExampleGroupFactory.default(@alternate_example_group_class)
36
- ExampleGroupFactory.get(:registered_type).should == @example_group_class
32
+ ExampleGroupFactory[:registered_type].should == @example_group_class
37
33
  end
38
34
  end
39
35
 
40
36
  describe "#create_example_group" do
41
37
  attr_reader :parent_example_group
42
38
  before do
43
- @parent_example_group = Class.new(ExampleGroup) do
39
+ @parent_example_group = Class.new(ExampleGroupDouble) do
44
40
  def initialize(*args, &block)
45
41
  ;
46
42
  end
@@ -62,7 +58,7 @@ module Spec
62
58
  Spec::Example::ExampleGroupFactory.create_example_group do; end
63
59
  }.should raise_error(ArgumentError)
64
60
  end
65
-
61
+
66
62
  it "should raise when no block is given" do
67
63
  lambda { Spec::Example::ExampleGroupFactory.create_example_group "foo" }.should raise_error(ArgumentError)
68
64
  end
@@ -112,7 +108,26 @@ module Spec
112
108
  ) {}
113
109
  custom_example_group.superclass.should == parent_example_group
114
110
  end
115
-
111
+
112
+ it "should create a type indicated by spec_path for a path-like key" do
113
+ Spec::Example::ExampleGroupFactory.register('path/to/custom/', parent_example_group)
114
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
115
+ "example_group", :spec_path => "./spec/path/to/custom/some_spec.rb"
116
+ ) {}
117
+ custom_example_group.superclass.should == parent_example_group
118
+ end
119
+
120
+ it "should use the longest key that matches when creating a type indicated by spec_path" do
121
+ longer = Class.new parent_example_group
122
+ Spec::Example::ExampleGroupFactory.register(:longer, longer)
123
+ long = Class.new parent_example_group
124
+ Spec::Example::ExampleGroupFactory.register(:long, long)
125
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
126
+ "example_group", :spec_path => "./spec/longer/some_spec.rb"
127
+ ) {}
128
+ custom_example_group.superclass.should == longer
129
+ end
130
+
116
131
  it "sets the spec_path from the caller" do
117
132
  options = {}
118
133
  shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group("foo", options) {}
@@ -152,19 +167,19 @@ module Spec
152
167
  end
153
168
  Spec::Runner.options.example_groups.should_not include(example_group)
154
169
  end
155
-
170
+
156
171
  after(:each) do
157
172
  Spec::Example::ExampleGroupFactory.reset
158
173
  end
159
174
  end
160
-
175
+
161
176
  describe "#create_shared_example_group" do
162
177
  it "registers a new shared example group" do
163
178
  shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("something shared") {}
164
179
  shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
165
180
  SharedExampleGroup.should include(shared_example_group)
166
181
  end
167
-
182
+
168
183
  it "sets the spec_path from the caller" do
169
184
  options = {}
170
185
  shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("foo", options) {}
@@ -172,34 +187,6 @@ module Spec
172
187
  end
173
188
  end
174
189
 
175
- describe "#registered_or_ancestor_of_registered?" do
176
- before(:each) do
177
- @unregistered_parent = Class.new(ExampleGroup)
178
- @registered_child = Class.new(@unregistered_parent)
179
- @unregistered_grandchild = Class.new(@registered_child)
180
- Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
181
- end
182
-
183
- it "should return true for empty list" do
184
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([]).should be_true
185
- end
186
-
187
- it "should return true for a registered example group class" do
188
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@registered_child]).should be_true
189
- end
190
-
191
- it "should return true for an ancestor of a registered example_group_classes" do
192
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_parent]).should be_true
193
- end
194
-
195
- it "should return false for a subclass of a registered example_group_class" do
196
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_grandchild]).should be_false
197
- end
198
-
199
- after(:each) do
200
- Spec::Example::ExampleGroupFactory.reset
201
- end
202
- end
203
190
  end
204
191
  end
205
192
  end
@@ -12,21 +12,21 @@ module Spec
12
12
  options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
13
13
  @reporter = FakeReporter.new(@options)
14
14
  options.reporter = reporter
15
- @example_group = Class.new(ExampleGroup) do
15
+ @example_group = Class.new(ExampleGroupDouble) do
16
16
  describe("ExampleGroup")
17
17
  it "does nothing"
18
18
  end
19
19
  end
20
20
 
21
21
  after(:each) do
22
- ExampleGroup.reset
22
+ ExampleGroupDouble.reset
23
23
  end
24
24
 
25
25
  ["describe","context"].each do |method|
26
26
  describe "##{method}" do
27
27
  describe "when creating an ExampleGroup" do
28
28
  before(:each) do
29
- @parent_example_group = Class.new(ExampleGroup) do
29
+ @parent_example_group = Class.new(ExampleGroupDouble) do
30
30
  example "first example" do; end
31
31
  end
32
32
  @child_example_group = @parent_example_group.__send__ method, "Child" do
@@ -66,17 +66,36 @@ module Spec
66
66
  end
67
67
  end
68
68
 
69
- [:specify, :it].each do |method|
69
+ [:example, :specify, :it].each do |method|
70
70
  describe "##{method.to_s}" do
71
- it "should should create an example" do
71
+ it "should add an example" do
72
72
  lambda {
73
73
  @example_group.__send__(method, "")
74
74
  }.should change { @example_group.examples.length }.by(1)
75
75
  end
76
+
77
+ describe "creates an ExampleDescription" do
78
+ before(:all) do
79
+ @example_group = Class.new(ExampleGroupDouble).describe("bar")
80
+ @example_description = @example_group.__send__(method, "foo", {:this => :that}, "the backtrace") {}
81
+ end
82
+
83
+ specify "with a description" do
84
+ @example_description.description.should == "foo"
85
+ end
86
+
87
+ specify "with options" do
88
+ @example_description.options.should == {:this => :that}
89
+ end
90
+
91
+ specify "with a backtrace" do
92
+ @example_description.backtrace.should == "the backtrace"
93
+ end
94
+ end
76
95
  end
77
96
  end
78
97
 
79
- [:xit, :xspecify].each do |method|
98
+ [:xexample, :xit, :xspecify].each do |method|
80
99
  describe "##{method.to_s}" do
81
100
  before(:each) do
82
101
  Kernel.stub!(:warn)
@@ -95,10 +114,9 @@ module Spec
95
114
  end
96
115
  end
97
116
 
98
-
99
117
  describe "#examples" do
100
118
  it "should have Examples" do
101
- example_group = Class.new(ExampleGroup) do
119
+ example_group = Class.new(ExampleGroupDouble) do
102
120
  it "should exist" do; end
103
121
  end
104
122
  example_group.examples.length.should == 1
@@ -106,7 +124,7 @@ module Spec
106
124
  end
107
125
 
108
126
  it "should not include methods that begin with test (only when TU interop is loaded)" do
109
- example_group = Class.new(ExampleGroup) do
127
+ example_group = Class.new(ExampleGroupDouble) do
110
128
  def test_any_args(*args)
111
129
  true.should be_true
112
130
  end
@@ -123,12 +141,13 @@ module Spec
123
141
  # forces the run
124
142
  end
125
143
  end
144
+
126
145
  example_group.examples.length.should == 1
127
146
  example_group.run(options).should be_true
128
147
  end
129
148
 
130
149
  it "should include methods that begin with should and has an arity of 0 in suite" do
131
- example_group = Class.new(ExampleGroup) do
150
+ example_group = Class.new(ExampleGroupDouble) do
132
151
  def shouldCamelCase
133
152
  true.should be_true
134
153
  end
@@ -149,7 +168,7 @@ module Spec
149
168
  end
150
169
  end
151
170
  example_group.should have(4).examples
152
- descriptions = example_group.examples.collect {|example| example.description.to_s}
171
+ descriptions = example_group.examples.collect {|e| e.description}
153
172
  descriptions.should include(
154
173
  "shouldCamelCase",
155
174
  "should_any_args",
@@ -162,7 +181,7 @@ module Spec
162
181
  end
163
182
 
164
183
  it "should not include methods that begin with test_ and has an arity > 0 in suite" do
165
- example_group = Class.new(ExampleGroup) do
184
+ example_group = Class.new(ExampleGroupDouble) do
166
185
  def test_invalid(foo)
167
186
  1.should == 1
168
187
  end
@@ -174,7 +193,7 @@ module Spec
174
193
  end
175
194
 
176
195
  it "should not include methods that begin with should_ and has an arity > 0 in suite" do
177
- example_group = Class.new(ExampleGroup) do
196
+ example_group = Class.new(ExampleGroupDouble) do
178
197
  def should_invalid(foo)
179
198
  1.should == 2
180
199
  end
@@ -193,7 +212,7 @@ module Spec
193
212
  end
194
213
 
195
214
  it "should run should_methods" do
196
- example_group = Class.new(ExampleGroup) do
215
+ example_group = Class.new(ExampleGroupDouble) do
197
216
  def should_valid
198
217
  1.should == 2
199
218
  end
@@ -322,8 +341,8 @@ module Spec
322
341
  example_group.spec_path.should == File.expand_path("blah")
323
342
  end
324
343
 
325
- it ".description_options should return all the options passed in" do
326
- example_group.description_options.should == {:a => "b", :spec_path => "blah"}
344
+ it ".options should return all the options passed in" do
345
+ example_group.options.should == {:a => "b", :spec_path => "blah"}
327
346
  end
328
347
 
329
348
  end
@@ -334,14 +353,14 @@ module Spec
334
353
  example_group.description.should eql(example_group.description)
335
354
  end
336
355
 
337
- it "should not add a space when description_text begins with #" do
356
+ it "should not add a space when description begins with #" do
338
357
  child_example_group = Class.new(example_group) do
339
358
  describe("#foobar", "Does something")
340
359
  end
341
360
  child_example_group.description.should == "ExampleGroup#foobar Does something"
342
361
  end
343
362
 
344
- it "should not add a space when description_text begins with ." do
363
+ it "should not add a space when description begins with ." do
345
364
  child_example_group = Class.new(example_group) do
346
365
  describe(".foobar", "Does something")
347
366
  end
@@ -357,6 +376,11 @@ module Spec
357
376
  example_group.set_description("")
358
377
  example_group.description.should =~ /Class:/
359
378
  end
379
+
380
+ it "is cached" do
381
+ example_group.set_description("describe me")
382
+ example_group.description.should be(example_group.description)
383
+ end
360
384
  end
361
385
 
362
386
  describe "#description_parts" do
@@ -365,7 +389,7 @@ module Spec
365
389
  end
366
390
 
367
391
  it "should return an Array of the description args from each class in the hierarchy" do
368
- parent_example_group = Class.new(ExampleGroup) do
392
+ parent_example_group = Class.new(ExampleGroupDouble) do
369
393
  describe("Parent")
370
394
  end
371
395
 
@@ -385,6 +409,10 @@ module Spec
385
409
  Spec::Example::ExampleGroup
386
410
  ]
387
411
  end
412
+
413
+ it "caches the description parts" do
414
+ example_group.description_parts.should equal(example_group.description_parts)
415
+ end
388
416
  end
389
417
 
390
418
  describe "#described_type" do
@@ -396,7 +424,7 @@ module Spec
396
424
  end
397
425
 
398
426
  it "should return #described_type of superclass when no passed in type" do
399
- parent_example_group = Class.new(ExampleGroup) do
427
+ parent_example_group = Class.new(ExampleGroupDouble) do
400
428
  describe Object, "#foobar"
401
429
  end
402
430
  child_example_group = Class.new(parent_example_group) do
@@ -404,25 +432,15 @@ module Spec
404
432
  end
405
433
  child_example_group.described_type.should == Object
406
434
  end
407
- end
408
-
409
- describe "#remove_after" do
410
- it "should unregister a given after(:each) block" do
411
- after_all_ran = false
412
- proc = Proc.new { after_all_ran = true }
413
-
414
- example_group = Class.new(ExampleGroup) do
415
- specify("example") {}
416
- after(:each, &proc)
435
+
436
+ it "is cached per example group" do
437
+ klass = Class.new
438
+ group = Class.new(ExampleGroupDouble) do
439
+ describe(klass)
417
440
  end
418
-
419
- example_group.run(options)
420
- after_all_ran.should be_true
421
-
422
- after_all_ran = false
423
- example_group.remove_after(:each, &proc)
424
- example_group.run(options)
425
- after_all_ran.should be_false
441
+ group.should_receive(:description_parts).once.and_return([klass])
442
+ group.described_type
443
+ group.described_type
426
444
  end
427
445
  end
428
446
 
@@ -463,7 +481,7 @@ module Spec
463
481
 
464
482
  describe "#class_eval" do
465
483
  it "should allow constants to be defined" do
466
- example_group = Class.new(ExampleGroup) do
484
+ example_group = Class.new(ExampleGroupDouble) do
467
485
  FOO = 1
468
486
  it "should reference FOO" do
469
487
  FOO.should == 1
@@ -485,7 +503,7 @@ module Spec
485
503
  end
486
504
  end
487
505
 
488
- describe '#unregister' do
506
+ describe '#remove_example_group' do
489
507
  before(:each) do
490
508
  Spec::Runner.options.add_example_group example_group
491
509
  end
@@ -498,7 +516,7 @@ module Spec
498
516
  describe "#run" do
499
517
  describe "given an example group with at least one example" do
500
518
  it "should call add_example_group" do
501
- example_group = Class.new(ExampleGroup) do
519
+ example_group = Class.new(ExampleGroupDouble) do
502
520
  example("anything") {}
503
521
  end
504
522
  reporter.should_receive(:add_example_group)
@@ -508,7 +526,7 @@ module Spec
508
526
 
509
527
  describe "given an example group with no examples" do
510
528
  it "should NOT call add_example_group" do
511
- example_group = Class.new(ExampleGroup) do end
529
+ example_group = Class.new(ExampleGroupDouble) do end
512
530
  reporter.should_not_receive(:add_example_group)
513
531
  example_group.run(options)
514
532
  end
@@ -517,7 +535,7 @@ module Spec
517
535
 
518
536
  describe "#matcher_class=" do
519
537
  it "should call new and matches? on the class used for matching examples" do
520
- example_group = Class.new(ExampleGroup) do
538
+ example_group = Class.new(ExampleGroupDouble) do
521
539
  it "should do something" do end
522
540
  def self.specified_examples
523
541
  ["something"]
@@ -552,7 +570,7 @@ module Spec
552
570
 
553
571
  describe "#backtrace" do
554
572
  it "returns the backtrace from where the example group was defined" do
555
- example_group = Class.new(ExampleGroup).describe("foo") do
573
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
556
574
  example "bar" do; end
557
575
  end
558
576
  example_group.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
@@ -564,13 +582,13 @@ module Spec
564
582
  Kernel.stub!(:warn)
565
583
  end
566
584
  it "sends a deprecation warning" do
567
- example_group = Class.new(ExampleGroup) {}
585
+ example_group = Class.new(ExampleGroupDouble) {}
568
586
  Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
569
587
  example_group.example_group_backtrace
570
588
  end
571
589
 
572
590
  it "returns the backtrace from where the example group was defined" do
573
- example_group = Class.new(ExampleGroup).describe("foo") do
591
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
574
592
  example "bar" do; end
575
593
  end
576
594
  example_group.example_group_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
@@ -579,21 +597,21 @@ module Spec
579
597
 
580
598
  describe "#before" do
581
599
  it "stores before(:each) blocks" do
582
- example_group = Class.new(ExampleGroup) {}
600
+ example_group = Class.new(ExampleGroupDouble) {}
583
601
  block = lambda {}
584
602
  example_group.before(:each, &block)
585
603
  example_group.before_each_parts.should include(block)
586
604
  end
587
605
 
588
606
  it "stores before(:all) blocks" do
589
- example_group = Class.new(ExampleGroup) {}
607
+ example_group = Class.new(ExampleGroupDouble) {}
590
608
  block = lambda {}
591
609
  example_group.before(:all, &block)
592
610
  example_group.before_all_parts.should include(block)
593
611
  end
594
612
 
595
613
  it "stores before(:suite) blocks" do
596
- example_group = Class.new(ExampleGroup) {}
614
+ example_group = Class.new(ExampleGroupDouble) {}
597
615
  parts = []
598
616
  ExampleGroupMethods.stub!(:before_suite_parts).and_return(parts)
599
617
  block = lambda {}
@@ -605,21 +623,21 @@ module Spec
605
623
 
606
624
  describe "#after" do
607
625
  it "stores after(:each) blocks" do
608
- example_group = Class.new(ExampleGroup) {}
626
+ example_group = Class.new(ExampleGroupDouble) {}
609
627
  block = lambda {}
610
628
  example_group.after(:each, &block)
611
629
  example_group.after_each_parts.should include(block)
612
630
  end
613
631
 
614
632
  it "stores after(:all) blocks" do
615
- example_group = Class.new(ExampleGroup) {}
633
+ example_group = Class.new(ExampleGroupDouble) {}
616
634
  block = lambda {}
617
635
  example_group.after(:all, &block)
618
636
  example_group.after_all_parts.should include(block)
619
637
  end
620
638
 
621
639
  it "stores after(:suite) blocks" do
622
- example_group = Class.new(ExampleGroup) {}
640
+ example_group = Class.new(ExampleGroupDouble) {}
623
641
  parts = []
624
642
  ExampleGroupMethods.stub!(:after_suite_parts).and_return(parts)
625
643
  block = lambda {}
@@ -628,6 +646,22 @@ module Spec
628
646
  end
629
647
  end
630
648
 
649
+ describe "#run_before_all" do
650
+ it "does not create an instance if before_all_parts are empty" do
651
+ example_group = Class.new(ExampleGroupDouble) { example("one example") {} }
652
+ example_group.should_not_receive(:new)
653
+ example_group.__send__ :run_before_all, nil
654
+ end
655
+ end
656
+
657
+ describe "#run_after_all" do
658
+ it "does not create an instance if after_all_parts are empty" do
659
+ example_group = Class.new(ExampleGroupDouble) { example("one example") {} }
660
+ example_group.should_not_receive(:new)
661
+ example_group.__send__ :run_after_all, true, {}, nil
662
+ end
663
+ end
664
+
631
665
  end
632
666
  end
633
667
  end