changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../../spec_helper.rb'
2require 'spec/runner/formatter/story/plain_text_formatter'
3
4module Spec
5 module Runner
6 module Formatter
7 module Story
8 describe PlainTextFormatter do
9 before :each do
10 # given
11 @out = StringIO.new
12 @tweaker = mock('tweaker')
13 @tweaker.stub!(:tweak_backtrace)
14 @options = mock('options')
15 @options.stub!(:colour).and_return(false)
16 @options.stub!(:backtrace_tweaker).and_return(@tweaker)
17 @formatter = PlainTextFormatter.new(@options, @out)
18 end
19
20 it 'should summarize the number of scenarios when the run ends' do
21 # when
22 @formatter.run_started(3)
23 @formatter.scenario_started(nil, nil)
24 @formatter.scenario_succeeded('story', 'scenario1')
25 @formatter.scenario_started(nil, nil)
26 @formatter.scenario_succeeded('story', 'scenario2')
27 @formatter.scenario_started(nil, nil)
28 @formatter.scenario_succeeded('story', 'scenario3')
29 @formatter.run_ended
30
31 # then
32 @out.string.should include('3 scenarios')
33 end
34
35 it 'should summarize the number of successful scenarios when the run ends' do
36 # when
37 @formatter.run_started(3)
38 @formatter.scenario_started(nil, nil)
39 @formatter.scenario_succeeded('story', 'scenario1')
40 @formatter.scenario_started(nil, nil)
41 @formatter.scenario_succeeded('story', 'scenario2')
42 @formatter.scenario_started(nil, nil)
43 @formatter.scenario_succeeded('story', 'scenario3')
44 @formatter.run_ended
45
46 # then
47 @out.string.should include('3 scenarios: 3 succeeded')
48 end
49
50 it 'should summarize the number of failed scenarios when the run ends' do
51 # when
52 @formatter.run_started(3)
53 @formatter.scenario_started(nil, nil)
54 @formatter.scenario_succeeded('story', 'scenario1')
55 @formatter.scenario_started(nil, nil)
56 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
57 @formatter.scenario_started(nil, nil)
58 @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
59 @formatter.run_ended
60
61 # then
62 @out.string.should include("3 scenarios: 1 succeeded, 2 failed")
63 end
64
65 it 'should end cleanly (no characters on the last line) with successes' do
66 # when
67 @formatter.run_started(1)
68 @formatter.scenario_started(nil, nil)
69 @formatter.scenario_succeeded('story', 'scenario')
70 @formatter.run_ended
71
72 # then
73 @out.string.should =~ /\n\z/
74 end
75
76 it 'should end cleanly (no characters on the last line) with failures' do
77 # when
78 @formatter.run_started(1)
79 @formatter.scenario_started(nil, nil)
80 @formatter.scenario_failed('story', 'scenario', exception_from { raise RuntimeError, 'oops' })
81 @formatter.run_ended
82
83 # then
84 @out.string.should =~ /\n\z/
85 end
86
87 it 'should end cleanly (no characters on the last line) with pending steps' do
88 # when
89 @formatter.run_started(1)
90 @formatter.scenario_started(nil, nil)
91 @formatter.step_pending(:then, 'do pend')
92 @formatter.scenario_pending('story', 'scenario', exception_from { raise RuntimeError, 'oops' })
93 @formatter.run_ended
94
95 # then
96 @out.string.should =~ /\n\z/
97 end
98
99 it 'should summarize the number of pending scenarios when the run ends' do
100 # when
101 @formatter.run_started(3)
102 @formatter.scenario_started(nil, nil)
103 @formatter.scenario_succeeded('story', 'scenario1')
104 @formatter.scenario_started(nil, nil)
105 @formatter.scenario_pending('story', 'scenario2', 'message')
106 @formatter.scenario_started(nil, nil)
107 @formatter.scenario_pending('story', 'scenario3', 'message')
108 @formatter.run_ended
109
110 # then
111 @out.string.should include("3 scenarios: 1 succeeded, 0 failed, 2 pending")
112 end
113
114 it "should only count the first failure in one scenario" do
115 # when
116 @formatter.run_started(3)
117 @formatter.scenario_started(nil, nil)
118 @formatter.scenario_succeeded('story', 'scenario1')
119 @formatter.scenario_started(nil, nil)
120 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
121 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' })
122 @formatter.scenario_started(nil, nil)
123 @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
124 @formatter.run_ended
125
126 # then
127 @out.string.should include("3 scenarios: 1 succeeded, 2 failed")
128 end
129
130 it "should only count the first pending in one scenario" do
131 # when
132 @formatter.run_started(3)
133 @formatter.scenario_started(nil, nil)
134 @formatter.scenario_succeeded('story', 'scenario1')
135 @formatter.scenario_started(nil, nil)
136 @formatter.scenario_pending('story', 'scenario2', 'because ...')
137 @formatter.scenario_pending('story', 'scenario2', 'because ...')
138 @formatter.scenario_started(nil, nil)
139 @formatter.scenario_pending('story', 'scenario3', 'because ...')
140 @formatter.run_ended
141
142 # then
143 @out.string.should include("3 scenarios: 1 succeeded, 0 failed, 2 pending")
144 end
145
146 it "should only count a failure before the first pending in one scenario" do
147 # when
148 @formatter.run_started(3)
149 @formatter.scenario_started(nil, nil)
150 @formatter.scenario_succeeded('story', 'scenario1')
151 @formatter.scenario_started(nil, nil)
152 @formatter.scenario_pending('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
153 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' })
154 @formatter.scenario_started(nil, nil)
155 @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
156 @formatter.run_ended
157
158 # then
159 @out.string.should include("3 scenarios: 1 succeeded, 1 failed, 1 pending")
160 end
161
162 it 'should produce details of the first failure each failed scenario when the run ends' do
163 # when
164 @formatter.run_started(3)
165 @formatter.scenario_started(nil, nil)
166 @formatter.scenario_succeeded('story', 'scenario1')
167 @formatter.scenario_started(nil, nil)
168 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2' })
169 @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2 - this one should not appear' })
170 @formatter.scenario_started(nil, nil)
171 @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops3' })
172 @formatter.run_ended
173
174 # then
175 @out.string.should include("FAILURES:\n")
176 @out.string.should include("1) story (scenario2) FAILED")
177 @out.string.should include("RuntimeError: oops2")
178 @out.string.should_not include("RuntimeError: oops2 - this one should not appear")
179 @out.string.should include("2) story (scenario3) FAILED")
180 @out.string.should include("RuntimeError: oops3")
181 end
182
183 it 'should produce details of each pending step when the run ends' do
184 # when
185 @formatter.run_started(2)
186 @formatter.story_started('story 1', 'narrative')
187 @formatter.scenario_started('story 1', 'scenario 1')
188 @formatter.step_pending(:given, 'todo 1', [])
189 @formatter.story_started('story 2', 'narrative')
190 @formatter.scenario_started('story 2', 'scenario 2')
191 @formatter.step_pending(:given, 'todo 2', [])
192 @formatter.run_ended
193
194 # then
195 @out.string.should include("Pending Steps:\n")
196 @out.string.should include("1) story 1 (scenario 1): todo 1")
197 @out.string.should include("2) story 2 (scenario 2): todo 2")
198 end
199
200 it 'should document a story title and narrative' do
201 # when
202 @formatter.story_started 'story', 'narrative'
203
204 # then
205 @out.string.should include("Story: story\n\n narrative")
206 end
207
208 it 'should document a scenario name' do
209 # when
210 @formatter.scenario_started 'story', 'scenario'
211
212 # then
213 @out.string.should include("\n\n Scenario: scenario")
214 end
215
216 it 'should document a step by sentence-casing its name' do
217 # when
218 @formatter.step_succeeded :given, 'a context'
219 @formatter.step_succeeded :when, 'an event'
220 @formatter.step_succeeded :then, 'an outcome'
221
222 # then
223 @out.string.should include("\n\n Given a context\n\n When an event\n\n Then an outcome")
224 end
225
226 it 'should document additional givens using And' do
227 # when
228 @formatter.step_succeeded :given, 'step 1'
229 @formatter.step_succeeded :given, 'step 2'
230 @formatter.step_succeeded :given, 'step 3'
231
232 # then
233 @out.string.should include(" Given step 1\n And step 2\n And step 3")
234 end
235
236 it 'should document additional events using And' do
237 # when
238 @formatter.step_succeeded :when, 'step 1'
239 @formatter.step_succeeded :when, 'step 2'
240 @formatter.step_succeeded :when, 'step 3'
241
242 # then
243 @out.string.should include(" When step 1\n And step 2\n And step 3")
244 end
245
246 it 'should document additional outcomes using And' do
247 # when
248 @formatter.step_succeeded :then, 'step 1'
249 @formatter.step_succeeded :then, 'step 2'
250 @formatter.step_succeeded :then, 'step 3'
251
252 # then
253 @out.string.should include(" Then step 1\n And step 2\n And step 3")
254 end
255
256 it 'should document a GivenScenario followed by a Given using And' do
257 # when
258 @formatter.step_succeeded :'given scenario', 'a scenario'
259 @formatter.step_succeeded :given, 'a context'
260
261 # then
262 @out.string.should include(" Given scenario a scenario\n And a context")
263 end
264
265 it 'should document steps with replaced params' do
266 @formatter.step_succeeded :given, 'a $coloured dog with $n legs', 'pink', 21
267 @out.string.should include(" Given a pink dog with 21 legs")
268 end
269
270 it 'should document regexp steps with replaced params' do
271 @formatter.step_succeeded :given, /a (pink|blue) dog with (.*) legs/, 'pink', 21
272 @out.string.should include(" Given a pink dog with 21 legs")
273 end
274
275 it "should append PENDING for the first pending step" do
276 @formatter.scenario_started('','')
277 @formatter.step_pending(:given, 'a context')
278
279 @out.string.should include('Given a context (PENDING)')
280 end
281
282 it "should append PENDING for pending after already pending" do
283 @formatter.scenario_started('','')
284 @formatter.step_pending(:given, 'a context')
285 @formatter.step_pending(:when, 'I say hey')
286
287 @out.string.should include('When I say hey (PENDING)')
288 end
289
290 it "should append FAILED for the first failiure" do
291 @formatter.scenario_started('','')
292 @formatter.step_failed(:given, 'a context')
293
294 @out.string.should include('Given a context (FAILED)')
295 end
296
297 it "should append SKIPPED for the second failiure" do
298 @formatter.scenario_started('','')
299 @formatter.step_failed(:given, 'a context')
300 @formatter.step_failed(:when, 'I say hey')
301
302 @out.string.should include('When I say hey (SKIPPED)')
303 end
304
305 it "should append SKIPPED for the a failiure after PENDING" do
306 @formatter.scenario_started('','')
307 @formatter.step_pending(:given, 'a context')
308 @formatter.step_failed(:when, 'I say hey')
309
310 @out.string.should include('When I say hey (SKIPPED)')
311 end
312
313 it 'should print some white space after each story' do
314 # when
315 @formatter.story_ended 'title', 'narrative'
316
317 # then
318 @out.string.should include("\n\n")
319 end
320
321 it "should print nothing for collected_steps" do
322 @formatter.collected_steps(['Given a $coloured $animal', 'Given a $n legged eel'])
323 @out.string.should == ("")
324 end
325
326 it "should ignore messages it doesn't care about" do
327 lambda {
328 @formatter.this_method_does_not_exist
329 }.should_not raise_error
330 end
331 end
332 end
333 end
334 end
335end