public
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/dchelimsky/rspec.git
Search Repo:
Click here to lend your support to: rspec and make a donation at www.pledgie.com !
commit  e1bce2b4517a206dd08313652cf2f0b0cf740d4f
tree    191fe7aef3e39acdd8e968b68e34a15312c297ce
parent  294acb030f811fd546735aa819cdcf89d142b635
rspec / spec / spec / runner / formatter / indented_text_formatter_spec.rb
100644 261 lines (227 sloc) 9.746 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
require File.dirname(__FILE__) + '/../../../spec_helper.rb'
require 'spec/runner/formatter/indented_text_formatter'
 
module Spec
  module Runner
    module Formatter
      describe IndentedTextFormatter do
        it_should_behave_like "sandboxed rspec_options"
        attr_reader :io, :options, :formatter, :example_group
        before(:each) do
          @io = StringIO.new
          options.stub!(:dry_run).and_return(false)
          options.stub!(:colour).and_return(false)
          @formatter = IndentedTextFormatter.new(options, io)
          @example_group = ::Spec::Example::ExampleGroup.describe("ExampleGroup") do
            specify "example" do
            end
          end
        end
 
        describe "where ExampleGroup has no superclasss with a description" do
          before do
            add_example_group
          end
 
          def add_example_group
            formatter.add_example_group(example_group)
          end
 
          describe "#dump_summary" do
            it "should produce standard summary without pending when pending has a 0 count" do
              formatter.dump_summary(3, 2, 1, 0)
              expected_output = <<-OUT
ExampleGroup
 
Finished in 3 seconds
 
2 examples, 1 failure
OUT
 
              io.string.should == expected_output.gsub(/^ /, '')
            end
 
            it "should produce standard summary" do
              formatter.dump_summary(3, 2, 1, 4)
              expected_output = <<-OUT
ExampleGroup
 
Finished in 3 seconds
 
2 examples, 1 failure, 4 pending
OUT
              io.string.should == expected_output.gsub(/^ /, '')
            end
          end
 
          describe "#add_example_group" do
            describe "when ExampleGroup has description_args" do
              before do
                example_group.description_args.should_not be_nil
              end
 
              describe "when ExampleGroup has no parents with description args" do
                before do
                  example_group.superclass.description_args.should be_nil
                end
 
                it "should push ExampleGroup name" do
                  io.string.should eql("ExampleGroup\n")
                end
              end
 
              describe "when ExampleGroup has one parent with description args" do
                attr_reader :child_example_group
                def add_example_group
                  example_group.description_args.should_not be_nil
                  @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
                  formatter.add_example_group(child_example_group)
                end
 
                it "should push ExampleGroup name with two spaces of indentation" do
                  io.string.should eql(" Child ExampleGroup\n")
                end
              end
 
              describe "when ExampleGroup has two parents with description args" do
                attr_reader :child_example_group, :grand_child_example_group
                def add_example_group
                  example_group.description_args.should_not be_nil
                  @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
                  @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
                  formatter.add_example_group(grand_child_example_group)
                end
 
                it "should push ExampleGroup name with two spaces of indentation" do
                  io.string.should eql(" GrandChild ExampleGroup\n")
                end
              end
            end
 
            describe "when ExampleGroup description_args is nil" do
              attr_reader :child_example_group
              def add_example_group
                @child_example_group = Class.new(example_group)
                child_example_group.description_args.should be_nil
                formatter.add_example_group(child_example_group)
              end
 
              it "should not render anything" do
                io.string.should eql("")
              end
            end
 
            describe "when ExampleGroup description_args is empty" do
              def add_example_group
                example_group.set_description
                example_group.description_args.should be_empty
                super
              end
 
              it "should not render anything" do
                io.string.should eql("")
              end
            end
          end
 
          describe "#example_failed" do
            describe "where ExampleGroup has no superclasss with a description" do
              describe "when having an error" do
                it "should push failing spec name and failure number" do
                  formatter.example_failed(
                    example_group.it("spec"),
                    98,
                    Reporter::Failure.new("c s", RuntimeError.new)
                  )
                  expected_output = <<-OUT
ExampleGroup
spec (ERROR - 98)
OUT
                  io.string.should == expected_output.gsub(/^ /, '')
                end
              end
 
              describe "when having an expectation failure" do
                it "should push failing spec name and failure number" do
                  formatter.example_failed(
                    example_group.it("spec"),
                    98,
                    Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
                  )
                  expected_output = <<-OUT
ExampleGroup
spec (FAILED - 98)
OUT
                  io.string.should == expected_output.gsub(/^ /, '')
                end
              end
            end
 
            describe "where ExampleGroup has two superclasses with a description" do
              attr_reader :child_example_group, :grand_child_example_group
 
              def add_example_group
                @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
                @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
                formatter.add_example_group(grand_child_example_group)
              end
 
              describe "when having an error" do
                it "should push failing spec name and failure number" do
                  formatter.example_failed(
                    grand_child_example_group.it("spec"),
                    98,
                    Reporter::Failure.new("c s", RuntimeError.new)
                  )
                  expected_output = <<-OUT
GrandChild ExampleGroup
spec (ERROR - 98)
OUT
                  io.string.should == expected_output.gsub(/^ /, '')
                end
              end
 
              describe "when having an expectation" do
                it "should push failing spec name and failure number" do
                  formatter.example_failed(
                    grand_child_example_group.it("spec"),
                    98,
                    Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
                  )
                  expected_output = <<-OUT
GrandChild ExampleGroup
spec (FAILED - 98)
OUT
                  io.string.should == expected_output.gsub(/^ /, '')
                end
              end
            end
          end
 
          describe "#start" do
            it "should push nothing on start" do
              formatter.start(5)
              expected_output = <<-OUT
ExampleGroup
OUT
              io.string.should == expected_output.gsub(/^ /, '')
            end
          end
 
          describe "#start_dump" do
            it "should push nothing on start dump" do
              formatter.start_dump
              expected_output = <<-OUT
ExampleGroup
OUT
              io.string.should == expected_output.gsub(/^ /, '')
            end
          end
 
          describe "#example_passed" do
            it "should push passing spec name" do
              formatter.example_passed(example_group.it("spec"))
              expected_output = <<-OUT
ExampleGroup
spec
OUT
              io.string.should == expected_output.gsub(/^ /, '')
            end
          end
 
          describe "#example_pending" do
            it "should push pending example name and message" do
              formatter.example_pending(example_group.examples.first, 'reason')
              expected_output = <<-OUT
ExampleGroup
example (PENDING: reason)
OUT
              io.string.should == expected_output.gsub(/^ /, '')
            end
 
            it "should dump pending" do
              formatter.example_pending(example_group.examples.first, 'reason')
              io.rewind
              formatter.dump_pending
              io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
            end
          end
 
          def have_single_level_example_group_output(expected_output)
            expected = "ExampleGroup\n #{expected_output}"
            ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
              actual == expected
            end
          end
        end
      end
    end
  end
end