Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / spec / spec / runner / formatter / story / plain_text_formatter_spec.rb
blob3d6869a870898aa42dcde4124ff79d29fdae8936
1 require File.dirname(__FILE__) + '/../../../../spec_helper.rb'
2 require File.dirname(__FILE__) + '/../../../story/rspec_adapter.rb'
4 module 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             @options = mock('options')
13             @options.stub!(:colour).and_return(false)
14             @reporter = PlainTextFormatter.new(@options, @out)
15           end
16         
17           it 'should summarize the number of scenarios when the run ends' do
18             # when
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')
26             @reporter.run_ended
27           
28             # then
29             @out.string.should include('3 scenarios')
30           end
31         
32           it 'should summarize the number of successful scenarios when the run ends' do
33             # when
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')
41             @reporter.run_ended
42           
43             # then
44             @out.string.should include('3 scenarios: 3 succeeded')
45           end
46         
47           it 'should summarize the number of failed scenarios when the run ends' do
48             # when
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' })
56             @reporter.run_ended
57           
58             # then
59             @out.string.should contain("3 scenarios: 1 succeeded, 2 failed")
60           end
61         
62           it 'should summarize the number of pending scenarios when the run ends' do
63             # when
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')
71             @reporter.run_ended
72           
73             # then
74             @out.string.should contain("3 scenarios: 1 succeeded, 0 failed, 2 pending")
75           end
76         
77           it "should only count the first failure in one scenario" do
78             # when
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' })
87             @reporter.run_ended
88           
89             # then
90             @out.string.should contain("3 scenarios: 1 succeeded, 2 failed")
91           end
92         
93           it "should only count the first pending in one scenario" do
94             # when
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 ...')
103             @reporter.run_ended
104           
105             # then
106             @out.string.should contain("3 scenarios: 1 succeeded, 0 failed, 2 pending")
107           end
108         
109           it "should only count a failure before the first pending in one scenario" do
110             # when
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' })
119             @reporter.run_ended
120           
121             # then
122             @out.string.should contain("3 scenarios: 1 succeeded, 1 failed, 1 pending")
123           end
124         
125           it 'should produce details of the first failure each failed scenario when the run ends' do
126             # when
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' })
135             @reporter.run_ended
136           
137             # then
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")
144           end
145         
146           it 'should produce details of each pending step when the run ends' do
147             # when
148             @reporter.run_started(2)
149             @reporter.scenario_pending('story', 'scenario2', 'todo2')
150             @reporter.scenario_pending('story', 'scenario3', 'todo3')
151             @reporter.run_ended
152           
153             # then
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")
157           end
158         
159           it 'should document a story title and narrative' do
160             # when
161             @reporter.story_started 'story', 'narrative'
162           
163             # then
164             @out.string.should contain("Story: story\n\n  narrative")
165           end
166         
167           it 'should document a scenario name' do
168             # when
169             @reporter.scenario_started 'story', 'scenario'
170           
171             # then
172             @out.string.should contain("\n\nScenario: scenario")
173           end
174         
175           it 'should document a step by sentence-casing its name' do
176             # when
177             @reporter.step_succeeded :given, 'a context'
178             @reporter.step_succeeded :when, 'an event'
179             @reporter.step_succeeded :then, 'an outcome'
180           
181             # then
182             @out.string.should contain("\n\n  Given a context\n\n  When an event\n\n  Then an outcome")
183           end
184         
185           it 'should document additional givens using And' do
186             # when
187             @reporter.step_succeeded :given, 'step 1'
188             @reporter.step_succeeded :given, 'step 2'
189             @reporter.step_succeeded :given, 'step 3'
190           
191             # then
192             @out.string.should contain("  Given step 1\n  And step 2\n  And step 3")
193           end
194         
195           it 'should document additional events using And' do
196             # when
197             @reporter.step_succeeded :when, 'step 1'
198             @reporter.step_succeeded :when, 'step 2'
199             @reporter.step_succeeded :when, 'step 3'
200           
201             # then
202             @out.string.should contain("  When step 1\n  And step 2\n  And step 3")
203           end
204         
205           it 'should document additional outcomes using And' do
206             # when
207             @reporter.step_succeeded :then, 'step 1'
208             @reporter.step_succeeded :then, 'step 2'
209             @reporter.step_succeeded :then, 'step 3'
210           
211             # then
212             @out.string.should contain("  Then step 1\n  And step 2\n  And step 3")
213           end
214         
215           it 'should document a GivenScenario followed by a Given using And' do
216             # when
217             @reporter.step_succeeded :'given scenario', 'a scenario'
218             @reporter.step_succeeded :given, 'a context'
219           
220             # then
221             @out.string.should contain("  Given scenario a scenario\n  And a context")
222           end
223         
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")
227           end
228         
229           it "should append PENDING for the first pending step" do
230             @reporter.scenario_started('','')
231             @reporter.step_pending(:given, 'a context')
232           
233             @out.string.should contain('Given a context (PENDING)')
234           end
235         
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')
240           
241             @out.string.should contain('When I say hey (PENDING)')
242           end
243         
244           it "should append FAILED for the first failiure" do
245             @reporter.scenario_started('','')
246             @reporter.step_failed(:given, 'a context')
247           
248             @out.string.should contain('Given a context (FAILED)')
249           end
250         
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')
255           
256             @out.string.should contain('When I say hey (SKIPPED)')
257           end
258         
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')
263           
264             @out.string.should contain('When I say hey (SKIPPED)')
265           end
266         
267           it 'should print some white space after each story' do
268             # when
269             @reporter.story_ended 'title', 'narrative'
270           
271             # then
272             @out.string.should contain("\n\n")
273           end
274           
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 == ("")
278           end
279         end
280       end
281     end
282   end