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 !
Adding IndentedTextFormatter. Did not commit this last time.
btakita (author)
Thu May 22 01:30:10 -0700 2008
commit  e1bce2b4517a206dd08313652cf2f0b0cf740d4f
tree    191fe7aef3e39acdd8e968b68e34a15312c297ce
parent  294acb030f811fd546735aa819cdcf89d142b635
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,49 @@
0
+require 'spec/runner/formatter/base_text_formatter'
0
+
0
+module Spec
0
+ module Runner
0
+ module Formatter
0
+ class IndentedTextFormatter < BaseTextFormatter
0
+ def add_example_group(example_group)
0
+ super
0
+ if example_group.description_args && !example_group.description_args.empty?
0
+ output.puts "#{example_group_indentation(example_group)}#{example_group.description_args}"
0
+ output.flush
0
+ end
0
+ end
0
+
0
+ def example_failed(example, counter, failure)
0
+ message = if failure.expectation_not_met?
0
+ "#{example_group_indentation(example.class)} #{example.description} (FAILED - #{counter})"
0
+ else
0
+ "#{example_group_indentation(example.class)} #{example.description} (ERROR - #{counter})"
0
+ end
0
+
0
+ output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
0
+ output.flush
0
+ end
0
+
0
+ def example_passed(example)
0
+ message = "#{example_group_indentation(example.class)} #{example.description}"
0
+ output.puts green(message)
0
+ output.flush
0
+ end
0
+
0
+ def example_pending(example, message)
0
+ super
0
+ output.puts yellow("#{example_group_indentation(example.class)} #{example.description} (PENDING: #{message})")
0
+ output.flush
0
+ end
0
+
0
+ def example_group_indentation(example_group)
0
+ example_group_chain = []
0
+ example_group.send(:execute_in_class_hierarchy) do |parent_example_group|
0
+ example_group_chain << parent_example_group if parent_example_group.description_args
0
+ end
0
+ ' ' * (example_group_chain - [example_group]).length
0
+ end
0
+ end
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,261 @@
0
+require File.dirname(__FILE__) + '/../../../spec_helper.rb'
0
+require 'spec/runner/formatter/indented_text_formatter'
0
+
0
+module Spec
0
+ module Runner
0
+ module Formatter
0
+ describe IndentedTextFormatter do
0
+ it_should_behave_like "sandboxed rspec_options"
0
+ attr_reader :io, :options, :formatter, :example_group
0
+ before(:each) do
0
+ @io = StringIO.new
0
+ options.stub!(:dry_run).and_return(false)
0
+ options.stub!(:colour).and_return(false)
0
+ @formatter = IndentedTextFormatter.new(options, io)
0
+ @example_group = ::Spec::Example::ExampleGroup.describe("ExampleGroup") do
0
+ specify "example" do
0
+ end
0
+ end
0
+ end
0
+
0
+ describe "where ExampleGroup has no superclasss with a description" do
0
+ before do
0
+ add_example_group
0
+ end
0
+
0
+ def add_example_group
0
+ formatter.add_example_group(example_group)
0
+ end
0
+
0
+ describe "#dump_summary" do
0
+ it "should produce standard summary without pending when pending has a 0 count" do
0
+ formatter.dump_summary(3, 2, 1, 0)
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+
0
+ Finished in 3 seconds
0
+
0
+ 2 examples, 1 failure
0
+ OUT
0
+
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+
0
+ it "should produce standard summary" do
0
+ formatter.dump_summary(3, 2, 1, 4)
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+
0
+ Finished in 3 seconds
0
+
0
+ 2 examples, 1 failure, 4 pending
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "#add_example_group" do
0
+ describe "when ExampleGroup has description_args" do
0
+ before do
0
+ example_group.description_args.should_not be_nil
0
+ end
0
+
0
+ describe "when ExampleGroup has no parents with description args" do
0
+ before do
0
+ example_group.superclass.description_args.should be_nil
0
+ end
0
+
0
+ it "should push ExampleGroup name" do
0
+ io.string.should eql("ExampleGroup\n")
0
+ end
0
+ end
0
+
0
+ describe "when ExampleGroup has one parent with description args" do
0
+ attr_reader :child_example_group
0
+ def add_example_group
0
+ example_group.description_args.should_not be_nil
0
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
0
+ formatter.add_example_group(child_example_group)
0
+ end
0
+
0
+ it "should push ExampleGroup name with two spaces of indentation" do
0
+ io.string.should eql(" Child ExampleGroup\n")
0
+ end
0
+ end
0
+
0
+ describe "when ExampleGroup has two parents with description args" do
0
+ attr_reader :child_example_group, :grand_child_example_group
0
+ def add_example_group
0
+ example_group.description_args.should_not be_nil
0
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
0
+ @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
0
+ formatter.add_example_group(grand_child_example_group)
0
+ end
0
+
0
+ it "should push ExampleGroup name with two spaces of indentation" do
0
+ io.string.should eql(" GrandChild ExampleGroup\n")
0
+ end
0
+ end
0
+ end
0
+
0
+ describe "when ExampleGroup description_args is nil" do
0
+ attr_reader :child_example_group
0
+ def add_example_group
0
+ @child_example_group = Class.new(example_group)
0
+ child_example_group.description_args.should be_nil
0
+ formatter.add_example_group(child_example_group)
0
+ end
0
+
0
+ it "should not render anything" do
0
+ io.string.should eql("")
0
+ end
0
+ end
0
+
0
+ describe "when ExampleGroup description_args is empty" do
0
+ def add_example_group
0
+ example_group.set_description
0
+ example_group.description_args.should be_empty
0
+ super
0
+ end
0
+
0
+ it "should not render anything" do
0
+ io.string.should eql("")
0
+ end
0
+ end
0
+ end
0
+
0
+ describe "#example_failed" do
0
+ describe "where ExampleGroup has no superclasss with a description" do
0
+ describe "when having an error" do
0
+ it "should push failing spec name and failure number" do
0
+ formatter.example_failed(
0
+ example_group.it("spec"),
0
+ 98,
0
+ Reporter::Failure.new("c s", RuntimeError.new)
0
+ )
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ spec (ERROR - 98)
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "when having an expectation failure" do
0
+ it "should push failing spec name and failure number" do
0
+ formatter.example_failed(
0
+ example_group.it("spec"),
0
+ 98,
0
+ Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
0
+ )
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ spec (FAILED - 98)
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+ end
0
+
0
+ describe "where ExampleGroup has two superclasses with a description" do
0
+ attr_reader :child_example_group, :grand_child_example_group
0
+
0
+ def add_example_group
0
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
0
+ @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
0
+ formatter.add_example_group(grand_child_example_group)
0
+ end
0
+
0
+ describe "when having an error" do
0
+ it "should push failing spec name and failure number" do
0
+ formatter.example_failed(
0
+ grand_child_example_group.it("spec"),
0
+ 98,
0
+ Reporter::Failure.new("c s", RuntimeError.new)
0
+ )
0
+ expected_output = <<-OUT
0
+ GrandChild ExampleGroup
0
+ spec (ERROR - 98)
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "when having an expectation" do
0
+ it "should push failing spec name and failure number" do
0
+ formatter.example_failed(
0
+ grand_child_example_group.it("spec"),
0
+ 98,
0
+ Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
0
+ )
0
+ expected_output = <<-OUT
0
+ GrandChild ExampleGroup
0
+ spec (FAILED - 98)
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+ end
0
+ end
0
+
0
+ describe "#start" do
0
+ it "should push nothing on start" do
0
+ formatter.start(5)
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "#start_dump" do
0
+ it "should push nothing on start dump" do
0
+ formatter.start_dump
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "#example_passed" do
0
+ it "should push passing spec name" do
0
+ formatter.example_passed(example_group.it("spec"))
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ spec
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+ end
0
+
0
+ describe "#example_pending" do
0
+ it "should push pending example name and message" do
0
+ formatter.example_pending(example_group.examples.first, 'reason')
0
+ expected_output = <<-OUT
0
+ ExampleGroup
0
+ example (PENDING: reason)
0
+ OUT
0
+ io.string.should == expected_output.gsub(/^ /, '')
0
+ end
0
+
0
+ it "should dump pending" do
0
+ formatter.example_pending(example_group.examples.first, 'reason')
0
+ io.rewind
0
+ formatter.dump_pending
0
+ io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
0
+ end
0
+ end
0
+
0
+ def have_single_level_example_group_output(expected_output)
0
+ expected = "ExampleGroup\n #{expected_output}"
0
+ ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
0
+ actual == expected
0
+ end
0
+ end
0
+ end
0
+ end
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.