rspec 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/{CHANGES → History.txt} +116 -64
  2. data/Manifest.txt +403 -0
  3. data/{MIT-LICENSE → README.txt} +43 -0
  4. data/Rakefile +39 -212
  5. data/{TODO → TODO.txt} +0 -0
  6. data/bin/autospec +4 -0
  7. data/bin/spec +1 -1
  8. data/examples/pure/yielding_example.rb +33 -0
  9. data/examples/stories/game-of-life/.loadpath +5 -0
  10. data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
  11. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
  12. data/init.rb +9 -0
  13. data/lib/autotest/discover.rb +1 -1
  14. data/lib/autotest/rspec.rb +3 -29
  15. data/lib/spec.rb +10 -12
  16. data/lib/spec/adapters.rb +1 -0
  17. data/lib/spec/adapters/ruby_engine.rb +26 -0
  18. data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
  19. data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
  20. data/lib/spec/example/errors.rb +6 -0
  21. data/lib/spec/example/example_group_methods.rb +17 -14
  22. data/lib/spec/example/example_matcher.rb +2 -0
  23. data/lib/spec/example/example_methods.rb +4 -9
  24. data/lib/spec/example/module_inclusion_warnings.rb +2 -1
  25. data/lib/spec/expectations/extensions/object.rb +2 -2
  26. data/lib/spec/expectations/handler.rb +8 -16
  27. data/lib/spec/extensions/main.rb +2 -17
  28. data/lib/spec/matchers.rb +8 -2
  29. data/lib/spec/matchers/be.rb +0 -3
  30. data/lib/spec/matchers/change.rb +44 -40
  31. data/lib/spec/matchers/has.rb +1 -1
  32. data/lib/spec/matchers/have.rb +17 -12
  33. data/lib/spec/matchers/operator_matcher.rb +10 -4
  34. data/lib/spec/matchers/simple_matcher.rb +113 -10
  35. data/lib/spec/mocks.rb +1 -1
  36. data/lib/spec/mocks/argument_constraints.rb +185 -0
  37. data/lib/spec/mocks/argument_expectation.rb +35 -173
  38. data/lib/spec/mocks/framework.rb +1 -1
  39. data/lib/spec/mocks/message_expectation.rb +30 -5
  40. data/lib/spec/mocks/methods.rb +14 -2
  41. data/lib/spec/mocks/mock.rb +4 -0
  42. data/lib/spec/mocks/proxy.rb +46 -5
  43. data/lib/spec/mocks/spec_methods.rb +9 -1
  44. data/lib/spec/rake/spectask.rb +14 -22
  45. data/lib/spec/rake/verify_rcov.rb +3 -3
  46. data/lib/spec/runner.rb +18 -6
  47. data/lib/spec/runner/backtrace_tweaker.rb +6 -7
  48. data/lib/spec/runner/command_line.rb +6 -17
  49. data/lib/spec/runner/drb_command_line.rb +1 -1
  50. data/lib/spec/runner/formatter/base_formatter.rb +3 -1
  51. data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
  52. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  53. data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
  54. data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
  55. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  56. data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
  57. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
  58. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
  59. data/lib/spec/runner/heckle_runner.rb +2 -2
  60. data/lib/spec/runner/option_parser.rb +2 -1
  61. data/lib/spec/runner/options.rb +18 -9
  62. data/lib/spec/runner/reporter.rb +24 -4
  63. data/lib/spec/runner/spec_parser.rb +1 -1
  64. data/lib/spec/story/runner.rb +1 -2
  65. data/lib/spec/story/runner/story_mediator.rb +14 -0
  66. data/lib/spec/story/runner/story_parser.rb +20 -0
  67. data/lib/spec/story/step.rb +40 -28
  68. data/lib/spec/story/step_mother.rb +2 -1
  69. data/lib/spec/story/world.rb +6 -2
  70. data/lib/spec/version.rb +13 -22
  71. data/rake_tasks/failing_examples_with_html.rake +1 -1
  72. data/rake_tasks/verify_rcov.rake +2 -2
  73. data/rspec.gemspec +33 -0
  74. data/spec/autotest/rspec_spec.rb +90 -141
  75. data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
  76. data/spec/spec/example/base_formatter_spec.rb +112 -0
  77. data/spec/spec/example/example_group_factory_spec.rb +2 -2
  78. data/spec/spec/example/example_group_methods_spec.rb +55 -4
  79. data/spec/spec/example/example_group_spec.rb +4 -3
  80. data/spec/spec/example/example_methods_spec.rb +18 -14
  81. data/spec/spec/example/pending_module_spec.rb +38 -0
  82. data/spec/spec/example/shared_example_group_spec.rb +1 -1
  83. data/spec/spec/expectations/extensions/object_spec.rb +0 -12
  84. data/spec/spec/extensions/main_spec.rb +3 -8
  85. data/spec/spec/matchers/change_spec.rb +16 -6
  86. data/spec/spec/matchers/handler_spec.rb +58 -37
  87. data/spec/spec/matchers/has_spec.rb +10 -0
  88. data/spec/spec/matchers/have_spec.rb +105 -2
  89. data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
  90. data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
  91. data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
  92. data/spec/spec/mocks/bug_report_496.rb +17 -0
  93. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
  94. data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
  95. data/spec/spec/mocks/mock_spec.rb +55 -10
  96. data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
  97. data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
  98. data/spec/spec/mocks/options_hash_spec.rb +18 -28
  99. data/spec/spec/mocks/partial_mock_spec.rb +2 -0
  100. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
  101. data/spec/spec/mocks/stub_spec.rb +7 -0
  102. data/spec/spec/runner/command_line_spec.rb +5 -12
  103. data/spec/spec/runner/drb_command_line_spec.rb +13 -6
  104. data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
  105. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
  106. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
  107. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
  108. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
  109. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
  110. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
  111. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
  112. data/spec/spec/runner/heckle_runner_spec.rb +8 -8
  113. data/spec/spec/runner/option_parser_spec.rb +21 -6
  114. data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
  115. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
  116. data/spec/spec/runner/reporter_spec.rb +51 -5
  117. data/spec/spec/runner/spec_parser_spec.rb +4 -4
  118. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
  119. data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
  120. data/spec/spec/story/runner/story_parser_spec.rb +23 -6
  121. data/spec/spec/story/scenario_spec.rb +1 -3
  122. data/spec/spec/story/step_mother_spec.rb +12 -0
  123. data/spec/spec/story/step_spec.rb +57 -4
  124. data/spec/spec/story/story_spec.rb +1 -3
  125. data/spec/spec/story/world_spec.rb +1 -1
  126. data/spec/spec_helper.rb +21 -68
  127. data/stories/all.rb +1 -1
  128. data/stories/configuration/before_blocks.story +21 -0
  129. data/stories/configuration/stories.rb +7 -0
  130. data/stories/example_groups/stories.rb +3 -4
  131. data/stories/resources/spec/before_blocks_example.rb +32 -0
  132. data/stories/stories/multiline_steps.story +23 -0
  133. data/stories/stories/steps/multiline_steps.rb +13 -0
  134. data/stories/stories/stories.rb +6 -0
  135. data/story_server/prototype/javascripts/builder.js +136 -0
  136. data/story_server/prototype/javascripts/controls.js +972 -0
  137. data/story_server/prototype/javascripts/dragdrop.js +976 -0
  138. data/story_server/prototype/javascripts/effects.js +1117 -0
  139. data/story_server/prototype/javascripts/prototype.js +4140 -0
  140. data/story_server/prototype/javascripts/rspec.js +149 -0
  141. data/story_server/prototype/javascripts/scriptaculous.js +58 -0
  142. data/story_server/prototype/javascripts/slider.js +276 -0
  143. data/story_server/prototype/javascripts/sound.js +55 -0
  144. data/story_server/prototype/javascripts/unittest.js +568 -0
  145. data/story_server/prototype/lib/server.rb +24 -0
  146. data/story_server/prototype/stories.html +176 -0
  147. data/story_server/prototype/stylesheets/rspec.css +136 -0
  148. data/story_server/prototype/stylesheets/test.css +90 -0
  149. metadata +166 -166
  150. data/README +0 -36
  151. data/UPGRADE +0 -7
  152. data/bin/spec_translator +0 -8
  153. data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
  154. data/lib/spec/translator.rb +0 -114
  155. data/spec/spec/example/example_spec.rb +0 -53
  156. data/spec/spec/runner/execution_context_spec.rb +0 -37
  157. data/spec/spec/translator_spec.rb +0 -265
@@ -6,6 +6,7 @@ module Spec
6
6
  module Runner
7
7
  module Formatter
8
8
  describe HtmlFormatter do
9
+ include SandboxedOptions
9
10
  ['--diff', '--dry-run'].each do |opt|
10
11
  def jruby?
11
12
  PLATFORM == 'java'
@@ -22,7 +23,7 @@ module Spec
22
23
  args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'html', opt]
23
24
  err = StringIO.new
24
25
  out = StringIO.new
25
- CommandLine.run(
26
+ run_with(
26
27
  OptionParser.parse(args, err, out)
27
28
  )
28
29
 
@@ -5,7 +5,7 @@ module Spec
5
5
  module Runner
6
6
  module Formatter
7
7
  describe NestedTextFormatter do
8
- it_should_behave_like "sandboxed rspec_options"
8
+ include SandboxedOptions
9
9
  attr_reader :io, :options, :formatter, :example_group
10
10
  before(:each) do
11
11
  @io = StringIO.new
@@ -304,7 +304,7 @@ module Spec
304
304
 
305
305
  describe "#example_pending" do
306
306
  it "should push pending example name and message" do
307
- formatter.example_pending(example_group.examples.first, 'reason')
307
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
308
308
  expected_output = <<-OUT
309
309
  ExampleGroup
310
310
  example (PENDING: reason)
@@ -313,7 +313,7 @@ module Spec
313
313
  end
314
314
 
315
315
  it "should dump pending" do
316
- formatter.example_pending(example_group.examples.first, 'reason')
316
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
317
317
  io.rewind
318
318
  formatter.dump_pending
319
319
  io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
@@ -29,7 +29,7 @@ module Spec
29
29
  end
30
30
  end
31
31
  example = example_group.examples.first
32
- @formatter.example_pending(example, "message")
32
+ @formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
33
33
  @io.rewind
34
34
  @formatter.dump_summary(3, 2, 1, 1)
35
35
  @io.string.should eql(%Q|
@@ -94,10 +94,28 @@ EOE
94
94
  end
95
95
  end
96
96
  example = example_group.examples.first
97
- @formatter.example_pending(example, "message")
97
+ @formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
98
98
  @formatter.dump_pending
99
99
  @io.string.should =~ /Pending\:\nexample_group example \(message\)\n/
100
100
  end
101
+
102
+ it "should dump pending with file and line number" do
103
+ example_group = ExampleGroup.describe("example_group") do
104
+ specify "example" do
105
+ end
106
+ end
107
+ example = example_group.examples.first
108
+ file = __FILE__
109
+ line = __LINE__ + 1
110
+ @formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
111
+ @formatter.dump_pending
112
+ @io.string.should ==(<<-HERE)
113
+ *
114
+ Pending:
115
+ example_group example (message)
116
+ Called from #{file}:#{line}
117
+ HERE
118
+ end
101
119
  end
102
120
 
103
121
  describe "ProgressBarFormatter outputting to custom out" do
@@ -6,6 +6,7 @@ module Spec
6
6
  module Runner
7
7
  module Formatter
8
8
  describe TextMateFormatter do
9
+ include SandboxedOptions
9
10
  attr_reader :root, :suffix, :expected_file
10
11
  before do
11
12
  @root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
@@ -33,7 +34,7 @@ module Spec
33
34
  err = StringIO.new
34
35
  out = StringIO.new
35
36
  options = ::Spec::Runner::OptionParser.parse(args, err, out)
36
- Spec::Runner::CommandLine.run(options)
37
+ run_with(options)
37
38
 
38
39
  yield(out.string)
39
40
  end
@@ -5,7 +5,7 @@ module Spec
5
5
  module Runner
6
6
  module Formatter
7
7
  describe SpecdocFormatter do
8
- it_should_behave_like "sandboxed rspec_options"
8
+ include SandboxedOptions
9
9
  attr_reader :io, :options, :formatter, :example_group
10
10
  before(:each) do
11
11
  @io = StringIO.new
@@ -133,12 +133,12 @@ module Spec
133
133
 
134
134
  describe "#example_pending" do
135
135
  it "should push pending example name and message" do
136
- formatter.example_pending(example_group.examples.first, 'reason')
136
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
137
137
  io.string.should have_example_group_output("- example (PENDING: reason)\n")
138
138
  end
139
139
 
140
140
  it "should dump pending" do
141
- formatter.example_pending(example_group.examples.first, 'reason')
141
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
142
142
  io.rewind
143
143
  formatter.dump_pending
144
144
  io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
@@ -37,12 +37,18 @@ module Spec
37
37
 
38
38
  it "should create spans for params" do
39
39
  @reporter.step_succeeded('given', 'a $coloured $animal', 'brown', 'dog')
40
- @out.string.should == " <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n"
40
+ @reporter.scenario_ended
41
+ @reporter.story_ended('story_title', 'narrative')
42
+
43
+ @out.string.should include(" <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n")
41
44
  end
42
45
 
43
46
  it 'should create spanes for params in regexp steps' do
44
47
  @reporter.step_succeeded :given, /a (pink|blue) (.*)/, 'brown', 'dog'
45
- @out.string.should == " <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n"
48
+ @reporter.scenario_ended
49
+ @reporter.story_ended('story_title', 'narrative')
50
+
51
+ @out.string.should include(" <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n")
46
52
  end
47
53
 
48
54
  it "should create a ul for collected_steps" do
@@ -54,6 +60,74 @@ module Spec
54
60
  </ul>
55
61
  EOF
56
62
  end
63
+
64
+ it 'should document additional givens using And' do
65
+ # when
66
+ @reporter.step_succeeded :given, 'step 1'
67
+ @reporter.step_succeeded :given, 'step 2'
68
+ @reporter.scenario_ended
69
+ @reporter.story_ended '', ''
70
+
71
+ # then
72
+ @out.string.should include("Given step 1")
73
+ @out.string.should include("And step 2")
74
+ end
75
+
76
+ it 'should document additional events using And' do
77
+ # when
78
+ @reporter.step_succeeded :when, 'step 1'
79
+ @reporter.step_succeeded :when, 'step 2'
80
+ @reporter.scenario_ended
81
+ @reporter.story_ended '', ''
82
+
83
+ # then
84
+ @out.string.should include("When step 1")
85
+ @out.string.should include("And step 2")
86
+ end
87
+
88
+ it 'should document additional outcomes using And' do
89
+ # when
90
+ @reporter.step_succeeded :then, 'step 1'
91
+ @reporter.step_succeeded :then, 'step 2'
92
+ @reporter.scenario_ended
93
+ @reporter.story_ended '', ''
94
+
95
+ # then
96
+ @out.string.should include("Then step 1")
97
+ @out.string.should include("And step 2")
98
+ end
99
+
100
+ it 'should document a GivenScenario followed by a Given using And' do
101
+ # when
102
+ @reporter.step_succeeded :'given scenario', 'a scenario'
103
+ @reporter.step_succeeded :given, 'a context'
104
+ @reporter.scenario_ended
105
+ @reporter.story_ended '', ''
106
+
107
+ # then
108
+ @out.string.should include("Given scenario a scenario")
109
+ @out.string.should include("And a context")
110
+ end
111
+
112
+ it "should create a failed story if one of its scenarios fails" do
113
+ @reporter.story_started('story_title', 'narrative')
114
+ @reporter.scenario_started('story_title', 'succeeded_scenario_name')
115
+ @reporter.step_failed('then', 'failed_step', 'en', 'to')
116
+ @reporter.scenario_failed('story_title', 'failed_scenario_name', NameError.new('sup'))
117
+ @reporter.story_ended('story_title', 'narrative')
118
+
119
+ @out.string.should include(" <dl class=\"story failed\">\n <dt>Story: story_title</dt>\n")
120
+ end
121
+
122
+ it "should create a failed scenario if one of its steps fails" do
123
+ @reporter.scenario_started('story_title', 'failed_scenario_name')
124
+ @reporter.step_failed('then', 'failed_step', 'en', 'to')
125
+ @reporter.scenario_failed('story_title', 'failed_scenario_name', NameError.new('sup'))
126
+ @reporter.story_ended('story_title', 'narrative')
127
+
128
+ @out.string.should include("<dl class=\"failed\">\n <dt>Scenario: failed_scenario_name</dt>\n")
129
+ end
130
+
57
131
  end
58
132
  end
59
133
  end
@@ -159,6 +159,45 @@ module Spec
159
159
  @out.string.should include("3 scenarios: 1 succeeded, 1 failed, 1 pending")
160
160
  end
161
161
 
162
+ it 'should show test summary in red if there were failed scenarios' do
163
+ # when
164
+ @out.stub!(:tty?).and_return(true)
165
+ @options.stub!(:colour).and_return(true)
166
+
167
+ @formatter.scenario_started(nil, nil)
168
+ @formatter.scenario_failed('story', 'scenario', exception_from { raise RuntimeError, 'oops' })
169
+ @formatter.run_ended
170
+
171
+ # then
172
+ @out.string.should include("\e[31m scenarios: 0 succeeded, 1 failed, 0 pending\e[0m")
173
+ end
174
+
175
+ it 'should show test summary in yellow if there are pending scenarios' do
176
+ # when
177
+ @out.stub!(:tty?).and_return(true)
178
+ @options.stub!(:colour).and_return(true)
179
+
180
+ @formatter.scenario_started(nil, nil)
181
+ @formatter.scenario_pending('story', 'scenario', '')
182
+ @formatter.run_ended
183
+
184
+ # then
185
+ @out.string.should include("\e[32m scenarios: 0 succeeded, 0 failed, 1 pending\e[0m")
186
+ end
187
+
188
+ it 'should show test summary in green if all scenarios pass' do
189
+ # when
190
+ @out.stub!(:tty?).and_return(true)
191
+ @options.stub!(:colour).and_return(true)
192
+
193
+ @formatter.scenario_started(nil, nil)
194
+ @formatter.scenario_succeeded('story', 'scenario')
195
+ @formatter.run_ended
196
+
197
+ # then
198
+ @out.string.should include("\e[32m scenarios: 1 succeeded, 0 failed, 0 pending\e[0m")
199
+ end
200
+
162
201
  it 'should produce details of the first failure each failed scenario when the run ends' do
163
202
  # when
164
203
  @formatter.run_started(3)
@@ -180,6 +219,19 @@ module Spec
180
219
  @out.string.should include("RuntimeError: oops3")
181
220
  end
182
221
 
222
+ it 'should produce details of the failures in red when the run ends' do
223
+ # when
224
+ @out.stub!(:tty?).and_return(true)
225
+ @options.stub!(:colour).and_return(true)
226
+ @formatter.scenario_started(nil, nil)
227
+ @formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
228
+ @formatter.run_ended
229
+
230
+ # then
231
+ @out.string.should =~ /\e\[31m[\n\s]*story \(scenario1\) FAILED\e\[0m/m
232
+ @out.string.should =~ /\e\[31m[\n\s]*RuntimeError: oops1\e\[0m/m
233
+ end
234
+
183
235
  it 'should produce details of each pending step when the run ends' do
184
236
  # when
185
237
  @formatter.run_started(2)
@@ -200,6 +252,7 @@ module Spec
200
252
  it 'should document a story title and narrative' do
201
253
  # when
202
254
  @formatter.story_started 'story', 'narrative'
255
+ @formatter.story_ended 'story', 'narrative'
203
256
 
204
257
  # then
205
258
  @out.string.should include("Story: story\n\n narrative")
@@ -208,6 +261,8 @@ module Spec
208
261
  it 'should document a scenario name' do
209
262
  # when
210
263
  @formatter.scenario_started 'story', 'scenario'
264
+ @formatter.scenario_ended
265
+ @formatter.story_ended '', ''
211
266
 
212
267
  # then
213
268
  @out.string.should include("\n\n Scenario: scenario")
@@ -218,6 +273,8 @@ module Spec
218
273
  @formatter.step_succeeded :given, 'a context'
219
274
  @formatter.step_succeeded :when, 'an event'
220
275
  @formatter.step_succeeded :then, 'an outcome'
276
+ @formatter.scenario_ended
277
+ @formatter.story_ended '', ''
221
278
 
222
279
  # then
223
280
  @out.string.should include("\n\n Given a context\n\n When an event\n\n Then an outcome")
@@ -228,6 +285,8 @@ module Spec
228
285
  @formatter.step_succeeded :given, 'step 1'
229
286
  @formatter.step_succeeded :given, 'step 2'
230
287
  @formatter.step_succeeded :given, 'step 3'
288
+ @formatter.scenario_ended
289
+ @formatter.story_ended '', ''
231
290
 
232
291
  # then
233
292
  @out.string.should include(" Given step 1\n And step 2\n And step 3")
@@ -238,6 +297,8 @@ module Spec
238
297
  @formatter.step_succeeded :when, 'step 1'
239
298
  @formatter.step_succeeded :when, 'step 2'
240
299
  @formatter.step_succeeded :when, 'step 3'
300
+ @formatter.scenario_ended
301
+ @formatter.story_ended '', ''
241
302
 
242
303
  # then
243
304
  @out.string.should include(" When step 1\n And step 2\n And step 3")
@@ -248,6 +309,8 @@ module Spec
248
309
  @formatter.step_succeeded :then, 'step 1'
249
310
  @formatter.step_succeeded :then, 'step 2'
250
311
  @formatter.step_succeeded :then, 'step 3'
312
+ @formatter.scenario_ended
313
+ @formatter.story_ended '', ''
251
314
 
252
315
  # then
253
316
  @out.string.should include(" Then step 1\n And step 2\n And step 3")
@@ -257,6 +320,8 @@ module Spec
257
320
  # when
258
321
  @formatter.step_succeeded :'given scenario', 'a scenario'
259
322
  @formatter.step_succeeded :given, 'a context'
323
+ @formatter.scenario_ended
324
+ @formatter.story_ended '', ''
260
325
 
261
326
  # then
262
327
  @out.string.should include(" Given scenario a scenario\n And a context")
@@ -264,27 +329,39 @@ module Spec
264
329
 
265
330
  it 'should document steps with replaced params' do
266
331
  @formatter.step_succeeded :given, 'a $coloured dog with $n legs', 'pink', 21
332
+ @formatter.scenario_ended
333
+ @formatter.story_ended '', ''
267
334
  @out.string.should include(" Given a pink dog with 21 legs")
268
335
  end
269
336
 
270
337
  it 'should document steps that include dollar signs ($)' do
271
338
  @formatter.step_succeeded :given, 'kicks that cost $$amount', 50
339
+ @formatter.scenario_ended
340
+ @formatter.story_ended '', ''
272
341
  @out.string.should include("Given kicks that cost $50")
273
342
  end
274
343
 
275
344
  it 'should document regexp steps with replaced params' do
276
345
  @formatter.step_succeeded :given, /a (pink|blue) dog with (.*) legs/, 'pink', 21
346
+ @formatter.scenario_ended
347
+ @formatter.story_ended '', ''
277
348
  @out.string.should include(" Given a pink dog with 21 legs")
278
349
  end
279
350
 
280
351
  it 'should document regex steps that include dollar signs ($)' do
281
352
  @formatter.step_succeeded :given, /kicks that cost \$(\d+)/, 50
353
+ @formatter.scenario_ended
354
+ @formatter.story_ended '', ''
282
355
  @out.string.should include("Given kicks that cost $50")
283
356
  end
284
357
 
285
358
  it "should append PENDING for the first pending step" do
286
359
  @formatter.scenario_started('','')
360
+ @formatter.scenario_ended
361
+ @formatter.story_ended '', ''
287
362
  @formatter.step_pending(:given, 'a context')
363
+ @formatter.scenario_ended
364
+ @formatter.story_ended '', ''
288
365
 
289
366
  @out.string.should include('Given a context (PENDING)')
290
367
  end
@@ -293,6 +370,8 @@ module Spec
293
370
  @formatter.scenario_started('','')
294
371
  @formatter.step_pending(:given, 'a context')
295
372
  @formatter.step_pending(:when, 'I say hey')
373
+ @formatter.scenario_ended
374
+ @formatter.story_ended '', ''
296
375
 
297
376
  @out.string.should include('When I say hey (PENDING)')
298
377
  end
@@ -300,6 +379,8 @@ module Spec
300
379
  it "should append FAILED for the first failiure" do
301
380
  @formatter.scenario_started('','')
302
381
  @formatter.step_failed(:given, 'a context')
382
+ @formatter.scenario_ended
383
+ @formatter.story_ended '', ''
303
384
 
304
385
  @out.string.should include('Given a context (FAILED)')
305
386
  end
@@ -308,6 +389,8 @@ module Spec
308
389
  @formatter.scenario_started('','')
309
390
  @formatter.step_failed(:given, 'a context')
310
391
  @formatter.step_failed(:when, 'I say hey')
392
+ @formatter.scenario_ended
393
+ @formatter.story_ended '', ''
311
394
 
312
395
  @out.string.should include('When I say hey (SKIPPED)')
313
396
  end
@@ -316,6 +399,8 @@ module Spec
316
399
  @formatter.scenario_started('','')
317
400
  @formatter.step_pending(:given, 'a context')
318
401
  @formatter.step_failed(:when, 'I say hey')
402
+ @formatter.scenario_ended
403
+ @formatter.story_ended '', ''
319
404
 
320
405
  @out.string.should include('When I say hey (SKIPPED)')
321
406
  end
@@ -326,6 +411,8 @@ module Spec
326
411
 
327
412
  @formatter.scenario_started('','')
328
413
  @formatter.step_succeeded(:given, 'a context')
414
+ @formatter.scenario_ended
415
+ @formatter.story_ended '', ''
329
416
 
330
417
  @out.string.should =~ /\e\[32m[\n\s]+Given a context\e\[0m/m
331
418
  end
@@ -336,6 +423,8 @@ module Spec
336
423
 
337
424
  @formatter.scenario_started('','')
338
425
  @formatter.step_failed(:given, 'a context')
426
+ @formatter.scenario_ended
427
+ @formatter.story_ended '', ''
339
428
 
340
429
  @out.string.should =~ /\e\[31m[\n\s]+Given a context\e\[0m/m
341
430
  end
@@ -346,6 +435,8 @@ module Spec
346
435
 
347
436
  @formatter.scenario_started('','')
348
437
  @formatter.step_failed(:given, 'a context')
438
+ @formatter.scenario_ended
439
+ @formatter.story_ended '', ''
349
440
 
350
441
  @out.string.should =~ /\e\[31m \(FAILED\)\e\[0m/
351
442
  end
@@ -356,6 +447,8 @@ module Spec
356
447
 
357
448
  @formatter.scenario_started('','')
358
449
  @formatter.step_pending(:given, 'a context')
450
+ @formatter.scenario_ended
451
+ @formatter.story_ended '', ''
359
452
 
360
453
  @out.string.should =~ /\e\[33m[\n\s]+Given a context\e\[0m/m
361
454
  end
@@ -366,10 +459,70 @@ module Spec
366
459
 
367
460
  @formatter.scenario_started('','')
368
461
  @formatter.step_pending(:given, 'a context')
462
+ @formatter.scenario_ended
463
+ @formatter.story_ended '', ''
369
464
 
370
465
  @out.string.should =~ /\e\[33m \(PENDING\)\e\[0m/
371
466
  end
372
467
 
468
+ it "should print a scenario in red if any of its steps fail" do
469
+ @out.stub!(:tty?).and_return(true)
470
+ @options.stub!(:colour).and_return(true)
471
+
472
+ @formatter.scenario_started('title','narrative')
473
+ @formatter.step_failed(:given, 'a context')
474
+ @formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
475
+ @formatter.story_ended('title','narrative')
476
+ @out.string.should include("\e[31m\n\n Scenario: narrative\e[0m")
477
+ end
478
+
479
+ it "should print a scenario in yellow if its steps are pending" do
480
+ @out.stub!(:tty?).and_return(true)
481
+ @options.stub!(:colour).and_return(true)
482
+
483
+ @formatter.scenario_started('title','narrative')
484
+ @formatter.step_pending(:given, 'a context')
485
+ @formatter.scenario_ended
486
+ @formatter.story_ended('','')
487
+ @out.string.should include("\e[33m\n\n Scenario: narrative\e[0m")
488
+ end
489
+
490
+ it "should print a story in red if any of its scenarios fail" do
491
+ @out.stub!(:tty?).and_return(true)
492
+ @options.stub!(:colour).and_return(true)
493
+
494
+ @formatter.story_started('story', 'narrative')
495
+ @formatter.scenario_started('','')
496
+ @formatter.step_failed(:given, 'a context')
497
+ @formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
498
+ @formatter.story_ended('story', 'narrative')
499
+ @out.string.should include("\e[31mStory: story\n\n narrative\e[0m")
500
+ end
501
+
502
+ it "should print a story in green if all its scenarios succeed" do
503
+ @out.stub!(:tty?).and_return(true)
504
+ @options.stub!(:colour).and_return(true)
505
+
506
+ @formatter.story_started('story', 'narrative')
507
+ @formatter.scenario_started('','')
508
+ @formatter.step_succeeded(:given, 'a context')
509
+ @formatter.scenario_succeeded('story', 'scenario1')
510
+ @formatter.story_ended('story', 'narrative')
511
+ @out.string.should include("\e[32mStory: story\n\n narrative\e[0m")
512
+ end
513
+
514
+ it "should print a story in yellow if all its scenarios are pending" do
515
+ @out.stub!(:tty?).and_return(true)
516
+ @options.stub!(:colour).and_return(true)
517
+
518
+ @formatter.story_started('story', 'narrative')
519
+ @formatter.scenario_started('','')
520
+ @formatter.step_pending(:given, 'a context')
521
+ @formatter.scenario_pending('story', 'scenario1','pending')
522
+ @formatter.story_ended('story', 'narrative')
523
+ @out.string.should include("\e[33mStory: story\n\n narrative\e[0m")
524
+ end
525
+
373
526
  it "should print skipped steps in yellow if the scenario is already pending" do
374
527
  @out.stub!(:tty?).and_return(true)
375
528
  @options.stub!(:colour).and_return(true)
@@ -377,6 +530,8 @@ module Spec
377
530
  @formatter.scenario_started('','')
378
531
  @formatter.step_pending(:given, 'a context')
379
532
  @formatter.step_failed(:when, 'I say hey')
533
+ @formatter.scenario_ended
534
+ @formatter.story_ended '', ''
380
535
 
381
536
  @out.string.should =~ /\e\[33m[\n\s]+When I say hey\e\[0m/m
382
537
  end
@@ -388,6 +543,8 @@ module Spec
388
543
  @formatter.scenario_started('','')
389
544
  @formatter.step_pending(:given, 'a context')
390
545
  @formatter.step_failed(:when, 'I say hey')
546
+ @formatter.scenario_ended
547
+ @formatter.story_ended '', ''
391
548
 
392
549
  @out.string.should =~ /\e\[33m \(SKIPPED\)\e\[0m/
393
550
  end
@@ -399,6 +556,8 @@ module Spec
399
556
  @formatter.scenario_started('','')
400
557
  @formatter.step_failed(:given, 'a context')
401
558
  @formatter.step_failed(:when, 'I say hey')
559
+ @formatter.scenario_ended
560
+ @formatter.story_ended '', ''
402
561
 
403
562
  @out.string.should =~ /\e\[31m[\n\s]+When I say hey\e\[0m/m
404
563
  end
@@ -410,6 +569,8 @@ module Spec
410
569
  @formatter.scenario_started('','')
411
570
  @formatter.step_failed(:given, 'a context')
412
571
  @formatter.step_failed(:when, 'I say hey')
572
+ @formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
573
+ @formatter.story_ended('','')
413
574
 
414
575
  @out.string.should =~ /\e\[31m \(SKIPPED\)\e\[0m/m
415
576
  end