rspec 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +35 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +9 -44
  4. data/Rakefile +34 -51
  5. data/TODO +0 -1
  6. data/UPGRADE +0 -24
  7. data/bin/spec +0 -0
  8. data/bin/spec_translator +0 -0
  9. data/examples/pure/behave_as_example.rb +0 -0
  10. data/examples/pure/partial_mock_example.rb +1 -0
  11. data/examples/stories/calculator.rb +1 -1
  12. data/lib/autotest/rspec.rb +7 -9
  13. data/lib/spec/example.rb +1 -1
  14. data/lib/spec/example/configuration.rb +30 -16
  15. data/lib/spec/example/example_group.rb +2 -1
  16. data/lib/spec/example/example_group_factory.rb +23 -21
  17. data/lib/spec/example/example_group_methods.rb +18 -5
  18. data/lib/spec/example/example_matcher.rb +0 -0
  19. data/lib/spec/example/example_methods.rb +6 -0
  20. data/lib/spec/example/module_inclusion_warnings.rb +37 -0
  21. data/lib/spec/expectations/differs/default.rb +1 -1
  22. data/lib/spec/expectations/extensions/object.rb +4 -12
  23. data/lib/spec/expectations/handler.rb +8 -0
  24. data/lib/spec/extensions.rb +1 -0
  25. data/lib/spec/extensions/metaclass.rb +7 -0
  26. data/lib/spec/extensions/object.rb +0 -4
  27. data/lib/spec/matchers/change.rb +1 -1
  28. data/lib/spec/matchers/has.rb +1 -11
  29. data/lib/spec/matchers/operator_matcher.rb +0 -0
  30. data/lib/spec/matchers/raise_error.rb +53 -30
  31. data/lib/spec/mocks.rb +1 -1
  32. data/lib/spec/mocks/argument_constraint_matchers.rb +5 -1
  33. data/lib/spec/mocks/argument_expectation.rb +26 -0
  34. data/lib/spec/mocks/extensions.rb +1 -0
  35. data/lib/spec/mocks/framework.rb +15 -0
  36. data/lib/spec/mocks/message_expectation.rb +29 -5
  37. data/lib/spec/mocks/mock.rb +9 -7
  38. data/lib/spec/mocks/proxy.rb +26 -12
  39. data/lib/spec/rake/spectask.rb +5 -5
  40. data/lib/spec/runner/backtrace_tweaker.rb +1 -1
  41. data/lib/spec/runner/formatter/base_formatter.rb +2 -3
  42. data/lib/spec/runner/formatter/base_text_formatter.rb +2 -2
  43. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +4 -8
  44. data/lib/spec/runner/formatter/html_formatter.rb +18 -14
  45. data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
  46. data/lib/spec/runner/formatter/profile_formatter.rb +4 -0
  47. data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -1
  48. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  49. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +18 -7
  50. data/lib/spec/runner/option_parser.rb +17 -15
  51. data/lib/spec/runner/options.rb +37 -14
  52. data/lib/spec/runner/reporter.rb +15 -11
  53. data/lib/spec/story/extensions/regexp.rb +2 -2
  54. data/lib/spec/story/extensions/string.rb +2 -2
  55. data/lib/spec/story/runner.rb +9 -5
  56. data/lib/spec/story/runner/plain_text_story_runner.rb +2 -2
  57. data/lib/spec/story/runner/scenario_runner.rb +8 -0
  58. data/lib/spec/story/runner/story_mediator.rb +1 -1
  59. data/lib/spec/story/runner/story_runner.rb +3 -1
  60. data/lib/spec/story/step.rb +4 -4
  61. data/lib/spec/story/story.rb +8 -11
  62. data/lib/spec/story/world.rb +0 -1
  63. data/lib/spec/version.rb +2 -2
  64. data/plugins/mock_frameworks/rspec.rb +2 -0
  65. data/spec/autotest/rspec_spec.rb +12 -10
  66. data/spec/spec/example/configuration_spec.rb +0 -0
  67. data/spec/spec/example/example_group/described_module_spec.rb +20 -0
  68. data/spec/spec/example/example_group/warning_messages_spec.rb +76 -0
  69. data/spec/spec/example/example_group_factory_spec.rb +117 -102
  70. data/spec/spec/example/example_group_methods_spec.rb +51 -17
  71. data/spec/spec/example/example_group_spec.rb +13 -1
  72. data/spec/spec/example/example_methods_spec.rb +28 -6
  73. data/spec/spec/example/nested_example_group_spec.rb +12 -0
  74. data/spec/spec/example/predicate_matcher_spec.rb +0 -0
  75. data/spec/spec/expectations/differs/default_spec.rb +27 -9
  76. data/spec/spec/matchers/be_spec.rb +24 -0
  77. data/spec/spec/matchers/has_spec.rb +16 -0
  78. data/spec/spec/matchers/raise_error_spec.rb +124 -0
  79. data/spec/spec/mocks/{bug_report_10263.rb → bug_report_10263_spec.rb} +0 -0
  80. data/spec/spec/mocks/bug_report_11545_spec.rb +2 -0
  81. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +8 -0
  82. data/spec/spec/mocks/hash_including_matcher_spec.rb +32 -0
  83. data/spec/spec/mocks/mock_spec.rb +56 -37
  84. data/spec/spec/mocks/partial_mock_spec.rb +41 -5
  85. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
  86. data/spec/spec/runner/execution_context_spec.rb +7 -1
  87. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +3 -2
  88. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +30 -25
  89. data/spec/spec/runner/formatter/html_formatter_spec.rb +0 -3
  90. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +333 -0
  91. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +12 -2
  92. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -2
  93. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -78
  94. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +105 -1
  95. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -28
  96. data/spec/spec/runner/option_parser_spec.rb +65 -49
  97. data/spec/spec/runner/options_spec.rb +103 -17
  98. data/spec/spec/runner/reporter_spec.rb +10 -7
  99. data/spec/spec/runner/spec_drb.opts +1 -0
  100. data/spec/spec/runner/spec_parser_spec.rb +10 -4
  101. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +14 -13
  102. data/spec/spec/story/runner/scenario_runner_spec.rb +124 -52
  103. data/spec/spec/story/runner/story_mediator_spec.rb +2 -2
  104. data/spec/spec/story/runner/story_runner_spec.rb +40 -2
  105. data/spec/spec/story/runner_spec.rb +59 -72
  106. data/spec/spec/story/step_spec.rb +20 -1
  107. data/spec/spec/story/story_spec.rb +2 -2
  108. data/stories/all.rb +1 -1
  109. data/stories/example_groups/stories.rb +4 -3
  110. data/stories/mock_framework_integration/stories.rb +7 -0
  111. data/stories/mock_framework_integration/use_flexmock.story +9 -0
  112. data/stories/resources/spec/spec_with_flexmock.rb +18 -0
  113. metadata +21 -18
  114. data/pre_commit/lib/pre_commit.rb +0 -4
  115. data/pre_commit/lib/pre_commit/core.rb +0 -50
  116. data/pre_commit/lib/pre_commit/pre_commit.rb +0 -54
  117. data/pre_commit/lib/pre_commit/rspec.rb +0 -111
  118. data/pre_commit/lib/pre_commit/rspec_on_rails.rb +0 -313
  119. data/pre_commit/spec/pre_commit/pre_commit_spec.rb +0 -15
  120. data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +0 -36
  121. data/pre_commit/spec/spec_helper.rb +0 -3
  122. data/pre_commit/spec/spec_suite.rb +0 -11
@@ -293,39 +293,44 @@ module Spec
293
293
  end
294
294
 
295
295
  describe "#run_examples" do
296
- it "should use the standard runner by default" do
297
- runner = ::Spec::Runner::ExampleGroupRunner.new(@options)
298
- ::Spec::Runner::ExampleGroupRunner.should_receive(:new).
296
+ describe "when not given a custom runner" do
297
+ it "should use the standard" do
298
+ runner = ::Spec::Runner::ExampleGroupRunner.new(@options)
299
+ ::Spec::Runner::ExampleGroupRunner.should_receive(:new).
299
300
  with(@options).
300
301
  and_return(runner)
301
- @options.user_input_for_runner = nil
302
+ @options.user_input_for_runner = nil
302
303
 
303
- @options.run_examples
304
+ @options.run_examples
305
+ end
304
306
  end
305
307
 
306
- it "should use a custom runner when given" do
307
- runner = Custom::ExampleGroupRunner.new(@options, nil)
308
- Custom::ExampleGroupRunner.should_receive(:new).
308
+ describe "when given a custom runner" do
309
+ it "should use the custom runner" do
310
+ runner = Custom::ExampleGroupRunner.new(@options, nil)
311
+ Custom::ExampleGroupRunner.should_receive(:new).
309
312
  with(@options, nil).
310
313
  and_return(runner)
311
- @options.user_input_for_runner = "Custom::ExampleGroupRunner"
314
+ @options.user_input_for_runner = "Custom::ExampleGroupRunner"
312
315
 
313
- @options.run_examples
314
- end
316
+ @options.run_examples
317
+ end
315
318
 
316
- it "should use a custom runner with extra options" do
317
- runner = Custom::ExampleGroupRunner.new(@options, 'something')
318
- Custom::ExampleGroupRunner.should_receive(:new).
319
+ it "should use the custom runner with extra options" do
320
+ runner = Custom::ExampleGroupRunner.new(@options, 'something')
321
+ Custom::ExampleGroupRunner.should_receive(:new).
319
322
  with(@options, 'something').
320
323
  and_return(runner)
321
- @options.user_input_for_runner = "Custom::ExampleGroupRunner:something"
324
+ @options.user_input_for_runner = "Custom::ExampleGroupRunner:something"
322
325
 
323
- @options.run_examples
326
+ @options.run_examples
327
+ end
324
328
  end
325
329
 
326
330
  describe "when there are examples" do
327
331
  before(:each) do
328
- @options.add_example_group Class.new(::Spec::Example::ExampleGroup)
332
+ @example_group = Class.new(::Spec::Example::ExampleGroup)
333
+ @options.add_example_group @example_group
329
334
  @options.formatters << Formatter::BaseTextFormatter.new(@options, @out)
330
335
  end
331
336
 
@@ -339,6 +344,77 @@ module Spec
339
344
  @options.run_examples
340
345
  @options.examples_run?.should be_true
341
346
  end
347
+
348
+ describe "and the suite passes" do
349
+ before do
350
+ @example_group.should_receive(:run).and_return(true)
351
+ end
352
+
353
+ it "invokes after_suite_parts with true" do
354
+ success_result = nil
355
+ @options.after_suite_parts << lambda do |success|
356
+ success_result = success
357
+ end
358
+
359
+ @options.run_examples
360
+ success_result.should be_true
361
+ end
362
+ end
363
+
364
+ describe "and the suite fails" do
365
+ before do
366
+ @example_group.should_receive(:run).and_return(false)
367
+ end
368
+
369
+ it "invokes after_suite_parts with false" do
370
+ success_result = nil
371
+ @options.after_suite_parts << lambda do |success|
372
+ success_result = success
373
+ end
374
+
375
+ @options.run_examples
376
+ success_result.should be_false
377
+ end
378
+ end
379
+
380
+ describe "when using heckle runner" do
381
+ before(:each) do
382
+ @heckle_runner_mock = mock("HeckleRunner")
383
+ @options.heckle_runner = @heckle_runner_mock
384
+ end
385
+
386
+ it "should heckle" do
387
+ @heckle_runner_mock.should_receive(:heckle_with)
388
+ @options.run_examples
389
+ end
390
+
391
+ it "shouldn't heckle recursively" do
392
+ heckled = false
393
+ @heckle_runner_mock.should_receive(:heckle_with) {
394
+ heckled.should == false
395
+ heckled = true
396
+ @options.run_examples
397
+ }
398
+ @options.run_examples
399
+ end
400
+
401
+ it "shouldn't load spec files twice" do
402
+ example_runner = mock("ExampleGroupRunner")
403
+ example_runner_inside_heckle = mock("ExampleGroupRunner inside Heckle")
404
+
405
+ ExampleGroupRunner.should_receive(:new).twice.and_return(
406
+ example_runner, example_runner_inside_heckle
407
+ )
408
+
409
+ example_runner.stub!(:run)
410
+ example_runner.should_receive(:load_files)
411
+ @heckle_runner_mock.stub!(:heckle_with).and_return { @options.run_examples }
412
+ example_runner_inside_heckle.stub!(:run)
413
+ example_runner_inside_heckle.should_not_receive(:load_files)
414
+
415
+ @options.run_examples
416
+ end
417
+ end
342
418
  end
343
419
 
344
420
  describe "when there are no examples" do
@@ -357,6 +433,16 @@ module Spec
357
433
  @options.run_examples
358
434
  @options.examples_run?.should be_false
359
435
  end
436
+
437
+ it "invokes after_suite_parts with true" do
438
+ success_result = nil
439
+ @options.after_suite_parts << lambda do |success|
440
+ success_result = success
441
+ end
442
+
443
+ @options.run_examples
444
+ success_result.should be_true
445
+ end
360
446
  end
361
447
  end
362
448
  end
@@ -21,8 +21,10 @@ module Spec
21
21
  end
22
22
 
23
23
  def create_example_group(description_text)
24
- example_group = Class.new(Spec::Example::ExampleGroup)
25
- example_group.describe description_text
24
+ example_group = Spec::Example::ExampleGroup.describe(description_text) do
25
+ it "should do something" do
26
+ end
27
+ end
26
28
  example_group
27
29
  end
28
30
 
@@ -127,8 +129,9 @@ module Spec
127
129
 
128
130
  describe Reporter, "reporting one failing example" do
129
131
  it "should tell formatter that example failed" do
132
+ example = example_group.it("should do something") {}
130
133
  formatter.should_receive(:example_failed)
131
- reporter.example_finished(example_group, RuntimeError.new)
134
+ reporter.example_finished(example, RuntimeError.new)
132
135
  end
133
136
 
134
137
  it "should delegate to backtrace tweaker" do
@@ -154,7 +157,7 @@ module Spec
154
157
  describe Reporter, "reporting one pending example (ExamplePendingError)" do
155
158
  it "should tell formatter example is pending" do
156
159
  example = ExampleGroup.new("example")
157
- formatter.should_receive(:example_pending).with(example_group.description, example, "reason")
160
+ formatter.should_receive(:example_pending).with(example, "reason")
158
161
  formatter.should_receive(:add_example_group).with(example_group)
159
162
  reporter.add_example_group(example_group)
160
163
  reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
@@ -162,7 +165,7 @@ module Spec
162
165
 
163
166
  it "should account for pending example in stats" do
164
167
  example = ExampleGroup.new("example")
165
- formatter.should_receive(:example_pending).with(example_group.description, example, "reason")
168
+ formatter.should_receive(:example_pending).with(example, "reason")
166
169
  formatter.should_receive(:start_dump)
167
170
  formatter.should_receive(:dump_pending)
168
171
  formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
@@ -177,11 +180,11 @@ module Spec
177
180
  describe Reporter, "reporting one pending example (PendingExampleFixedError)" do
178
181
  it "should tell formatter pending example is fixed" do
179
182
  formatter.should_receive(:example_failed) do |name, counter, failure|
180
- failure.header.should == "'example_group example' FIXED"
183
+ failure.header.should == "'example_group should do something' FIXED"
181
184
  end
182
185
  formatter.should_receive(:add_example_group).with(example_group)
183
186
  reporter.add_example_group(example_group)
184
- reporter.example_finished(ExampleGroup.new("example"), Spec::Example::PendingExampleFixedError.new("reason"))
187
+ reporter.example_finished(example_group.examples.first, Spec::Example::PendingExampleFixedError.new("reason"))
185
188
  end
186
189
  end
187
190
  end
@@ -0,0 +1 @@
1
+ --drb
@@ -3,9 +3,15 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  describe "SpecParser" do
4
4
  attr_reader :parser, :file
5
5
  before(:each) do
6
+ @original_rspec_options = $rspec_options
7
+ $rspec_options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
6
8
  @parser = Spec::Runner::SpecParser.new
7
9
  @file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
8
- require file
10
+ load file
11
+ end
12
+
13
+ after do
14
+ $rspec_options = @original_rspec_options
9
15
  end
10
16
 
11
17
  it "should find spec name for 'specify' at same line" do
@@ -32,9 +38,9 @@ describe "SpecParser" do
32
38
  parser.spec_name_for(file, 14).should == "d"
33
39
  end
34
40
 
35
- it "should find nearest example name between examples" do
36
- parser.spec_name_for(file, 7).should == "c 1"
37
- end
41
+ it "should find nearest example name between examples" do
42
+ parser.spec_name_for(file, 7).should == "c 1"
43
+ end
38
44
 
39
45
  it "should find nothing outside a context" do
40
46
  parser.spec_name_for(file, 2).should be_nil
@@ -22,28 +22,29 @@ module Spec
22
22
 
23
23
  it "should parse a story file" do
24
24
  runner = PlainTextStoryRunner.new("path")
25
-
26
25
  during {
27
- runner.run
26
+ runner.run(mock('runner'))
28
27
  }.expect {
29
28
  @parser.should_receive(:parse).with(["this", "and that"])
30
29
  }
31
30
  end
32
31
 
33
32
  it "should build up a mediator with its own steps and the singleton story_runner" do
33
+ @story_runner = mock('story runner', :null_object => true)
34
+
34
35
  runner = PlainTextStoryRunner.new("path")
35
- Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner"))
36
- Spec::Story::Runner::StoryMediator.should_receive(:new).with(runner.steps, story_runner, {}).
37
- and_return(mediator = stub("mediator", :run_stories => nil))
38
- runner.run
36
+
37
+ Spec::Story::Runner::StoryMediator.should_receive(:new).with(
38
+ runner.steps, @story_runner, {}
39
+ ).and_return(mediator = stub("mediator", :run_stories => nil))
40
+ runner.run(@story_runner)
39
41
  end
40
42
 
41
43
  it "should build up a parser with the mediator" do
42
44
  runner = PlainTextStoryRunner.new("path")
43
- Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner"))
44
45
  Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator = stub("mediator", :run_stories => nil))
45
46
  Spec::Story::Runner::StoryParser.should_receive(:new).with(mediator).and_return(@parser)
46
- runner.run
47
+ runner.run(stub("story_runner"))
47
48
  end
48
49
 
49
50
  it "should tell the mediator to run the stories" do
@@ -51,7 +52,7 @@ module Spec
51
52
  mediator = mock("mediator")
52
53
  Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator)
53
54
  mediator.should_receive(:run_stories)
54
- runner.run
55
+ runner.run(mock('runner'))
55
56
  end
56
57
 
57
58
  it "should accept a block instead of a path" do
@@ -59,13 +60,13 @@ module Spec
59
60
  runner.load("path/to/story")
60
61
  end
61
62
  File.should_receive(:read).with("path/to/story").and_return("this\nand that")
62
- runner.run
63
+ runner.run(mock('runner'))
63
64
  end
64
65
 
65
66
  it "should tell you if you try to run with no path set" do
66
67
  runner = PlainTextStoryRunner.new
67
68
  lambda {
68
- runner.run
69
+ runner.run(mock('runner'))
69
70
  }.should raise_error(RuntimeError, "You must set a path to the file with the story. See the RDoc.")
70
71
  end
71
72
 
@@ -74,7 +75,7 @@ module Spec
74
75
  Spec::Story::Runner::StoryMediator.should_receive(:new).
75
76
  with(anything, anything, :foo => :bar).
76
77
  and_return(mediator = stub("mediator", :run_stories => nil))
77
- runner.run
78
+ runner.run(mock('runner'))
78
79
  end
79
80
 
80
81
  it "should provide access to its options" do
@@ -83,7 +84,7 @@ module Spec
83
84
  Spec::Story::Runner::StoryMediator.should_receive(:new).
84
85
  with(anything, anything, :foo => :bar).
85
86
  and_return(mediator = stub("mediator", :run_stories => nil))
86
- runner.run
87
+ runner.run mock('runner')
87
88
  end
88
89
 
89
90
  end
@@ -70,71 +70,143 @@ module Spec
70
70
 
71
71
  # then
72
72
  end
73
-
74
- it 'should notify listeners when a scenario succeeds' do
75
- # given
76
- world = stub_everything('world')
77
- story = Story.new 'story', 'narrative' do end
78
- scenario = Scenario.new story, 'scenario1' do
79
- # succeeds
73
+ describe "when a scenario succeeds" do
74
+ before(:each) do
75
+ # given
76
+ @world = stub_everything('world')
77
+ @story = Story.new 'story', 'narrative' do end
78
+ @scenario = Scenario.new @story, 'scenario1' do
79
+ # succeeds
80
+ end
81
+ @scenario_runner = ScenarioRunner.new
80
82
  end
81
- scenario_runner = ScenarioRunner.new
82
- mock_listener1 = stub_everything('listener1')
83
- mock_listener2 = stub_everything('listener2')
84
- scenario_runner.add_listener(mock_listener1)
85
- scenario_runner.add_listener(mock_listener2)
86
83
 
87
- # expect
88
- mock_listener1.should_receive(:scenario_succeeded).with('story', 'scenario1')
89
- mock_listener2.should_receive(:scenario_succeeded).with('story', 'scenario1')
90
-
91
- # when
92
- scenario_runner.run(scenario, world)
84
+ it 'should notify listeners' do
85
+ #given
86
+ mock_listener1 = stub_everything('listener1')
87
+ mock_listener2 = stub_everything('listener2')
88
+ @scenario_runner.add_listener(mock_listener1)
89
+ @scenario_runner.add_listener(mock_listener2)
90
+
91
+ # expect
92
+ mock_listener1.should_receive(:scenario_succeeded).with('story', 'scenario1')
93
+ mock_listener2.should_receive(:scenario_succeeded).with('story', 'scenario1')
94
+
95
+ # when
96
+ @scenario_runner.run(@scenario, @world)
97
+
98
+ # then
99
+ end
93
100
 
94
- # then
101
+ it "should return true" do
102
+ #when
103
+ success = @scenario_runner.run(@scenario, @world)
104
+
105
+ #then
106
+ success.should == true
107
+ end
95
108
  end
96
-
97
- it 'should notify listeners ONCE when a scenario raises an error' do
98
- # given
99
- error = RuntimeError.new('oops')
100
- story = Story.new 'title', 'narrative' do end
101
- scenario = Scenario.new story, 'scenario1' do
109
+
110
+ describe "when a scenario raises an error (other than a pending error)" do
111
+ before(:each) do
112
+ # given
113
+ @error = RuntimeError.new('oops')
114
+ @story = Story.new 'title', 'narrative' do end
115
+ @scenario = Scenario.new @story, 'scenario1' do
116
+ end
117
+ @scenario_runner = ScenarioRunner.new
118
+ @world = stub_everything
119
+
120
+ # expect
121
+ @world.should_receive(:errors).twice.and_return([@error, @error])
102
122
  end
103
- scenario_runner = ScenarioRunner.new
104
- mock_listener = stub_everything('listener')
105
- scenario_runner.add_listener(mock_listener)
106
- world = stub_everything
107
123
 
108
- # expect
109
- world.should_receive(:errors).twice.and_return([error, error])
110
- mock_listener.should_receive(:scenario_failed).with('title', 'scenario1', error).once
124
+ it 'should notify listeners ONCE' do
125
+ #given
126
+ mock_listener = stub_everything('listener')
127
+ @scenario_runner.add_listener(mock_listener)
128
+
129
+ #expect
130
+ mock_listener.should_receive(:scenario_failed).with('title', 'scenario1', @error).once
131
+
132
+ # when
133
+ @scenario_runner.run @scenario, @world
134
+
135
+ # then
136
+ end
137
+
138
+ it "should return false" do
139
+ # when
140
+ success = @scenario_runner.run @scenario, @world
141
+
142
+ # then
143
+ success.should == false
144
+ end
111
145
 
112
- # when
113
- scenario_runner.run scenario, world
114
146
 
115
- # then
116
147
  end
117
148
 
118
- it 'should notify listeners when a scenario is pending' do
119
- # given
120
- pending_error = Spec::Example::ExamplePendingError.new('todo')
121
- story = Story.new 'title', 'narrative' do end
122
- scenario = Scenario.new story, 'scenario1' do
149
+ describe "when a scenario is pending" do
150
+ before(:each) do
151
+ # given
152
+ @pending_error = Spec::Example::ExamplePendingError.new('todo')
153
+ @story = Story.new 'title', 'narrative' do end
154
+ @scenario = Scenario.new @story, 'scenario1' do
155
+ end
156
+ @scenario_runner = ScenarioRunner.new
157
+ @world = stub_everything
158
+
159
+ # expect
160
+ @world.should_receive(:errors).twice.and_return([@pending_error, @pending_error])
123
161
  end
124
- scenario_runner = ScenarioRunner.new
125
- mock_listener = mock('listener')
126
- scenario_runner.add_listener(mock_listener)
127
- world = stub_everything
128
162
 
129
- # expect
130
- world.should_receive(:errors).twice.and_return([pending_error, pending_error])
131
- mock_listener.should_receive(:scenario_started).with('title', 'scenario1')
132
- mock_listener.should_receive(:scenario_pending).with('title', 'scenario1', 'todo').once
133
-
134
- # when
135
- scenario_runner.run scenario, world
163
+ it 'should notify listeners' do
164
+ #given
165
+ mock_listener = mock('listener')
166
+ @scenario_runner.add_listener(mock_listener)
167
+
168
+ # expect
169
+ mock_listener.should_receive(:scenario_started).with('title', 'scenario1')
170
+ mock_listener.should_receive(:scenario_pending).with('title', 'scenario1', 'todo').once
171
+
172
+ # when
173
+ @scenario_runner.run @scenario, @world
174
+
175
+ # then
176
+ end
136
177
 
137
- # then
178
+ it "should return true" do
179
+ # when
180
+ success = @scenario_runner.run @scenario, @world
181
+
182
+ # then
183
+ success.should == true
184
+ end
185
+ end
186
+
187
+ describe "when a scenario has an empty body" do
188
+ before(:each) do
189
+ @story = Story.new 'title', 'narrative' do end
190
+ @scenario = Scenario.new @story, 'scenario'
191
+ @scenario_runner = ScenarioRunner.new
192
+ @world = stub_everything
193
+ end
194
+
195
+ it "should mark the scenario as pending" do
196
+ mock_listener = stub('listener', :scenario_started => true)
197
+ @scenario_runner.add_listener mock_listener
198
+
199
+ mock_listener.should_receive(:scenario_pending).with('title', 'scenario', '')
200
+ @scenario_runner.run @scenario, @world
201
+ end
202
+
203
+ it "should return true" do
204
+ # when
205
+ success = @scenario_runner.run @scenario, @world
206
+
207
+ # then
208
+ success.should == true
209
+ end
138
210
  end
139
211
  end
140
212
  end