rspec 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +30 -3
  2. data/License.txt +22 -0
  3. data/Manifest.txt +3 -3
  4. data/README.txt +1 -25
  5. data/Rakefile +4 -2
  6. data/TODO.txt +5 -4
  7. data/bin/autospec +1 -1
  8. data/examples/pure/shared_example_group_example.rb +2 -2
  9. data/lib/autotest/rspec.rb +1 -1
  10. data/lib/spec.rb +5 -1
  11. data/lib/spec/example.rb +1 -1
  12. data/lib/spec/example/before_and_after_hooks.rb +93 -0
  13. data/lib/spec/example/configuration.rb +10 -1
  14. data/lib/spec/example/example_group.rb +2 -1
  15. data/lib/spec/example/example_group_factory.rb +18 -1
  16. data/lib/spec/example/example_group_methods.rb +45 -123
  17. data/lib/spec/example/example_methods.rb +9 -6
  18. data/lib/spec/example/shared_example_group.rb +6 -12
  19. data/lib/spec/extensions/main.rb +1 -1
  20. data/lib/spec/interop/test/unit/testcase.rb +1 -1
  21. data/lib/spec/mocks/error_generator.rb +1 -1
  22. data/lib/spec/mocks/message_expectation.rb +19 -4
  23. data/lib/spec/mocks/methods.rb +2 -2
  24. data/lib/spec/mocks/proxy.rb +4 -5
  25. data/lib/spec/runner.rb +3 -4
  26. data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
  27. data/lib/spec/runner/option_parser.rb +23 -22
  28. data/lib/spec/version.rb +1 -1
  29. data/rspec.gemspec +19 -8
  30. data/spec/autotest/rspec_spec.rb +5 -1
  31. data/spec/spec/example/configuration_spec.rb +229 -215
  32. data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
  33. data/spec/spec/example/example_group_factory_spec.rb +48 -27
  34. data/spec/spec/example/example_group_methods_spec.rb +436 -426
  35. data/spec/spec/example/example_group_spec.rb +459 -500
  36. data/spec/spec/example/example_methods_spec.rb +92 -86
  37. data/spec/spec/example/shared_example_group_spec.rb +219 -203
  38. data/spec/spec/extensions/main_spec.rb +23 -23
  39. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
  40. data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
  41. data/spec/spec/mocks/mock_spec.rb +12 -2
  42. data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
  43. data/spec/spec/mocks/partial_mock_spec.rb +10 -5
  44. data/spec/spec/package/bin_spec_spec.rb +8 -0
  45. data/spec/spec/runner/command_line_spec.rb +101 -100
  46. data/spec/spec/runner/drb_command_line_spec.rb +0 -2
  47. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
  48. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
  49. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
  51. data/spec/spec/runner/option_parser_spec.rb +18 -6
  52. data/spec/spec_helper.rb +26 -5
  53. data/stories/mock_framework_integration/use_flexmock.story +1 -1
  54. metadata +38 -7
  55. data/lib/spec/example/module_inclusion_warnings.rb +0 -38
  56. data/spec/spec/example/example_group/described_module_spec.rb +0 -20
  57. data/spec/spec/example/example_group/warning_messages_spec.rb +0 -76
@@ -65,585 +65,586 @@ module Spec
65
65
  end
66
66
 
67
67
  describe ExampleGroup, "#run" do
68
- include SandboxedOptions
69
- attr_reader :example_group, :formatter, :reporter
70
- before :each do
71
- method_with_three_args = lambda { |arg1, arg2, arg3| }
72
- @formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
73
- options.formatters << formatter
74
- options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
75
- @reporter = FakeReporter.new(options)
76
- options.reporter = reporter
77
- @example_group = Class.new(ExampleGroup) do
78
- describe("example")
79
- it "does nothing" do
80
- end
81
- end
82
- class << example_group
83
- public :include
84
- end
85
- end
86
-
87
- after :each do
88
- ExampleGroup.reset
89
- end
90
-
91
- it "should not run when there are no examples" do
92
- example_group = Class.new(ExampleGroup) do
93
- describe("Foobar")
94
- end
95
- example_group.examples.should be_empty
96
-
97
- reporter = mock("Reporter")
98
- reporter.should_not_receive(:add_example_group)
99
- example_group.run
100
- end
101
-
102
- describe "when before_each fails" do
103
- before(:each) do
104
- $example_ran = $after_each_ran = false
105
- @example_group = describe("Foobar") do
106
- before(:each) {raise}
107
- it "should not be run" do
108
- $example_ran = true
109
- end
110
- after(:each) do
111
- $after_each_ran = true
68
+ with_sandboxed_options do
69
+ attr_reader :example_group, :formatter, :reporter
70
+ before :each do
71
+ method_with_three_args = lambda { |arg1, arg2, arg3| }
72
+ @formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
73
+ options.formatters << formatter
74
+ options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
75
+ @reporter = FakeReporter.new(options)
76
+ options.reporter = reporter
77
+ @example_group = Class.new(ExampleGroup) do
78
+ describe("example")
79
+ it "does nothing" do
112
80
  end
113
81
  end
114
- end
115
-
116
- it "should not run example block" do
117
- example_group.run
118
- $example_ran.should be_false
119
- end
120
-
121
- it "should run after_each" do
122
- example_group.run
123
- $after_each_ran.should be_true
124
- end
125
-
126
- it "should report failure location when in before_each" do
127
- reporter.should_receive(:example_finished) do |example_group, error|
128
- error.message.should eql("in before_each")
82
+ class << example_group
83
+ public :include
129
84
  end
130
- example_group.run
131
85
  end
132
- end
133
86
 
134
- describe ExampleGroup, "#run on dry run" do
135
- before do
136
- @options.dry_run = true
87
+ after :each do
88
+ ExampleGroup.reset
137
89
  end
138
90
 
139
- it "should not run before(:all) or after(:all)" do
140
- before_all_ran = false
141
- after_all_ran = false
142
- ExampleGroup.before(:all) { before_all_ran = true }
143
- ExampleGroup.after(:all) { after_all_ran = true }
144
- example_group.it("should") {}
145
- example_group.run
146
- before_all_ran.should be_false
147
- after_all_ran.should be_false
148
- end
91
+ it "should not run when there are no examples" do
92
+ example_group = Class.new(ExampleGroup) do
93
+ describe("Foobar")
94
+ end
95
+ example_group.examples.should be_empty
149
96
 
150
- it "should not run example" do
151
- example_ran = false
152
- example_group.it("should") {example_ran = true}
97
+ reporter = mock("Reporter")
98
+ reporter.should_not_receive(:add_example_group)
153
99
  example_group.run
154
- example_ran.should be_false
155
100
  end
156
- end
157
-
158
- describe ExampleGroup, "#run with specified examples" do
159
- attr_reader :examples_that_were_run
160
- before do
161
- @examples_that_were_run = []
162
- end
163
-
164
- describe "when specified_examples matches entire ExampleGroup" do
165
- before do
166
- examples_that_were_run = @examples_that_were_run
167
- @example_group = Class.new(ExampleGroup) do
168
- describe("the ExampleGroup")
169
- it("should be run") do
170
- examples_that_were_run << 'should be run'
101
+
102
+ describe "when before_each fails" do
103
+ before(:each) do
104
+ $example_ran = $after_each_ran = false
105
+ @example_group = describe("Foobar") do
106
+ before(:each) {raise}
107
+ it "should not be run" do
108
+ $example_ran = true
171
109
  end
172
-
173
- it("should also be run") do
174
- examples_that_were_run << 'should also be run'
110
+ after(:each) do
111
+ $after_each_ran = true
175
112
  end
176
113
  end
177
- options.examples = ["the ExampleGroup"]
178
114
  end
179
115
 
180
- it "should not run the Examples in the ExampleGroup" do
116
+ it "should not run example block" do
181
117
  example_group.run
182
- examples_that_were_run.should == ['should be run', 'should also be run']
118
+ $example_ran.should be_false
183
119
  end
184
- end
185
-
186
- describe ExampleGroup, "#run when specified_examples matches only Example description" do
187
- before do
188
- examples_that_were_run = @examples_that_were_run
189
- @example_group = Class.new(ExampleGroup) do
190
- describe("example")
191
- it("should be run") do
192
- examples_that_were_run << 'should be run'
193
- end
194
- end
195
- options.examples = ["should be run"]
196
- end
197
-
198
- it "should not run the example" do
120
+
121
+ it "should run after_each" do
199
122
  example_group.run
200
- examples_that_were_run.should == ['should be run']
123
+ $after_each_ran.should be_true
201
124
  end
202
- end
203
125
 
204
- describe ExampleGroup, "#run when specified_examples does not match an Example description" do
205
- before do
206
- examples_that_were_run = @examples_that_were_run
207
- @example_group = Class.new(ExampleGroup) do
208
- describe("example")
209
- it("should be something else") do
210
- examples_that_were_run << 'should be something else'
211
- end
126
+ it "should report failure location when in before_each" do
127
+ reporter.should_receive(:example_finished) do |example_group, error|
128
+ error.message.should eql("in before_each")
212
129
  end
213
- options.examples = ["does not match anything"]
214
- end
215
-
216
- it "should not run the example" do
217
130
  example_group.run
218
- examples_that_were_run.should == []
219
131
  end
220
132
  end
221
133
 
222
- describe ExampleGroup, "#run when specified_examples matches an Example description" do
134
+ describe ExampleGroup, "#run on dry run" do
223
135
  before do
224
- examples_that_were_run = @examples_that_were_run
225
- @example_group = Class.new(ExampleGroup) do
226
- describe("example")
227
- it("should be run") do
228
- examples_that_were_run << 'should be run'
229
- end
230
- it("should not be run") do
231
- examples_that_were_run << 'should not be run'
232
- end
233
- end
234
- options.examples = ["should be run"]
136
+ @options.dry_run = true
235
137
  end
236
138
 
237
- it "should run only the example, when there is only one" do
139
+ it "should not run before(:all) or after(:all)" do
140
+ before_all_ran = false
141
+ after_all_ran = false
142
+ ExampleGroup.before(:all) { before_all_ran = true }
143
+ ExampleGroup.after(:all) { after_all_ran = true }
144
+ example_group.it("should") {}
238
145
  example_group.run
239
- examples_that_were_run.should == ["should be run"]
146
+ before_all_ran.should be_false
147
+ after_all_ran.should be_false
240
148
  end
241
149
 
242
- it "should run only the one example" do
150
+ it "should not run example" do
151
+ example_ran = false
152
+ example_group.it("should") {example_ran = true}
243
153
  example_group.run
244
- examples_that_were_run.should == ["should be run"] end
154
+ example_ran.should be_false
155
+ end
245
156
  end
246
- end
247
157
 
248
- describe ExampleGroup, "#run with success" do
249
- before do
250
- @special_example_group = Class.new(ExampleGroup)
251
- ExampleGroupFactory.register(:special, @special_example_group)
252
- @not_special_example_group = Class.new(ExampleGroup)
253
- ExampleGroupFactory.register(:not_special, @not_special_example_group)
254
- end
158
+ describe ExampleGroup, "#run with specified examples" do
159
+ attr_reader :examples_that_were_run
160
+ before do
161
+ @examples_that_were_run = []
162
+ end
255
163
 
256
- after do
257
- ExampleGroupFactory.reset
258
- end
164
+ describe "when specified_examples matches entire ExampleGroup" do
165
+ before do
166
+ examples_that_were_run = @examples_that_were_run
167
+ @example_group = Class.new(ExampleGroup) do
168
+ describe("the ExampleGroup")
169
+ it("should be run") do
170
+ examples_that_were_run << 'should be run'
171
+ end
259
172
 
260
- it "should send reporter add_example_group" do
261
- example_group.run
262
- reporter.example_groups.should == [example_group]
263
- end
173
+ it("should also be run") do
174
+ examples_that_were_run << 'should also be run'
175
+ end
176
+ end
177
+ options.examples = ["the ExampleGroup"]
178
+ end
264
179
 
265
- it "should run example on run" do
266
- example_ran = false
267
- example_group.it("should") {example_ran = true}
268
- example_group.run
269
- example_ran.should be_true
270
- end
180
+ it "should not run the Examples in the ExampleGroup" do
181
+ example_group.run
182
+ examples_that_were_run.should == ['should be run', 'should also be run']
183
+ end
184
+ end
271
185
 
272
- it "should run before(:all) block only once" do
273
- before_all_run_count_run_count = 0
274
- example_group.before(:all) {before_all_run_count_run_count += 1}
275
- example_group.it("test") {true}
276
- example_group.it("test2") {true}
277
- example_group.run
278
- before_all_run_count_run_count.should == 1
279
- end
186
+ describe ExampleGroup, "#run when specified_examples matches only Example description" do
187
+ before do
188
+ examples_that_were_run = @examples_that_were_run
189
+ @example_group = Class.new(ExampleGroup) do
190
+ describe("example")
191
+ it("should be run") do
192
+ examples_that_were_run << 'should be run'
193
+ end
194
+ end
195
+ options.examples = ["should be run"]
196
+ end
280
197
 
281
- it "should run after(:all) block only once" do
282
- after_all_run_count = 0
283
- example_group.after(:all) {after_all_run_count += 1}
284
- example_group.it("test") {true}
285
- example_group.it("test2") {true}
286
- example_group.run
287
- after_all_run_count.should == 1
288
- @reporter.rspec_verify
289
- end
198
+ it "should not run the example" do
199
+ example_group.run
200
+ examples_that_were_run.should == ['should be run']
201
+ end
202
+ end
290
203
 
291
- it "after(:all) should have access to all instance variables defined in before(:all)" do
292
- context_instance_value_in = "Hello there"
293
- context_instance_value_out = ""
294
- example_group.before(:all) { @instance_var = context_instance_value_in }
295
- example_group.after(:all) { context_instance_value_out = @instance_var }
296
- example_group.it("test") {true}
297
- example_group.run
298
- context_instance_value_in.should == context_instance_value_out
299
- end
204
+ describe ExampleGroup, "#run when specified_examples does not match an Example description" do
205
+ before do
206
+ examples_that_were_run = @examples_that_were_run
207
+ @example_group = Class.new(ExampleGroup) do
208
+ describe("example")
209
+ it("should be something else") do
210
+ examples_that_were_run << 'should be something else'
211
+ end
212
+ end
213
+ options.examples = ["does not match anything"]
214
+ end
300
215
 
301
- it "should copy instance variables from before(:all)'s execution context into spec's execution context" do
302
- context_instance_value_in = "Hello there"
303
- context_instance_value_out = ""
304
- example_group.before(:all) { @instance_var = context_instance_value_in }
305
- example_group.it("test") {context_instance_value_out = @instance_var}
306
- example_group.run
307
- context_instance_value_in.should == context_instance_value_out
308
- end
216
+ it "should not run the example" do
217
+ example_group.run
218
+ examples_that_were_run.should == []
219
+ end
220
+ end
309
221
 
310
- it "should not add global before callbacks for untargetted example_group" do
311
- fiddle = []
222
+ describe ExampleGroup, "#run when specified_examples matches an Example description" do
223
+ before do
224
+ examples_that_were_run = @examples_that_were_run
225
+ @example_group = Class.new(ExampleGroup) do
226
+ describe("example")
227
+ it("should be run") do
228
+ examples_that_were_run << 'should be run'
229
+ end
230
+ it("should not be run") do
231
+ examples_that_were_run << 'should not be run'
232
+ end
233
+ end
234
+ options.examples = ["should be run"]
235
+ end
312
236
 
313
- ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
314
- ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
315
- @special_example_group.before(:each) { fiddle << "Example.before(:each, :type => :special)" }
316
- @special_example_group.prepend_before(:each) { fiddle << "Example.prepend_before(:each, :type => :special)" }
317
- @special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
318
- @special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
237
+ it "should run only the example, when there is only one" do
238
+ example_group.run
239
+ examples_that_were_run.should == ["should be run"]
240
+ end
319
241
 
320
- example_group = Class.new(ExampleGroup) do
321
- describe("I'm not special", :type => :not_special)
322
- it "does nothing"
242
+ it "should run only the one example" do
243
+ example_group.run
244
+ examples_that_were_run.should == ["should be run"] end
323
245
  end
324
- example_group.run
325
- fiddle.should == [
326
- 'Example.prepend_before(:all)',
327
- 'Example.before(:all)',
328
- ]
329
246
  end
330
247
 
331
- it "should add global before callbacks for targetted example_groups" do
332
- fiddle = []
333
-
334
- ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
335
- ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
336
- @special_example_group.before(:each) { fiddle << "special.before(:each, :type => :special)" }
337
- @special_example_group.prepend_before(:each) { fiddle << "special.prepend_before(:each, :type => :special)" }
338
- @special_example_group.before(:all) { fiddle << "special.before(:all, :type => :special)" }
339
- @special_example_group.prepend_before(:all) { fiddle << "special.prepend_before(:all, :type => :special)" }
340
- @special_example_group.append_before(:each) { fiddle << "special.append_before(:each, :type => :special)" }
248
+ describe ExampleGroup, "#run with success" do
249
+ before do
250
+ @special_example_group = Class.new(ExampleGroup)
251
+ ExampleGroupFactory.register(:special, @special_example_group)
252
+ @not_special_example_group = Class.new(ExampleGroup)
253
+ ExampleGroupFactory.register(:not_special, @not_special_example_group)
254
+ end
341
255
 
342
- example_group = Class.new(@special_example_group).describe("I'm a special example_group") {}
343
- example_group.it("test") {true}
344
- example_group.run
345
- fiddle.should == [
346
- 'Example.prepend_before(:all)',
347
- 'Example.before(:all)',
348
- 'special.prepend_before(:all, :type => :special)',
349
- 'special.before(:all, :type => :special)',
350
- 'special.prepend_before(:each, :type => :special)',
351
- 'special.before(:each, :type => :special)',
352
- 'special.append_before(:each, :type => :special)',
353
- ]
354
- end
256
+ after do
257
+ ExampleGroupFactory.reset
258
+ end
355
259
 
356
- it "should order before callbacks from global to local" do
357
- fiddle = []
358
- ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
359
- ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
360
- example_group.prepend_before(:all) { fiddle << "prepend_before(:all)" }
361
- example_group.before(:all) { fiddle << "before(:all)" }
362
- example_group.prepend_before(:each) { fiddle << "prepend_before(:each)" }
363
- example_group.before(:each) { fiddle << "before(:each)" }
364
- example_group.run
365
- fiddle.should == [
366
- 'Example.prepend_before(:all)',
367
- 'Example.before(:all)',
368
- 'prepend_before(:all)',
369
- 'before(:all)',
370
- 'prepend_before(:each)',
371
- 'before(:each)'
372
- ]
373
- end
260
+ it "should send reporter add_example_group" do
261
+ example_group.run
262
+ reporter.example_groups.should == [example_group]
263
+ end
374
264
 
375
- it "should order after callbacks from local to global" do
376
- fiddle = []
377
- example_group.after(:each) { fiddle << "after(:each)" }
378
- example_group.append_after(:each) { fiddle << "append_after(:each)" }
379
- example_group.after(:all) { fiddle << "after(:all)" }
380
- example_group.append_after(:all) { fiddle << "append_after(:all)" }
381
- ExampleGroup.after(:all) { fiddle << "Example.after(:all)" }
382
- ExampleGroup.append_after(:all) { fiddle << "Example.append_after(:all)" }
383
- example_group.run
384
- fiddle.should == [
385
- 'after(:each)',
386
- 'append_after(:each)',
387
- 'after(:all)',
388
- 'append_after(:all)',
389
- 'Example.after(:all)',
390
- 'Example.append_after(:all)'
391
- ]
392
- end
265
+ it "should run example on run" do
266
+ example_ran = false
267
+ example_group.it("should") {example_ran = true}
268
+ example_group.run
269
+ example_ran.should be_true
270
+ end
393
271
 
394
- it "should have accessible instance methods from included module" do
395
- mod1_method_called = false
396
- mod1 = Module.new do
397
- define_method :mod1_method do
398
- mod1_method_called = true
399
- end
272
+ it "should run before(:all) block only once" do
273
+ before_all_run_count_run_count = 0
274
+ example_group.before(:all) {before_all_run_count_run_count += 1}
275
+ example_group.it("test") {true}
276
+ example_group.it("test2") {true}
277
+ example_group.run
278
+ before_all_run_count_run_count.should == 1
400
279
  end
401
280
 
402
- mod2_method_called = false
403
- mod2 = Module.new do
404
- define_method :mod2_method do
405
- mod2_method_called = true
406
- end
281
+ it "should run after(:all) block only once" do
282
+ after_all_run_count = 0
283
+ example_group.after(:all) {after_all_run_count += 1}
284
+ example_group.it("test") {true}
285
+ example_group.it("test2") {true}
286
+ example_group.run
287
+ after_all_run_count.should == 1
288
+ @reporter.rspec_verify
407
289
  end
408
290
 
409
- example_group.include mod1, mod2
291
+ it "after(:all) should have access to all instance variables defined in before(:all)" do
292
+ context_instance_value_in = "Hello there"
293
+ context_instance_value_out = ""
294
+ example_group.before(:all) { @instance_var = context_instance_value_in }
295
+ example_group.after(:all) { context_instance_value_out = @instance_var }
296
+ example_group.it("test") {true}
297
+ example_group.run
298
+ context_instance_value_in.should == context_instance_value_out
299
+ end
410
300
 
411
- example_group.it("test") do
412
- mod1_method
413
- mod2_method
301
+ it "should copy instance variables from before(:all)'s execution context into spec's execution context" do
302
+ context_instance_value_in = "Hello there"
303
+ context_instance_value_out = ""
304
+ example_group.before(:all) { @instance_var = context_instance_value_in }
305
+ example_group.it("test") {context_instance_value_out = @instance_var}
306
+ example_group.run
307
+ context_instance_value_in.should == context_instance_value_out
414
308
  end
415
- example_group.run
416
- mod1_method_called.should be_true
417
- mod2_method_called.should be_true
418
- end
419
309
 
420
- it "should include targetted modules included using configuration" do
421
- mod1 = Module.new
422
- mod2 = Module.new
423
- mod3 = Module.new
424
- Spec::Runner.configuration.include(mod1, mod2)
425
- Spec::Runner.configuration.include(mod3, :type => :not_special)
310
+ it "should not add global before callbacks for untargetted example_group" do
311
+ fiddle = []
312
+
313
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
314
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
315
+ @special_example_group.before(:each) { fiddle << "Example.before(:each, :type => :special)" }
316
+ @special_example_group.prepend_before(:each) { fiddle << "Example.prepend_before(:each, :type => :special)" }
317
+ @special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
318
+ @special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
426
319
 
427
- example_group = Class.new(@special_example_group).describe("I'm special", :type => :special) do
428
- it "does nothing"
320
+ example_group = Class.new(ExampleGroup) do
321
+ describe("I'm not special", :type => :not_special)
322
+ it "does nothing"
323
+ end
324
+ example_group.run
325
+ fiddle.should == [
326
+ 'Example.prepend_before(:all)',
327
+ 'Example.before(:all)',
328
+ ]
429
329
  end
430
- example_group.run
431
330
 
432
- example_group.included_modules.should include(mod1)
433
- example_group.included_modules.should include(mod2)
434
- example_group.included_modules.should_not include(mod3)
435
- end
331
+ it "should add global before callbacks for targetted example_groups" do
332
+ fiddle = []
436
333
 
437
- it "should include any predicate_matchers included using configuration" do
438
- $included_predicate_matcher_found = false
439
- Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
440
- example_group = Class.new(ExampleGroup) do
441
- describe('example')
442
- it "should respond to do_something" do
443
- $included_predicate_matcher_found = respond_to?(:do_something)
334
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
335
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
336
+ @special_example_group.before(:each) { fiddle << "special.before(:each, :type => :special)" }
337
+ @special_example_group.prepend_before(:each) { fiddle << "special.prepend_before(:each, :type => :special)" }
338
+ @special_example_group.before(:all) { fiddle << "special.before(:all, :type => :special)" }
339
+ @special_example_group.prepend_before(:all) { fiddle << "special.prepend_before(:all, :type => :special)" }
340
+ @special_example_group.append_before(:each) { fiddle << "special.append_before(:each, :type => :special)" }
341
+
342
+ example_group = Class.new(@special_example_group).describe("I'm a special example_group") {}
343
+ example_group.it("test") {true}
344
+ example_group.run
345
+ fiddle.should == [
346
+ 'Example.prepend_before(:all)',
347
+ 'Example.before(:all)',
348
+ 'special.prepend_before(:all, :type => :special)',
349
+ 'special.before(:all, :type => :special)',
350
+ 'special.prepend_before(:each, :type => :special)',
351
+ 'special.before(:each, :type => :special)',
352
+ 'special.append_before(:each, :type => :special)',
353
+ ]
354
+ end
355
+
356
+ it "should order before callbacks from global to local" do
357
+ fiddle = []
358
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
359
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
360
+ example_group.prepend_before(:all) { fiddle << "prepend_before(:all)" }
361
+ example_group.before(:all) { fiddle << "before(:all)" }
362
+ example_group.prepend_before(:each) { fiddle << "prepend_before(:each)" }
363
+ example_group.before(:each) { fiddle << "before(:each)" }
364
+ example_group.run
365
+ fiddle.should == [
366
+ 'Example.prepend_before(:all)',
367
+ 'Example.before(:all)',
368
+ 'prepend_before(:all)',
369
+ 'before(:all)',
370
+ 'prepend_before(:each)',
371
+ 'before(:each)'
372
+ ]
373
+ end
374
+
375
+ it "should order after callbacks from local to global" do
376
+ fiddle = []
377
+ example_group.after(:each) { fiddle << "after(:each)" }
378
+ example_group.append_after(:each) { fiddle << "append_after(:each)" }
379
+ example_group.after(:all) { fiddle << "after(:all)" }
380
+ example_group.append_after(:all) { fiddle << "append_after(:all)" }
381
+ ExampleGroup.after(:all) { fiddle << "Example.after(:all)" }
382
+ ExampleGroup.append_after(:all) { fiddle << "Example.append_after(:all)" }
383
+ example_group.run
384
+ fiddle.should == [
385
+ 'after(:each)',
386
+ 'append_after(:each)',
387
+ 'after(:all)',
388
+ 'append_after(:all)',
389
+ 'Example.after(:all)',
390
+ 'Example.append_after(:all)'
391
+ ]
392
+ end
393
+
394
+ it "should have accessible instance methods from included module" do
395
+ mod1_method_called = false
396
+ mod1 = Module.new do
397
+ define_method :mod1_method do
398
+ mod1_method_called = true
399
+ end
444
400
  end
445
- end
446
- example_group.run
447
- $included_predicate_matcher_found.should be(true)
448
- end
449
401
 
450
- it "should use a mock framework set up in config" do
451
- mod = Module.new do
452
- class << self
453
- def included(mod)
454
- $included_module = mod
402
+ mod2_method_called = false
403
+ mod2 = Module.new do
404
+ define_method :mod2_method do
405
+ mod2_method_called = true
455
406
  end
456
407
  end
457
408
 
458
- def teardown_mocks_for_rspec
459
- $torn_down = true
409
+ example_group.include mod1, mod2
410
+
411
+ example_group.it("test") do
412
+ mod1_method
413
+ mod2_method
460
414
  end
415
+ example_group.run
416
+ mod1_method_called.should be_true
417
+ mod2_method_called.should be_true
461
418
  end
462
419
 
463
- begin
464
- $included_module = nil
465
- $torn_down = true
466
- Spec::Runner.configuration.mock_with mod
420
+ it "should include targetted modules included using configuration" do
421
+ mod1 = Module.new
422
+ mod2 = Module.new
423
+ mod3 = Module.new
424
+ Spec::Runner.configuration.include(mod1, mod2)
425
+ Spec::Runner.configuration.include(mod3, :type => :not_special)
467
426
 
468
- example_group = Class.new(ExampleGroup) do
469
- describe('example')
427
+ example_group = Class.new(@special_example_group).describe("I'm special", :type => :special) do
470
428
  it "does nothing"
471
429
  end
472
430
  example_group.run
473
431
 
474
- $included_module.should_not be_nil
475
- $torn_down.should == true
476
- ensure
477
- Spec::Runner.configuration.mock_with :rspec
432
+ example_group.included_modules.should include(mod1)
433
+ example_group.included_modules.should include(mod2)
434
+ example_group.included_modules.should_not include(mod3)
478
435
  end
479
- end
480
- end
481
436
 
482
- describe ExampleGroup, "#run with pending example that has a failing assertion" do
483
- before do
484
- example_group.it("should be pending") do
485
- pending("Example fails") {false.should be_true}
437
+ it "should include any predicate_matchers included using configuration" do
438
+ $included_predicate_matcher_found = false
439
+ Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
440
+ example_group = Class.new(ExampleGroup) do
441
+ describe('example')
442
+ it "should respond to do_something" do
443
+ $included_predicate_matcher_found = respond_to?(:do_something)
444
+ end
445
+ end
446
+ example_group.run
447
+ $included_predicate_matcher_found.should be(true)
486
448
  end
487
- end
488
449
 
489
- it "should send example_pending to formatter" do
490
- @formatter.should_receive(:example_pending).with("example", "should be pending", "Example fails")
491
- example_group.run
492
- end
493
- end
450
+ it "should use a mock framework set up in config" do
451
+ mod = Module.new do
452
+ class << self
453
+ def included(mod)
454
+ $included_module = mod
455
+ end
456
+ end
457
+
458
+ def teardown_mocks_for_rspec
459
+ $torn_down = true
460
+ end
461
+ end
494
462
 
495
- describe ExampleGroup, "#run with pending example that does not have a failing assertion" do
496
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
463
+ begin
464
+ $included_module = nil
465
+ $torn_down = true
466
+ Spec::Runner.configuration.mock_with mod
497
467
 
498
- before do
499
- example_group.it("should be pending") do
500
- pending("Example passes") {true.should be_true}
468
+ example_group = Class.new(ExampleGroup) do
469
+ describe('example')
470
+ it "does nothing"
471
+ end
472
+ example_group.run
473
+
474
+ $included_module.should_not be_nil
475
+ $torn_down.should == true
476
+ ensure
477
+ Spec::Runner.configuration.mock_with :rspec
478
+ end
501
479
  end
502
480
  end
503
481
 
504
- it "should send example_pending to formatter" do
505
- @formatter.should_receive(:example_pending).with("example", "should be pending", "Example passes")
506
- example_group.run
482
+ describe ExampleGroup, "#run with pending example that has a failing assertion" do
483
+ before do
484
+ example_group.it("should be pending") do
485
+ pending("Example fails") {false.should be_true}
486
+ end
487
+ end
488
+
489
+ it "should send example_pending to formatter" do
490
+ @formatter.should_receive(:example_pending).with("example", "should be pending", "Example fails")
491
+ example_group.run
492
+ end
507
493
  end
508
- end
509
494
 
510
- describe ExampleGroup, "#run when before(:all) fails" do
511
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
495
+ describe ExampleGroup, "#run with pending example that does not have a failing assertion" do
496
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
512
497
 
513
- before do
514
- ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" }
515
- end
498
+ before do
499
+ example_group.it("should be pending") do
500
+ pending("Example passes") {true.should be_true}
501
+ end
502
+ end
516
503
 
517
- it "should not run any example" do
518
- spec_ran = false
519
- example_group.it("test") {spec_ran = true}
520
- example_group.run
521
- spec_ran.should be_false
504
+ it "should send example_pending to formatter" do
505
+ @formatter.should_receive(:example_pending).with("example", "should be pending", "Example passes")
506
+ example_group.run
507
+ end
522
508
  end
523
509
 
524
- it "should run ExampleGroup after(:all)" do
525
- after_all_ran = false
526
- ExampleGroup.after(:all) { after_all_ran = true }
527
- example_group.run
528
- after_all_ran.should be_true
529
- end
510
+ describe ExampleGroup, "#run when before(:all) fails" do
511
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
530
512
 
531
- it "should run example_group after(:all)" do
532
- after_all_ran = false
533
- example_group.after(:all) { after_all_ran = true }
534
- example_group.run
535
- after_all_ran.should be_true
536
- end
513
+ before do
514
+ ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" }
515
+ end
537
516
 
538
- it "should supply before(:all) as description" do
539
- @reporter.should_receive(:failure) do |example, error|
540
- example.description.should eql("before(:all)")
541
- error.message.should eql("before(:all) failure")
517
+ it "should not run any example" do
518
+ spec_ran = false
519
+ example_group.it("test") {spec_ran = true}
520
+ example_group.run
521
+ spec_ran.should be_false
542
522
  end
543
523
 
544
- example_group.it("test") {true}
545
- example_group.run
546
- end
547
- end
524
+ it "should run ExampleGroup after(:all)" do
525
+ after_all_ran = false
526
+ ExampleGroup.after(:all) { after_all_ran = true }
527
+ example_group.run
528
+ after_all_ran.should be_true
529
+ end
548
530
 
549
- describe ExampleGroup, "#run when before(:each) fails" do
550
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
531
+ it "should run example_group after(:all)" do
532
+ after_all_ran = false
533
+ example_group.after(:all) { after_all_ran = true }
534
+ example_group.run
535
+ after_all_ran.should be_true
536
+ end
551
537
 
552
- before do
553
- ExampleGroup.before(:each) { raise NonStandardError }
554
- end
538
+ it "should supply before(:all) as description" do
539
+ @reporter.should_receive(:failure) do |example, error|
540
+ example.description.should eql("before(:all)")
541
+ error.message.should eql("before(:all) failure")
542
+ end
555
543
 
556
- it "should run after(:all)" do
557
- after_all_ran = false
558
- ExampleGroup.after(:all) { after_all_ran = true }
559
- example_group.run
560
- after_all_ran.should be_true
544
+ example_group.it("test") {true}
545
+ example_group.run
546
+ end
561
547
  end
562
- end
563
548
 
564
- describe ExampleGroup, "#run when any example fails" do
565
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
549
+ describe ExampleGroup, "#run when before(:each) fails" do
550
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
566
551
 
567
- before do
568
- example_group.it("should") { raise NonStandardError }
569
- end
552
+ before do
553
+ ExampleGroup.before(:each) { raise NonStandardError }
554
+ end
570
555
 
571
- it "should run after(:all)" do
572
- after_all_ran = false
573
- ExampleGroup.after(:all) { after_all_ran = true }
574
- example_group.run
575
- after_all_ran.should be_true
556
+ it "should run after(:all)" do
557
+ after_all_ran = false
558
+ ExampleGroup.after(:all) { after_all_ran = true }
559
+ example_group.run
560
+ after_all_ran.should be_true
561
+ end
576
562
  end
577
- end
578
563
 
579
- describe ExampleGroup, "#run when first after(:each) block fails" do
580
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
564
+ describe ExampleGroup, "#run when any example fails" do
565
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
581
566
 
582
- before do
583
- class << example_group
584
- attr_accessor :first_after_ran, :second_after_ran
567
+ before do
568
+ example_group.it("should") { raise NonStandardError }
585
569
  end
586
- example_group.first_after_ran = false
587
- example_group.second_after_ran = false
588
570
 
589
- example_group.after(:each) do
590
- self.class.second_after_ran = true
591
- end
592
- example_group.after(:each) do
593
- self.class.first_after_ran = true
594
- raise "first"
571
+ it "should run after(:all)" do
572
+ after_all_ran = false
573
+ ExampleGroup.after(:all) { after_all_ran = true }
574
+ example_group.run
575
+ after_all_ran.should be_true
595
576
  end
596
577
  end
597
578
 
598
- it "should run second after(:each) block" do
599
- reporter.should_receive(:example_finished) do |example, error|
600
- example.should equal(example)
601
- error.message.should eql("first")
602
- end
603
- example_group.run
604
- example_group.first_after_ran.should be_true
605
- example_group.second_after_ran.should be_true
606
- end
607
- end
579
+ describe ExampleGroup, "#run when first after(:each) block fails" do
580
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
608
581
 
609
- describe ExampleGroup, "#run when first before(:each) block fails" do
610
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
582
+ before do
583
+ class << example_group
584
+ attr_accessor :first_after_ran, :second_after_ran
585
+ end
586
+ example_group.first_after_ran = false
587
+ example_group.second_after_ran = false
611
588
 
612
- before do
613
- class << example_group
614
- attr_accessor :first_before_ran, :second_before_ran
589
+ example_group.after(:each) do
590
+ self.class.second_after_ran = true
591
+ end
592
+ example_group.after(:each) do
593
+ self.class.first_after_ran = true
594
+ raise "first"
595
+ end
615
596
  end
616
- example_group.first_before_ran = false
617
- example_group.second_before_ran = false
618
597
 
619
- example_group.before(:each) do
620
- self.class.first_before_ran = true
621
- raise "first"
622
- end
623
- example_group.before(:each) do
624
- self.class.second_before_ran = true
598
+ it "should run second after(:each) block" do
599
+ reporter.should_receive(:example_finished) do |example, error|
600
+ example.should equal(example)
601
+ error.message.should eql("first")
602
+ end
603
+ example_group.run
604
+ example_group.first_after_ran.should be_true
605
+ example_group.second_after_ran.should be_true
625
606
  end
626
607
  end
627
608
 
628
- it "should not run second before(:each)" do
629
- reporter.should_receive(:example_finished) do |name, error|
630
- error.message.should eql("first")
609
+ describe ExampleGroup, "#run when first before(:each) block fails" do
610
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
611
+
612
+ before do
613
+ class << example_group
614
+ attr_accessor :first_before_ran, :second_before_ran
615
+ end
616
+ example_group.first_before_ran = false
617
+ example_group.second_before_ran = false
618
+
619
+ example_group.before(:each) do
620
+ self.class.first_before_ran = true
621
+ raise "first"
622
+ end
623
+ example_group.before(:each) do
624
+ self.class.second_before_ran = true
625
+ end
626
+ end
627
+
628
+ it "should not run second before(:each)" do
629
+ reporter.should_receive(:example_finished) do |name, error|
630
+ error.message.should eql("first")
631
+ end
632
+ example_group.run
633
+ example_group.first_before_ran.should be_true
634
+ example_group.second_before_ran.should be_false
631
635
  end
632
- example_group.run
633
- example_group.first_before_ran.should be_true
634
- example_group.second_before_ran.should be_false
635
636
  end
636
- end
637
637
 
638
- describe ExampleGroup, "#run when failure in after(:all)" do
639
- it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
638
+ describe ExampleGroup, "#run when failure in after(:all)" do
639
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
640
640
 
641
- before do
642
- ExampleGroup.after(:all) { raise NonStandardError, "in after(:all)" }
643
- end
641
+ before do
642
+ ExampleGroup.after(:all) { raise NonStandardError, "in after(:all)" }
643
+ end
644
644
 
645
- it "should return false" do
646
- example_group.run.should be_false
645
+ it "should return false" do
646
+ example_group.run.should be_false
647
+ end
647
648
  end
648
649
  end
649
650
  end
@@ -673,48 +674,6 @@ module Spec
673
674
  end
674
675
  end
675
676
 
676
- describe Enumerable do
677
- before(:each) do
678
- Kernel.stub!(:warn)
679
- end
680
-
681
- def each(&block)
682
- ["4", "2", "1"].each(&block)
683
- end
684
-
685
- it "should be included in examples because it is a module" do
686
- map{|e| e.to_i}.should == [4,2,1]
687
- end
688
- end
689
-
690
- describe "An", Enumerable, "as a second argument" do
691
- before(:each) do
692
- Kernel.stub!(:warn)
693
- end
694
-
695
- def each(&block)
696
- ["4", "2", "1"].each(&block)
697
- end
698
-
699
- it "should be included in examples because it is a module" do
700
- map{|e| e.to_i}.should == [4,2,1]
701
- end
702
- end
703
-
704
- describe Enumerable do
705
- describe "as the parent of nested example groups" do
706
- before(:each) do
707
- Kernel.stub!(:warn)
708
- end
709
-
710
- it "should be included in examples because it is a module" do
711
- pending("need to make sure nested groups know the described type") do
712
- map{|e| e.to_i}.should == [4,2,1]
713
- end
714
- end
715
- end
716
- end
717
-
718
677
  describe String do
719
678
  it "should not be included in examples because it is not a module" do
720
679
  lambda{self.map}.should raise_error(NoMethodError, /undefined method `map' for/)