Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / spec / spec / runner / formatter / nested_text_formatter_spec.rb
1 require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2 require 'spec/runner/formatter/nested_text_formatter'
3
4 module Spec
5   module Runner
6     module Formatter
7       describe NestedTextFormatter do
8         it_should_behave_like "sandboxed rspec_options"
9         attr_reader :io, :options, :formatter, :example_group
10         before(:each) do
11           @io = StringIO.new
12           options.stub!(:dry_run).and_return(false)
13           options.stub!(:colour).and_return(false)
14           @formatter = NestedTextFormatter.new(options, io)
15           @example_group = ::Spec::Example::ExampleGroup.describe("ExampleGroup") do
16             specify "example" do
17             end
18           end
19         end
20
21         describe "where ExampleGroup has no superclasss with a description" do
22           before do
23             add_example_group
24           end
25
26           def add_example_group
27             formatter.add_example_group(example_group)
28           end
29
30           describe "#dump_summary" do
31             it "should produce standard summary without pending when pending has a 0 count" do
32               formatter.dump_summary(3, 2, 1, 0)
33               expected_output = <<-OUT
34               ExampleGroup
35
36               Finished in 3 seconds
37
38               2 examples, 1 failure
39               OUT
40
41               io.string.should == expected_output.gsub(/^              /, '')
42             end
43
44             it "should produce standard summary" do
45               formatter.dump_summary(3, 2, 1, 4)
46               expected_output = <<-OUT
47               ExampleGroup
48
49               Finished in 3 seconds
50
51               2 examples, 1 failure, 4 pending
52               OUT
53               io.string.should == expected_output.gsub(/^              /, '')
54             end
55           end
56
57           describe "#add_example_group" do
58             describe "when ExampleGroup has description_args" do
59               before do
60                 example_group.description_args.should_not be_nil
61               end
62
63               describe "when ExampleGroup has no parents with description args" do
64                 before do
65                   example_group.superclass.description_args.should be_nil
66                 end
67
68                 it "should push ExampleGroup name" do
69                   io.string.should eql("ExampleGroup\n")
70                 end
71               end
72
73               describe "when ExampleGroup has one parent with description args" do
74                 attr_reader :child_example_group
75                 def add_example_group
76                   example_group.description_args.should_not be_nil
77                   @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
78                 end
79
80                 describe "and parent ExampleGroups have not been printed" do
81                   before do
82                     formatter.add_example_group(child_example_group)
83                   end
84
85                   it "should push ExampleGroup name with two spaces of indentation" do
86                     expected_output = <<-OUT
87                     ExampleGroup
88                       Child ExampleGroup
89                     OUT
90                     io.string.should == expected_output.gsub(/^                    /, '')
91                   end
92                 end
93
94                 describe "and parent ExampleGroups have been printed" do
95                   before do
96                     formatter.add_example_group(example_group)
97                     io.string = ""
98                     formatter.add_example_group(child_example_group)
99                   end
100
101                   it "should print only the indented ExampleGroup" do
102                     expected_output = <<-OUT
103                       Child ExampleGroup
104                     OUT
105                     io.string.should == expected_output.gsub(/^                    /, '')
106                   end
107                 end
108               end
109
110               describe "when ExampleGroup has two parents with description args" do
111                 attr_reader :child_example_group, :grand_child_example_group
112                 def add_example_group
113                   example_group.description_args.should_not be_nil
114                   @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
115                   @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
116                 end
117
118                 describe "and parent ExampleGroups have not been printed" do
119                   before do
120                     formatter.add_example_group(grand_child_example_group)
121                   end
122
123                   it "should print the entire nested ExampleGroup heirarchy" do
124                     expected_output = <<-OUT
125                     ExampleGroup
126                       Child ExampleGroup
127                         GrandChild ExampleGroup
128                     OUT
129                     io.string.should == expected_output.gsub(/^                    /, '')
130                   end
131                 end
132
133                 describe "and parent ExampleGroups have been printed" do
134                   before do
135                     formatter.add_example_group(child_example_group)
136                     io.string = ""
137                     formatter.add_example_group(grand_child_example_group)
138                   end
139
140                   it "should print only the indented ExampleGroup" do
141                     expected_output = <<-OUT
142                         GrandChild ExampleGroup
143                     OUT
144                     io.string.should == expected_output.gsub(/^                    /, '')
145                   end
146                 end
147               end
148             end
149
150             describe "when ExampleGroup description_args is nil" do
151               attr_reader :child_example_group
152
153               describe "and parent ExampleGroups have not been printed" do
154                 def add_example_group
155                   @child_example_group = Class.new(example_group)
156                   child_example_group.description_args.should be_nil
157                   formatter.add_example_group(child_example_group)
158                 end
159
160                 it "should render only the parent ExampleGroup" do
161                   expected_output = <<-OUT
162                   ExampleGroup
163                   OUT
164                   io.string.should == expected_output.gsub(/^                  /, '')
165                 end
166               end
167
168               describe "and parent ExampleGroups have been printed" do
169                 def add_example_group
170                   @child_example_group = Class.new(example_group)
171                   child_example_group.description_args.should be_nil
172                   formatter.add_example_group(example_group)
173                   io.string = ""
174                   formatter.add_example_group(child_example_group)
175                 end
176
177                 it "should not render anything" do
178                   io.string.should == ""
179                 end
180               end
181             end
182
183             describe "when ExampleGroup description_args is empty" do
184               def add_example_group
185                 example_group.set_description
186                 example_group.description_args.should be_empty
187                 super
188               end
189
190               it "should not render anything" do
191                 io.string.should == ""
192               end
193             end
194           end
195
196           describe "#example_failed" do
197             describe "where ExampleGroup has no superclasss with a description" do
198               describe "when having an error" do
199                 it "should push failing spec name and failure number" do
200                   formatter.example_failed(
201                     example_group.it("spec"),
202                     98,
203                     Reporter::Failure.new("c s", RuntimeError.new)
204                   )
205                   expected_output = <<-OUT
206                   ExampleGroup
207                     spec (ERROR - 98)
208                   OUT
209                   io.string.should == expected_output.gsub(/^                  /, '')
210                 end
211               end
212
213               describe "when having an expectation failure" do
214                 it "should push failing spec name and failure number" do
215                   formatter.example_failed(
216                     example_group.it("spec"),
217                     98,
218                     Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
219                   )
220                   expected_output = <<-OUT
221                   ExampleGroup
222                     spec (FAILED - 98)
223                   OUT
224                   io.string.should == expected_output.gsub(/^                  /, '')
225                 end
226               end
227             end
228
229             describe "where ExampleGroup has two superclasses with a description" do
230               attr_reader :child_example_group, :grand_child_example_group
231
232               def add_example_group
233                 @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
234                 @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
235                 formatter.add_example_group(grand_child_example_group)
236               end
237
238               describe "when having an error" do
239                 it "should push failing spec name and failure number" do
240                   formatter.example_failed(
241                     grand_child_example_group.it("spec"),
242                     98,
243                     Reporter::Failure.new("c s", RuntimeError.new)
244                   )
245                   expected_output = <<-OUT
246                   ExampleGroup
247                     Child ExampleGroup
248                       GrandChild ExampleGroup
249                         spec (ERROR - 98)
250                   OUT
251                   io.string.should == expected_output.gsub(/^                  /, '')
252                 end
253               end
254
255               describe "when having an expectation" do
256                 it "should push failing spec name and failure number" do
257                   formatter.example_failed(
258                     grand_child_example_group.it("spec"),
259                     98,
260                     Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
261                   )
262                   expected_output = <<-OUT
263                   ExampleGroup
264                     Child ExampleGroup
265                       GrandChild ExampleGroup
266                         spec (FAILED - 98)
267                   OUT
268                   io.string.should == expected_output.gsub(/^                  /, '')
269                 end
270               end
271             end
272           end
273
274           describe "#start" do
275             it "should push nothing on start" do
276               formatter.start(5)
277               expected_output = <<-OUT
278               ExampleGroup
279               OUT
280               io.string.should == expected_output.gsub(/^              /, '')
281             end
282           end
283
284           describe "#start_dump" do
285             it "should push nothing on start dump" do
286               formatter.start_dump
287               expected_output = <<-OUT
288               ExampleGroup
289               OUT
290               io.string.should == expected_output.gsub(/^              /, '')
291             end
292           end
293
294           describe "#example_passed" do
295             it "should push passing spec name" do
296               formatter.example_passed(example_group.it("spec"))
297               expected_output = <<-OUT
298               ExampleGroup
299                 spec
300               OUT
301               io.string.should == expected_output.gsub(/^              /, '')
302             end
303           end
304
305           describe "#example_pending" do
306             it "should push pending example name and message" do
307               formatter.example_pending(example_group.examples.first, 'reason')
308               expected_output = <<-OUT
309               ExampleGroup
310                 example (PENDING: reason)
311               OUT
312               io.string.should == expected_output.gsub(/^              /, '')
313             end
314
315             it "should dump pending" do
316               formatter.example_pending(example_group.examples.first, 'reason')
317               io.rewind
318               formatter.dump_pending
319               io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
320             end
321           end
322
323           def have_single_level_example_group_output(expected_output)
324             expected = "ExampleGroup\n  #{expected_output}"
325             ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
326               actual == expected
327             end
328           end
329         end
330       end
331     end
332   end
333 end