1 require File.dirname(__FILE__) + '/../../../../spec_helper.rb'
2 require File.dirname(__FILE__) + '/../../../story/rspec_adapter.rb'
8 describe PlainTextFormatter do
12 @options = mock('options')
13 @options.stub!(:colour).and_return(false)
14 @reporter = PlainTextFormatter.new(@options, @out)
17 it 'should summarize the number of scenarios when the run ends' do
19 @reporter.run_started(3)
20 @reporter.scenario_started(nil, nil)
21 @reporter.scenario_succeeded('story', 'scenario1')
22 @reporter.scenario_started(nil, nil)
23 @reporter.scenario_succeeded('story', 'scenario2')
24 @reporter.scenario_started(nil, nil)
25 @reporter.scenario_succeeded('story', 'scenario3')
29 @out.string.should include('3 scenarios')
32 it 'should summarize the number of successful scenarios when the run ends' do
34 @reporter.run_started(3)
35 @reporter.scenario_started(nil, nil)
36 @reporter.scenario_succeeded('story', 'scenario1')
37 @reporter.scenario_started(nil, nil)
38 @reporter.scenario_succeeded('story', 'scenario2')
39 @reporter.scenario_started(nil, nil)
40 @reporter.scenario_succeeded('story', 'scenario3')
44 @out.string.should include('3 scenarios: 3 succeeded')
47 it 'should summarize the number of failed scenarios when the run ends' do
49 @reporter.run_started(3)
50 @reporter.scenario_started(nil, nil)
51 @reporter.scenario_succeeded('story', 'scenario1')
52 @reporter.scenario_started(nil, nil)
53 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
54 @reporter.scenario_started(nil, nil)
55 @reporter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
59 @out.string.should contain("3 scenarios: 1 succeeded, 2 failed")
62 it 'should summarize the number of pending scenarios when the run ends' do
64 @reporter.run_started(3)
65 @reporter.scenario_started(nil, nil)
66 @reporter.scenario_succeeded('story', 'scenario1')
67 @reporter.scenario_started(nil, nil)
68 @reporter.scenario_pending('story', 'scenario2', 'message')
69 @reporter.scenario_started(nil, nil)
70 @reporter.scenario_pending('story', 'scenario3', 'message')
74 @out.string.should contain("3 scenarios: 1 succeeded, 0 failed, 2 pending")
77 it "should only count the first failure in one scenario" do
79 @reporter.run_started(3)
80 @reporter.scenario_started(nil, nil)
81 @reporter.scenario_succeeded('story', 'scenario1')
82 @reporter.scenario_started(nil, nil)
83 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
84 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' })
85 @reporter.scenario_started(nil, nil)
86 @reporter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
90 @out.string.should contain("3 scenarios: 1 succeeded, 2 failed")
93 it "should only count the first pending in one scenario" do
95 @reporter.run_started(3)
96 @reporter.scenario_started(nil, nil)
97 @reporter.scenario_succeeded('story', 'scenario1')
98 @reporter.scenario_started(nil, nil)
99 @reporter.scenario_pending('story', 'scenario2', 'because ...')
100 @reporter.scenario_pending('story', 'scenario2', 'because ...')
101 @reporter.scenario_started(nil, nil)
102 @reporter.scenario_pending('story', 'scenario3', 'because ...')
106 @out.string.should contain("3 scenarios: 1 succeeded, 0 failed, 2 pending")
109 it "should only count a failure before the first pending in one scenario" do
111 @reporter.run_started(3)
112 @reporter.scenario_started(nil, nil)
113 @reporter.scenario_succeeded('story', 'scenario1')
114 @reporter.scenario_started(nil, nil)
115 @reporter.scenario_pending('story', 'scenario2', exception_from { raise RuntimeError, 'oops' })
116 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' })
117 @reporter.scenario_started(nil, nil)
118 @reporter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' })
122 @out.string.should contain("3 scenarios: 1 succeeded, 1 failed, 1 pending")
125 it 'should produce details of the first failure each failed scenario when the run ends' do
127 @reporter.run_started(3)
128 @reporter.scenario_started(nil, nil)
129 @reporter.scenario_succeeded('story', 'scenario1')
130 @reporter.scenario_started(nil, nil)
131 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2' })
132 @reporter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2 - this one should not appear' })
133 @reporter.scenario_started(nil, nil)
134 @reporter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops3' })
138 @out.string.should contain("FAILURES:\n")
139 @out.string.should contain("1) story (scenario2) FAILED")
140 @out.string.should contain("RuntimeError: oops2")
141 @out.string.should_not contain("RuntimeError: oops2 - this one should not appear")
142 @out.string.should contain("2) story (scenario3) FAILED")
143 @out.string.should contain("RuntimeError: oops3")
146 it 'should produce details of each pending step when the run ends' do
148 @reporter.run_started(2)
149 @reporter.scenario_pending('story', 'scenario2', 'todo2')
150 @reporter.scenario_pending('story', 'scenario3', 'todo3')
154 @out.string.should contain("Pending Steps:\n")
155 @out.string.should contain("1) story (scenario2): todo2")
156 @out.string.should contain("2) story (scenario3): todo3")
159 it 'should document a story title and narrative' do
161 @reporter.story_started 'story', 'narrative'
164 @out.string.should contain("Story: story\n\n narrative")
167 it 'should document a scenario name' do
169 @reporter.scenario_started 'story', 'scenario'
172 @out.string.should contain("\n\nScenario: scenario")
175 it 'should document a step by sentence-casing its name' do
177 @reporter.step_succeeded :given, 'a context'
178 @reporter.step_succeeded :when, 'an event'
179 @reporter.step_succeeded :then, 'an outcome'
182 @out.string.should contain("\n\n Given a context\n\n When an event\n\n Then an outcome")
185 it 'should document additional givens using And' do
187 @reporter.step_succeeded :given, 'step 1'
188 @reporter.step_succeeded :given, 'step 2'
189 @reporter.step_succeeded :given, 'step 3'
192 @out.string.should contain(" Given step 1\n And step 2\n And step 3")
195 it 'should document additional events using And' do
197 @reporter.step_succeeded :when, 'step 1'
198 @reporter.step_succeeded :when, 'step 2'
199 @reporter.step_succeeded :when, 'step 3'
202 @out.string.should contain(" When step 1\n And step 2\n And step 3")
205 it 'should document additional outcomes using And' do
207 @reporter.step_succeeded :then, 'step 1'
208 @reporter.step_succeeded :then, 'step 2'
209 @reporter.step_succeeded :then, 'step 3'
212 @out.string.should contain(" Then step 1\n And step 2\n And step 3")
215 it 'should document a GivenScenario followed by a Given using And' do
217 @reporter.step_succeeded :'given scenario', 'a scenario'
218 @reporter.step_succeeded :given, 'a context'
221 @out.string.should contain(" Given scenario a scenario\n And a context")
224 it 'should document steps with replaced params' do
225 @reporter.step_succeeded :given, 'a $coloured dog with $n legs', 'pink', 21
226 @out.string.should contain(" Given a pink dog with 21 legs")
229 it "should append PENDING for the first pending step" do
230 @reporter.scenario_started('','')
231 @reporter.step_pending(:given, 'a context')
233 @out.string.should contain('Given a context (PENDING)')
236 it "should append PENDING for pending after already pending" do
237 @reporter.scenario_started('','')
238 @reporter.step_pending(:given, 'a context')
239 @reporter.step_pending(:when, 'I say hey')
241 @out.string.should contain('When I say hey (PENDING)')
244 it "should append FAILED for the first failiure" do
245 @reporter.scenario_started('','')
246 @reporter.step_failed(:given, 'a context')
248 @out.string.should contain('Given a context (FAILED)')
251 it "should append SKIPPED for the second failiure" do
252 @reporter.scenario_started('','')
253 @reporter.step_failed(:given, 'a context')
254 @reporter.step_failed(:when, 'I say hey')
256 @out.string.should contain('When I say hey (SKIPPED)')
259 it "should append SKIPPED for the a failiure after PENDING" do
260 @reporter.scenario_started('','')
261 @reporter.step_pending(:given, 'a context')
262 @reporter.step_failed(:when, 'I say hey')
264 @out.string.should contain('When I say hey (SKIPPED)')
267 it 'should print some white space after each story' do
269 @reporter.story_ended 'title', 'narrative'
272 @out.string.should contain("\n\n")
275 it "should print nothing for collected_steps" do
276 @reporter.collected_steps(['Given a $coloured $animal', 'Given a $n legged eel'])
277 @out.string.should == ("")