dchelimsky-rspec 1.1.11 → 1.1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.autotest +4 -0
  2. data/History.txt +19 -3
  3. data/Manifest.txt +6 -1
  4. data/examples/failing/README.txt +7 -0
  5. data/examples/failing/diffing_spec.rb +36 -0
  6. data/examples/failing/failing_autogenerated_docstrings_example.rb +19 -0
  7. data/examples/failing/failure_in_setup.rb +10 -0
  8. data/examples/failing/failure_in_teardown.rb +10 -0
  9. data/examples/failing/mocking_example.rb +40 -0
  10. data/examples/failing/mocking_with_flexmock.rb +26 -0
  11. data/examples/failing/mocking_with_mocha.rb +25 -0
  12. data/examples/failing/mocking_with_rr.rb +27 -0
  13. data/examples/failing/partial_mock_example.rb +20 -0
  14. data/examples/failing/predicate_example.rb +34 -0
  15. data/examples/failing/raising_example.rb +47 -0
  16. data/examples/failing/spec_helper.rb +3 -0
  17. data/examples/failing/syntax_error_example.rb +7 -0
  18. data/examples/failing/team_spec.rb +44 -0
  19. data/examples/failing/timeout_behaviour.rb +7 -0
  20. data/examples/passing/custom_formatter.rb +1 -1
  21. data/examples/passing/simple_matcher_example.rb +31 -0
  22. data/lib/autotest/rspec.rb +1 -1
  23. data/lib/spec/dsl/main.rb +82 -0
  24. data/lib/spec/dsl.rb +1 -0
  25. data/lib/spec/example/before_and_after_hooks.rb +2 -1
  26. data/lib/spec/example/configuration.rb +1 -1
  27. data/lib/spec/example/example_group.rb +1 -0
  28. data/lib/spec/example/example_group_factory.rb +2 -1
  29. data/lib/spec/example/example_group_methods.rb +40 -25
  30. data/lib/spec/example/example_methods.rb +19 -8
  31. data/lib/spec/example.rb +15 -17
  32. data/lib/spec/expectations/handler.rb +23 -28
  33. data/lib/spec/expectations/wrap_expectation.rb +56 -0
  34. data/lib/spec/expectations.rb +22 -18
  35. data/lib/spec/extensions.rb +0 -1
  36. data/lib/spec/interop/test/unit/testcase.rb +19 -17
  37. data/lib/spec/matchers/be_close.rb +6 -22
  38. data/lib/spec/matchers/eql.rb +7 -25
  39. data/lib/spec/matchers/equal.rb +6 -24
  40. data/lib/spec/matchers/errors.rb +5 -0
  41. data/lib/spec/matchers/exist.rb +8 -14
  42. data/lib/spec/matchers/generated_descriptions.rb +48 -0
  43. data/lib/spec/matchers/has.rb +12 -28
  44. data/lib/spec/matchers/include.rb +12 -9
  45. data/lib/spec/matchers/match.rb +8 -27
  46. data/lib/spec/matchers/method_missing.rb +9 -0
  47. data/lib/spec/matchers/operator_matcher.rb +23 -46
  48. data/lib/spec/matchers/raise_error.rb +4 -8
  49. data/lib/spec/matchers/respond_to.rb +2 -1
  50. data/lib/spec/matchers/throw_symbol.rb +9 -3
  51. data/lib/spec/mocks/message_expectation.rb +0 -5
  52. data/lib/spec/mocks/proxy.rb +12 -10
  53. data/lib/spec/rake/spectask.rb +4 -6
  54. data/lib/spec/runner/class_and_arguments_parser.rb +7 -9
  55. data/lib/spec/runner/command_line.rb +6 -8
  56. data/lib/spec/runner/formatter/base_text_formatter.rb +3 -2
  57. data/lib/spec/runner/option_parser.rb +4 -6
  58. data/lib/spec/runner/spec_parser.rb +5 -5
  59. data/lib/spec/runner.rb +37 -39
  60. data/lib/spec/story/runner/story_runner.rb +10 -6
  61. data/lib/spec/story/runner.rb +40 -42
  62. data/lib/spec/story/world.rb +66 -70
  63. data/lib/spec/version.rb +3 -1
  64. data/lib/spec.rb +21 -19
  65. data/rspec.gemspec +15 -6
  66. data/spec/autotest/autotest_helper.rb +2 -2
  67. data/spec/autotest/discover_spec.rb +4 -15
  68. data/spec/autotest/failed_results_re_spec.rb +24 -0
  69. data/spec/autotest/rspec_spec.rb +0 -37
  70. data/spec/spec/dsl/main_spec.rb +65 -0
  71. data/spec/spec/example/example_group_class_definition_spec.rb +6 -2
  72. data/spec/spec/example/example_group_factory_spec.rb +2 -1
  73. data/spec/spec/example/example_group_methods_spec.rb +138 -141
  74. data/spec/spec/example/example_group_spec.rb +3 -5
  75. data/spec/spec/example/example_methods_spec.rb +60 -23
  76. data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
  77. data/spec/spec/interop/test/unit/spec_spec.rb +1 -5
  78. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +4 -0
  79. data/spec/spec/matchers/be_close_spec.rb +12 -10
  80. data/spec/spec/matchers/description_generation_spec.rb +1 -1
  81. data/spec/spec/matchers/eql_spec.rb +7 -6
  82. data/spec/spec/matchers/equal_spec.rb +7 -6
  83. data/spec/spec/matchers/has_spec.rb +1 -1
  84. data/spec/spec/matchers/have_spec.rb +23 -18
  85. data/spec/spec/matchers/include_spec.rb +24 -0
  86. data/spec/spec/matchers/matcher_methods_spec.rb +1 -13
  87. data/spec/spec/matchers/throw_symbol_spec.rb +3 -3
  88. data/spec/spec/mocks/bug_report_11545_spec.rb +4 -5
  89. data/spec/spec/mocks/bug_report_496.rb +11 -9
  90. data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
  91. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +1 -1
  92. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +4 -14
  93. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +1 -1
  94. data/spec/spec/runner/options_spec.rb +1 -1
  95. data/spec/spec/runner/spec_parser_spec.rb +76 -80
  96. data/spec/spec_helper.rb +4 -0
  97. data/stories/example_groups/autogenerated_docstrings +4 -4
  98. data/stories/interop/test_but_not_test_unit +14 -0
  99. data/stories/resources/helpers/story_helper.rb +1 -1
  100. data/stories/resources/test/spec_including_test_but_not_unit.rb +11 -0
  101. data/story_server/prototype/javascripts/prototype.js +1 -1
  102. metadata +34 -53
  103. data/lib/spec/extensions/metaclass.rb +0 -7
@@ -3,8 +3,12 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  module Spec
4
4
  module Example
5
5
  class ExampleGroupSubclass < ExampleGroup
6
- class << self
7
- attr_accessor :examples_ran
6
+ def self.examples_ran
7
+ @examples_ran
8
+ end
9
+
10
+ def self.examples_ran=(examples_ran)
11
+ @examples_ran = examples_ran
8
12
  end
9
13
 
10
14
  @@class_variable = :class_variable
@@ -146,7 +146,8 @@ module Spec
146
146
  end
147
147
  Spec::Runner.options.example_groups.should_not include(example_group)
148
148
  end
149
-
149
+
150
+
150
151
  after(:each) do
151
152
  Spec::Example::ExampleGroupFactory.reset
152
153
  end
@@ -16,12 +16,8 @@ module Spec
16
16
  describe("ExampleGroup")
17
17
  it "does nothing"
18
18
  end
19
- class << example_group
20
- public :include
21
- end
22
- @result = nil
23
19
  end
24
-
20
+
25
21
  after(:each) do
26
22
  ExampleGroup.reset
27
23
  end
@@ -29,93 +25,84 @@ module Spec
29
25
  ["describe","context"].each do |method|
30
26
  describe "##{method}" do
31
27
  describe "when creating an ExampleGroup" do
32
- attr_reader :child_example_group
33
- before do
34
- @child_example_group = @example_group.send method, "Another ExampleGroup" do
35
- it "should pass" do
36
- true.should be_true
37
- end
28
+ before(:each) do
29
+ @parent_example_group = Class.new(ExampleGroup) do
30
+ example "first example" do; end
31
+ end
32
+ @child_example_group = @parent_example_group.__send__ method, "Child" do
33
+ example "second example" do; end
38
34
  end
39
35
  end
40
36
 
41
37
  it "should create a subclass of the ExampleGroup when passed a block" do
42
- child_example_group.superclass.should == @example_group
43
- @options.example_groups.should include(child_example_group)
38
+ @child_example_group.superclass.should == @parent_example_group
39
+ options.example_groups.should include(@child_example_group)
44
40
  end
45
41
 
46
42
  it "should not inherit examples" do
47
- child_example_group.examples.length.should == 1
43
+ @child_example_group.should have(1).examples
48
44
  end
49
45
  end
50
46
 
51
47
  describe "when creating a SharedExampleGroup" do
52
- attr_reader :name, :shared_example_group
53
48
  before(:each) do
54
- @name = "A Shared ExampleGroup"
55
- @shared_example_group = @example_group.send method, name, :shared => true do
56
- it "should pass" do
57
- true.should be_true
58
- end
59
- end
49
+ @shared_example_group = @example_group.__send__ method, "A Shared ExampleGroup", :shared => true do; end
60
50
  end
61
51
 
62
52
  after(:each) do
63
- SharedExampleGroup.clear
53
+ SharedExampleGroup.instance_eval{@shared_example_groups}.delete @shared_example_group
64
54
  end
65
55
 
66
56
  it "should create a SharedExampleGroup" do
67
- SharedExampleGroup.find(name).should == shared_example_group
57
+ @shared_example_group.should_not be_nil
58
+ SharedExampleGroup.find("A Shared ExampleGroup").should == @shared_example_group
68
59
  end
69
60
  end
70
61
 
71
62
  end
72
63
  end
73
-
74
- describe "#it" do
75
- it "should should create an example instance" do
76
- lambda {
77
- @example_group.it("")
78
- }.should change { @example_group.examples.length }.by(1)
64
+
65
+ [:specify, :it].each do |method|
66
+ describe "##{method.to_s}" do
67
+ it "should should create an example" do
68
+ lambda {
69
+ @example_group.__send__(method, "")
70
+ }.should change { @example_group.examples.length }.by(1)
71
+ end
79
72
  end
80
73
  end
74
+
75
+ [:xit, :xspecify].each do |method|
76
+ describe "##{method.to_s}" do
77
+ before(:each) do
78
+ Kernel.stub!(:warn)
79
+ end
81
80
 
82
- describe "#xit and #xspecify" do
83
- before(:each) do
84
- Kernel.stub!(:warn)
85
- end
86
-
87
- it "should NOT create an example instance" do
88
- lambda {
89
- @example_group.xit("")
90
- }.should_not change(@example_group.examples, :length)
91
-
92
- lambda {
93
- @example_group.xspecify("")
94
- }.should_not change(@example_group.examples, :length)
95
- end
81
+ it "should NOT create an example" do
82
+ lambda {
83
+ @example_group.__send__(method,"")
84
+ }.should_not change(@example_group.examples, :length)
85
+ end
96
86
 
97
- it "should warn that it is disabled" do
98
- Kernel.should_receive(:warn).with("Example disabled: foo").twice
99
- @example_group.xit("foo")
100
- @example_group.xspecify("foo")
87
+ it "should warn that the example is disabled" do
88
+ Kernel.should_receive(:warn).with("Example disabled: foo")
89
+ @example_group.__send__(method,"foo")
90
+ end
101
91
  end
102
92
  end
93
+
103
94
 
104
95
  describe "#examples" do
105
96
  it "should have Examples" do
106
97
  example_group = Class.new(ExampleGroup) do
107
- describe('example')
108
- it "should pass" do
109
- 1.should == 1
110
- end
98
+ it "should exist" do; end
111
99
  end
112
100
  example_group.examples.length.should == 1
113
- example_group.examples.first.description.should == "should pass"
101
+ example_group.examples.first.description.should == "should exist"
114
102
  end
115
103
 
116
104
  it "should not include methods that begin with test (only when TU interop is loaded)" do
117
105
  example_group = Class.new(ExampleGroup) do
118
- describe('example')
119
106
  def test_any_args(*args)
120
107
  true.should be_true
121
108
  end
@@ -138,7 +125,6 @@ module Spec
138
125
 
139
126
  it "should include methods that begin with should and has an arity of 0 in suite" do
140
127
  example_group = Class.new(ExampleGroup) do
141
- describe('example')
142
128
  def shouldCamelCase
143
129
  true.should be_true
144
130
  end
@@ -158,20 +144,21 @@ module Spec
158
144
  raise "This is not a real example"
159
145
  end
160
146
  end
161
- example_group = example_group.dup
162
- example_group.examples.length.should == 4
163
- descriptions = example_group.examples.collect {|example| example.description}.sort
164
- descriptions.should include("shouldCamelCase")
165
- descriptions.should include("should_any_args")
166
- descriptions.should include("should_something")
167
- descriptions.should include("should_not_something")
168
- descriptions.should_not include("should")
169
- descriptions.should_not include("should_not")
147
+ example_group.should have(4).examples
148
+ descriptions = example_group.examples.collect {|example| example.description}
149
+ descriptions.should include(
150
+ "shouldCamelCase",
151
+ "should_any_args",
152
+ "should_something",
153
+ "should_not_something")
154
+ descriptions.should_not include(
155
+ "should",
156
+ "should_not"
157
+ )
170
158
  end
171
159
 
172
160
  it "should not include methods that begin with test_ and has an arity > 0 in suite" do
173
161
  example_group = Class.new(ExampleGroup) do
174
- describe('example')
175
162
  def test_invalid(foo)
176
163
  1.should == 1
177
164
  end
@@ -179,12 +166,11 @@ module Spec
179
166
  1.should == 1
180
167
  end
181
168
  end
182
- example_group.examples.length.should == 0
169
+ example_group.should have(:no).examples
183
170
  end
184
171
 
185
172
  it "should not include methods that begin with should_ and has an arity > 0 in suite" do
186
173
  example_group = Class.new(ExampleGroup) do
187
- describe('example')
188
174
  def should_invalid(foo)
189
175
  1.should == 2
190
176
  end
@@ -198,7 +184,7 @@ module Spec
198
184
  1.should == 1
199
185
  end
200
186
  end
201
- example_group.examples.length.should == 1
187
+ example_group.should have(1).examples
202
188
  example_group.run.should be_true
203
189
  end
204
190
 
@@ -208,7 +194,7 @@ module Spec
208
194
  1.should == 2
209
195
  end
210
196
  end
211
- example_group.examples.length.should == 1
197
+ example_group.should have(1).examples
212
198
  example_group.run.should be_false
213
199
  end
214
200
  end
@@ -221,7 +207,7 @@ module Spec
221
207
  end
222
208
  end
223
209
 
224
- describe "#set_description(String)" do
210
+ describe "given a String" do
225
211
  before(:each) do
226
212
  example_group.set_description("abc")
227
213
  end
@@ -235,7 +221,7 @@ module Spec
235
221
  end
236
222
  end
237
223
 
238
- describe "#set_description(Type)" do
224
+ describe "given a Class" do
239
225
  before(:each) do
240
226
  example_group.set_description(ExampleGroup)
241
227
  end
@@ -249,7 +235,7 @@ module Spec
249
235
  end
250
236
  end
251
237
 
252
- describe "#set_description(String, Type)" do
238
+ describe "given a String and a Class" do
253
239
  before(:each) do
254
240
  example_group.set_description("behaving", ExampleGroup)
255
241
  end
@@ -263,7 +249,7 @@ module Spec
263
249
  end
264
250
  end
265
251
 
266
- describe "#set_description(Type, String not starting with a space)" do
252
+ describe "given a Class and a String (starting with an alpha char)" do
267
253
  before(:each) do
268
254
  example_group.set_description(ExampleGroup, "behaving")
269
255
  end
@@ -273,7 +259,7 @@ module Spec
273
259
  end
274
260
  end
275
261
 
276
- describe "#set_description(Type, String starting with .)" do
262
+ describe "given a Class and a String (starting with a '.')" do
277
263
  before(:each) do
278
264
  example_group.set_description(ExampleGroup, ".behaving")
279
265
  end
@@ -375,7 +361,11 @@ module Spec
375
361
  end
376
362
 
377
363
  it "should return an Array of the description args from each class in the hierarchy" do
378
- child_example_group = Class.new(example_group)
364
+ parent_example_group = Class.new(ExampleGroup) do
365
+ describe("Parent")
366
+ end
367
+
368
+ child_example_group = Class.new(parent_example_group)
379
369
  child_example_group.describe("Child", ExampleGroup)
380
370
  child_example_group.description.should_not be_empty
381
371
 
@@ -384,7 +374,7 @@ module Spec
384
374
  grand_child_example_group.description.should_not be_empty
385
375
 
386
376
  grand_child_example_group.description_parts.should == [
387
- "ExampleGroup",
377
+ "Parent",
388
378
  "Child",
389
379
  Spec::Example::ExampleGroup,
390
380
  "GrandChild",
@@ -415,64 +405,49 @@ module Spec
415
405
  describe "#remove_after" do
416
406
  it "should unregister a given after(:each) block" do
417
407
  after_all_ran = false
418
- @example_group.it("example") {}
419
408
  proc = Proc.new { after_all_ran = true }
420
- ExampleGroup.after(:each, &proc)
421
- @example_group.run
409
+
410
+ example_group = Class.new(ExampleGroup) do
411
+ specify("example") {}
412
+ after(:each, &proc)
413
+ end
414
+
415
+ example_group.run
422
416
  after_all_ran.should be_true
423
417
 
424
418
  after_all_ran = false
425
- ExampleGroup.remove_after(:each, &proc)
426
- @example_group.run
419
+ example_group.remove_after(:each, &proc)
420
+ example_group.run
427
421
  after_all_ran.should be_false
428
422
  end
429
423
  end
430
424
 
431
425
  describe "#include" do
432
426
  it "should have accessible class methods from included module" do
433
- mod1_method_called = false
434
- mod1 = Module.new do
435
- extend Spec::MetaClass
436
- class_methods = Module.new do
437
- define_method :mod1_method do
438
- mod1_method_called = true
439
- end
440
- end
441
-
442
- metaclass.class_eval do
443
- define_method(:included) do |receiver|
444
- receiver.extend class_methods
445
- end
446
- end
447
- end
448
-
449
- mod2_method_called = false
450
- mod2 = Module.new do
451
- extend Spec::MetaClass
427
+ mod_method_called = false
428
+ mod = Module.new do
452
429
  class_methods = Module.new do
453
- define_method :mod2_method do
454
- mod2_method_called = true
430
+ define_method :mod_method do
431
+ mod_method_called = true
455
432
  end
456
433
  end
457
434
 
458
- metaclass.class_eval do
435
+ self.class.class_eval do
459
436
  define_method(:included) do |receiver|
460
437
  receiver.extend class_methods
461
438
  end
462
439
  end
463
440
  end
464
441
 
465
- @example_group.include mod1, mod2
442
+ @example_group.__send__ :include, mod
466
443
 
467
- @example_group.mod1_method
468
- @example_group.mod2_method
469
- mod1_method_called.should be_true
470
- mod2_method_called.should be_true
444
+ @example_group.mod_method
445
+ mod_method_called.should be_true
471
446
  end
472
447
  end
473
448
 
474
449
  describe "#number_of_examples" do
475
- it "should count number of specs" do
450
+ it "should count number of examples" do
476
451
  proc do
477
452
  @example_group.it("one") {}
478
453
  @example_group.it("two") {}
@@ -485,58 +460,54 @@ module Spec
485
460
  describe "#class_eval" do
486
461
  it "should allow constants to be defined" do
487
462
  example_group = Class.new(ExampleGroup) do
488
- describe('example')
489
463
  FOO = 1
490
464
  it "should reference FOO" do
491
465
  FOO.should == 1
492
466
  end
493
467
  end
494
- example_group.run
468
+ success = example_group.run
469
+ success.should be_true
495
470
  Object.const_defined?(:FOO).should == false
496
471
  end
497
472
  end
498
473
 
499
474
  describe '#register' do
475
+ after(:each) do
476
+ example_group.unregister
477
+ end
500
478
  it "should add ExampleGroup to set of ExampleGroups to be run" do
501
- options.example_groups.delete(example_group)
502
- options.example_groups.should_not include(example_group)
503
-
504
- example_group.register {}
479
+ example_group.register
505
480
  options.example_groups.should include(example_group)
506
481
  end
507
482
  end
508
483
 
509
484
  describe '#unregister' do
510
- before do
511
- options.example_groups.should include(example_group)
485
+ before(:each) do
486
+ example_group.register
512
487
  end
513
-
514
488
  it "should remove ExampleGroup from set of ExampleGroups to be run" do
515
489
  example_group.unregister
516
490
  options.example_groups.should_not include(example_group)
517
491
  end
518
492
  end
519
-
520
- describe "#registration_backtrace" do
521
- it "returns the backtrace of where the ExampleGroup was registered" do
522
- example_group = Class.new(ExampleGroup)
523
- example_group.registration_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
524
- end
525
- end
526
493
 
527
494
  describe "#run" do
528
- it "should add_example_group if there are any examples to run" do
529
- example_group = Class.new(ExampleGroup) do
530
- it "should do something" do end
495
+ describe "given an example group with at least one example" do
496
+ it "should call add_example_group" do
497
+ example_group = Class.new(ExampleGroup) do
498
+ example("anything") {}
499
+ end
500
+ reporter.should_receive(:add_example_group)
501
+ example_group.run
531
502
  end
532
- reporter.should_receive(:add_example_group)
533
- example_group.run
534
503
  end
535
504
 
536
- it "should NOT add_example_group if there are no examples to run" do
537
- example_group = Class.new(ExampleGroup) do end
538
- reporter.should_not_receive(:add_example_group)
539
- example_group.run
505
+ describe "given an example group with no examples" do
506
+ it "should NOT call add_example_group" do
507
+ example_group = Class.new(ExampleGroup) do end
508
+ reporter.should_not_receive(:add_example_group)
509
+ example_group.run
510
+ end
540
511
  end
541
512
  end
542
513
 
@@ -544,13 +515,11 @@ module Spec
544
515
  it "should call new and matches? on the class used for matching examples" do
545
516
  example_group = Class.new(ExampleGroup) do
546
517
  it "should do something" do end
547
- class << self
548
- def specified_examples
549
- ["something"]
550
- end
551
- def to_s
552
- "TestMatcher"
553
- end
518
+ def self.specified_examples
519
+ ["something"]
520
+ end
521
+ def self.to_s
522
+ "TestMatcher"
554
523
  end
555
524
  end
556
525
 
@@ -576,7 +545,35 @@ module Spec
576
545
  group.options[:this].should == 'hash'
577
546
  end
578
547
  end
548
+
549
+ describe "#backtrace" do
550
+ it "returns the backtrace from where the example group was defined" do
551
+ example_group = Class.new(ExampleGroup).describe("foo") do
552
+ example "bar" do; end
553
+ end
554
+ example_group.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
555
+ end
556
+ end
557
+
558
+ describe "#example_group_backtrace (deprecated)" do
559
+ before(:each) do
560
+ Kernel.stub!(:warn)
561
+ end
562
+ it "sends a deprecation warning" do
563
+ example_group = Class.new(ExampleGroup) {}
564
+ Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
565
+ example_group.example_group_backtrace
566
+ end
567
+
568
+ it "returns the backtrace from where the example group was defined" do
569
+ example_group = Class.new(ExampleGroup).describe("foo") do
570
+ example "bar" do; end
571
+ end
572
+ example_group.example_group_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
573
+ end
574
+ end
575
+
579
576
  end
580
577
  end
581
578
  end
582
- end
579
+ end
@@ -449,10 +449,8 @@ module Spec
449
449
 
450
450
  it "should use a mock framework set up in config" do
451
451
  mod = Module.new do
452
- class << self
453
- def included(mod)
454
- $included_module = mod
455
- end
452
+ def self.included(mod)
453
+ $included_module = mod
456
454
  end
457
455
 
458
456
  def teardown_mocks_for_rspec
@@ -661,7 +659,7 @@ module Spec
661
659
  example_group = Class.new(ExampleSubclass) do
662
660
  describe(Array)
663
661
  end
664
- example_group.send(:described_type).should == Array
662
+ example_group.__send__(:described_type).should == Array
665
663
  end
666
664
 
667
665
  it "should concat descriptions when nested" do
@@ -134,14 +134,40 @@ module Spec
134
134
  end
135
135
  end
136
136
 
137
- describe "#implementation_backtrace" do
138
- it "returns the backtrace of where the implementation was defined" do
139
- example_group = Class.new(ExampleGroup) do
140
- it "should use ExampleMethods callbacks" do
137
+ describe "#backtrace" do
138
+ with_sandboxed_options do
139
+ it "returns the backtrace from where the example was defined" do
140
+ example_group = Class.new(ExampleGroup) do
141
+ example "of something" do; end
141
142
  end
143
+
144
+ example = example_group.examples.first
145
+ example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
146
+ end
147
+ end
148
+ end
149
+
150
+ describe "#implementation_backtrace (deprecated)" do
151
+ with_sandboxed_options do
152
+ before(:each) do
153
+ Kernel.stub!(:warn)
154
+ end
155
+
156
+ it "sends a deprecation warning" do
157
+ example_group = Class.new(ExampleGroup) {}
158
+ example = example_group.example("") {}
159
+ Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
160
+ example.implementation_backtrace
161
+ end
162
+
163
+ it "returns the backtrace from where the example was defined" do
164
+ example_group = Class.new(ExampleGroup) do
165
+ example "of something" do; end
166
+ end
167
+
168
+ example = example_group.examples.first
169
+ example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
142
170
  end
143
- example = example_group.examples.first
144
- example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
145
171
  end
146
172
  end
147
173
 
@@ -157,26 +183,37 @@ module Spec
157
183
  end
158
184
 
159
185
  describe "#subject" do
160
- it "should return an instance variable named after the described type" do
161
- example_group = describe(Array) do
162
- example {}
186
+ with_sandboxed_options do
187
+ it "should return an instance variable named after the described type" do
188
+ example_group = Class.new(ExampleGroup).describe(Array) do
189
+ example {}
190
+ end
191
+ example = example_group.examples.first
192
+ example.subject.should == []
163
193
  end
164
- example = example_group.examples.first
165
- example.subject.should == []
166
- end
167
-
168
- it "should not barf on a module (as opposed to a class)" do
169
- example_group = Class.new(ExampleGroup).describe(ObjectSpace) do
170
- example {}
194
+
195
+ it "should not barf on a module (as opposed to a class)" do
196
+ example_group = Class.new(ExampleGroup).describe(ObjectSpace) do
197
+ example {}
198
+ end
199
+ example_group.examples.first.subject.should be_nil
171
200
  end
172
- example_group.examples.first.subject.should be_nil
173
- end
174
-
175
- it "should not barf on a string" do
176
- example_group = describe('foo') do
177
- example {}
201
+
202
+ it "should not barf on a string" do
203
+ example_group = Class.new(ExampleGroup).describe('foo') do
204
+ example {}
205
+ end
206
+ example_group.examples.first.subject.should be_nil
207
+ end
208
+
209
+ it "should interact with the same scope as the before block" do
210
+ example_group = Class.new(ExampleGroup) do
211
+ subject { @foo = 'foo'}
212
+ example { should == @foo}
213
+ it { should == 'foo'}
214
+ end
215
+ example_group.run.should be_true
178
216
  end
179
- example_group.examples.first.subject.should be_nil
180
217
  end
181
218
  end
182
219