command_line_reporter 2.1 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/column_spec.rb CHANGED
@@ -1,130 +1,423 @@
1
1
  require 'spec_helper'
2
2
  require 'column'
3
3
 
4
- describe Column do
5
- context 'creation' do
4
+ describe CommandLineReporter::Column do
5
+ describe '#initialize' do
6
6
  it 'rejects invalid options' do
7
7
  expect {
8
- Column.new('test', :asdf => '1234')
8
+ CommandLineReporter::Column.new('test', :asdf => '1234')
9
9
  }.to raise_error ArgumentError
10
10
  end
11
11
 
12
12
  it 'defaults options hash' do
13
13
  expect {
14
- Column.new('test')
14
+ CommandLineReporter::Column.new('test')
15
15
  }.to_not raise_error
16
16
  end
17
17
 
18
18
  it 'defaults the width' do
19
- Column.new('test').width.should == 10
19
+ CommandLineReporter::Column.new('test').width.should == 10
20
20
  end
21
21
 
22
22
  it 'accepts the width' do
23
- Column.new('test', :width => 50).width.should == 50
23
+ CommandLineReporter::Column.new('test', :width => 50).width.should == 50
24
24
  end
25
25
 
26
26
  it 'requires valid width' do
27
27
  expect {
28
- Column.new('test', :width => 'asdf')
28
+ CommandLineReporter::Column.new('test', :width => 'asdf')
29
29
  }.to raise_error ArgumentError
30
30
  end
31
31
 
32
32
  it 'accepts text' do
33
- Column.new('asdf').text.should == 'asdf'
33
+ CommandLineReporter::Column.new('asdf').text.should == 'asdf'
34
+ end
35
+
36
+ it 'accepts color' do
37
+ CommandLineReporter::Column.new('asdf', :color => 'red').color.should == 'red'
38
+ end
39
+
40
+ it 'accepts bold' do
41
+ CommandLineReporter::Column.new('asdf', :bold => true).bold.should be_true
34
42
  end
35
43
 
36
44
  it 'defaults the padding' do
37
- Column.new('test').padding.should == 0
45
+ CommandLineReporter::Column.new('test').padding.should == 0
38
46
  end
39
47
 
40
48
  it 'accepts the padding' do
41
- Column.new('test', :padding => 5).padding.should == 5
49
+ CommandLineReporter::Column.new('test', :padding => 5).padding.should == 5
42
50
  end
43
51
 
44
52
  it 'requires valid width' do
45
53
  expect {
46
- Column.new('test', :padding => 'asdf')
54
+ CommandLineReporter::Column.new('test', :padding => 'asdf')
47
55
  }.to raise_error ArgumentError
48
56
  end
49
57
  end
50
58
 
51
59
  describe '#screen_rows' do
60
+ before :all do
61
+ @controls = {
62
+ :clear => "\e[0m",
63
+ :bold => "\e[1m",
64
+ :red => "\e[31m",
65
+ }
66
+ end
67
+
52
68
  context 'no wrapping' do
53
69
  context 'no padding' do
54
70
  it 'gives a single row' do
55
- c = Column.new('x' * 5)
71
+ c = CommandLineReporter::Column.new('x' * 5)
56
72
  c.screen_rows.size == 1
57
73
  end
58
74
 
59
75
  it 'handles empty text' do
60
- c = Column.new
76
+ c = CommandLineReporter::Column.new
61
77
  c.screen_rows[0].should == ' ' * 10
62
78
  end
63
79
 
64
- it 'left justifies' do
65
- c = Column.new('x' * 10, :width => 20)
66
- c.screen_rows[0].should == 'x' * 10 + ' ' * 10
80
+ context 'left justifies' do
81
+ before :each do
82
+ @text = 'x' * 10
83
+ @filler = ' ' * 10
84
+ end
85
+
86
+ it 'plain text' do
87
+ c = CommandLineReporter::Column.new(@text, :width => 20)
88
+ c.screen_rows[0].should == @text + @filler
89
+ end
90
+
91
+ it 'outputs red' do
92
+ c = CommandLineReporter::Column.new(@text, :align => 'left', :width => 20, :color => 'red')
93
+ c.screen_rows[0].should == @controls[:red] + @text + @filler + @controls[:clear]
94
+ end
95
+
96
+ it 'outputs bold' do
97
+ c = CommandLineReporter::Column.new(@text, :align => 'left', :width => 20, :bold => true)
98
+ c.screen_rows[0].should == @controls[:bold] + @text + @filler + @controls[:clear]
99
+ end
67
100
  end
68
101
 
69
- it 'right justifies' do
70
- c = Column.new('x' * 10, :align => 'right', :width => 20)
71
- c.screen_rows[0].should == ' ' * 10 + 'x' * 10
102
+ context 'right justifies' do
103
+ before :each do
104
+ @text = 'x' * 10
105
+ @filler = ' ' * 10
106
+ end
107
+
108
+ it 'plain text' do
109
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 20)
110
+ c.screen_rows[0].should == @filler + @text
111
+ end
112
+
113
+ it 'outputs red' do
114
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 20, :color => 'red')
115
+ c.screen_rows[0].should == @controls[:red] + @filler + @text + @controls[:clear]
116
+ end
117
+
118
+ it 'outputs bold' do
119
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 20, :bold => true)
120
+ c.screen_rows[0].should == @controls[:bold] + @filler + @text + @controls[:clear]
121
+ end
72
122
  end
73
123
 
74
- it 'center justifies' do
75
- c = Column.new('x' * 10, :align => 'center', :width => 20)
76
- c.screen_rows[0].should == ' ' * 5 + 'x' * 10 + ' ' * 5
124
+ context 'center justifies' do
125
+ before :each do
126
+ @text = 'x' * 10
127
+ @filler = ' ' * 5
128
+ end
129
+
130
+ it 'plain text' do
131
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 20)
132
+ c.screen_rows[0].should == @filler + @text + @filler
133
+ end
134
+
135
+ it 'outputs red' do
136
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 20, :color => 'red')
137
+ c.screen_rows[0].should == @controls[:red] + @filler + @text + @filler + @controls[:clear]
138
+ end
139
+
140
+ it 'outputs bold' do
141
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 20, :bold => true)
142
+ c.screen_rows[0].should == @controls[:bold] + @filler + @text + @filler + @controls[:clear]
143
+ end
77
144
  end
78
145
  end
79
146
 
80
147
  context 'accounts for padding' do
81
- it 'left justifies' do
82
- c = Column.new('x' * 10, :padding => 5, :width => 30)
83
- c.screen_rows[0].should == ' ' * 5 + 'x' * 10 + ' ' * 15
148
+ context 'left justifies' do
149
+ before :each do
150
+ @text = 'x' * 10
151
+ @padding = ' ' * 5
152
+ @filler = ' ' * 10
153
+ end
154
+
155
+ it 'plain text' do
156
+ c = CommandLineReporter::Column.new(@text, :padding => 5, :width => 30)
157
+ c.screen_rows[0].should == @padding + @text + @filler + @padding
158
+ end
159
+
160
+ it 'outputs red' do
161
+ c = CommandLineReporter::Column.new(@text, :padding => 5, :width => 30, :color => 'red')
162
+ c.screen_rows[0].should == @padding + @controls[:red] + @text + @filler + @controls[:clear] + @padding
163
+ end
164
+
165
+ it 'outputs bold' do
166
+ c = CommandLineReporter::Column.new(@text, :padding => 5, :width => 30, :bold => true)
167
+ c.screen_rows[0].should == @padding + @controls[:bold] + @text + @filler + @controls[:clear] + @padding
168
+ end
84
169
  end
85
- it 'right justifies' do
86
- c = Column.new('x' * 10, :align => 'right', :padding => 5, :width => 30)
87
- c.screen_rows[0].should == ' ' * 15 + 'x' * 10 + ' ' * 5
170
+
171
+ context 'right justifies' do
172
+ before :each do
173
+ @text = 'x' * 10
174
+ @padding = ' ' * 5
175
+ @filler = ' ' * 10
176
+ end
177
+
178
+ it 'plain text' do
179
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :padding => 5, :width => 30)
180
+ c.screen_rows[0].should == @padding + @filler + @text + @padding
181
+ end
182
+
183
+ it 'outputs red' do
184
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :padding => 5, :width => 30, :color => 'red')
185
+ c.screen_rows[0].should == @padding + @controls[:red] + @filler + @text + @controls[:clear] + @padding
186
+ end
187
+
188
+ it 'outputs bold' do
189
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :padding => 5, :width => 30, :bold => true)
190
+ c.screen_rows[0].should == @padding + @controls[:bold] + @filler + @text + @controls[:clear] + @padding
191
+ end
88
192
  end
89
- it 'right justifies' do
90
- c = Column.new('x' * 10, :align => 'center', :padding => 5, :width => 30)
91
- c.screen_rows[0].should == ' ' * 10 + 'x' * 10 + ' ' * 10
193
+
194
+ context 'right justifies' do
195
+ before :each do
196
+ @text = ' ' * 10
197
+ @padding = ' ' * 5
198
+ @filler = ' ' * 5
199
+ end
200
+
201
+ it 'plain text' do
202
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :padding => 5, :width => 30)
203
+ c.screen_rows[0].should == @padding + @filler + @text + @filler + @padding
204
+ end
205
+
206
+ it 'outputs red' do
207
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :padding => 5, :width => 30, :color => 'red')
208
+ c.screen_rows[0].should == @padding + @controls[:red] + @filler + @text + @filler + @controls[:clear] + @padding
209
+ end
210
+
211
+ it 'outputs bold' do
212
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :padding => 5, :width => 30, :bold => true)
213
+ c.screen_rows[0].should == @padding + @controls[:bold] + @filler + @text + @filler + @controls[:clear] + @padding
214
+ end
92
215
  end
93
216
  end
94
217
  end
95
218
 
96
219
  context 'with wrapping' do
97
220
  context 'no padding' do
98
- it 'left justifies' do
99
- c = Column.new('x' * 25, :width => 10)
100
- c.screen_rows.should == ['x' * 10, 'x' * 10, 'x' * 5 + ' ' * 5]
221
+ context 'left justifies' do
222
+ before :each do
223
+ @text = 'x' * 25
224
+ @full_line = 'x' * 10
225
+ @remainder = 'x' * 5
226
+ @filler = ' ' * 5
227
+ end
228
+
229
+ it 'plain text' do
230
+ c = CommandLineReporter::Column.new(@text, :width => 10)
231
+ c.screen_rows.should == [@full_line, @full_line, @remainder + @filler]
232
+ end
233
+
234
+ it 'outputs red' do
235
+ c = CommandLineReporter::Column.new(@text, :width => 10, :color => 'red')
236
+ c.screen_rows.should == [
237
+ @controls[:red] + @full_line + @controls[:clear],
238
+ @controls[:red] + @full_line + @controls[:clear],
239
+ @controls[:red] + @remainder + @filler + @controls[:clear],
240
+ ]
241
+ end
242
+
243
+ it 'outputs bold' do
244
+ c = CommandLineReporter::Column.new(@text, :width => 10, :bold => true)
245
+ c.screen_rows.should == [
246
+ @controls[:bold] + @full_line + @controls[:clear],
247
+ @controls[:bold] + @full_line + @controls[:clear],
248
+ @controls[:bold] + @remainder + @filler + @controls[:clear],
249
+ ]
250
+ end
101
251
  end
102
252
 
103
- it 'left justifies' do
104
- c = Column.new('x' * 25, :align => 'right', :width => 10)
105
- c.screen_rows.should == ['x' * 10, 'x' * 10, ' ' * 5 + 'x' * 5]
253
+ context 'right justifies' do
254
+ before :each do
255
+ @text = 'x' * 25
256
+ @full_line = 'x' * 10
257
+ @remainder = 'x' * 5
258
+ @filler = ' ' * 5
259
+ end
260
+
261
+ it 'plain text' do
262
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 10)
263
+ c.screen_rows.should == [@full_line, @full_line, @filler + @remainder]
264
+ end
265
+
266
+ it 'outputs red' do
267
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 10, :color => 'red')
268
+ c.screen_rows.should == [
269
+ @controls[:red] + @full_line + @controls[:clear],
270
+ @controls[:red] + @full_line + @controls[:clear],
271
+ @controls[:red] + @filler + @remainder + @controls[:clear],
272
+ ]
273
+ end
274
+
275
+ it 'outputs bold' do
276
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :width => 10, :bold => true)
277
+ c.screen_rows.should == [
278
+ @controls[:bold] + @full_line + @controls[:clear],
279
+ @controls[:bold] + @full_line + @controls[:clear],
280
+ @controls[:bold] + @filler + @remainder + @controls[:clear],
281
+ ]
282
+ end
106
283
  end
107
284
 
108
- it 'left justifies' do
109
- c = Column.new('x' * 25, :align => 'center', :width => 10)
110
- c.screen_rows.should == ['x' * 10, 'x' * 10, ' ' * 3 + 'x' * 5 + ' ' * 2]
285
+ context 'center justifies' do
286
+ before :each do
287
+ @text = 'x' * 25
288
+ @full_line = 'x' * 10
289
+ @remainder = 'x' * 5
290
+ @left_filler = ' ' * 3
291
+ @right_filler = ' ' * 2
292
+ end
293
+
294
+ it 'plain text' do
295
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 10)
296
+ c.screen_rows.should == [@full_line, @full_line, ' ' * 3 + @remainder + @right_filler]
297
+ end
298
+
299
+ it 'outputs red' do
300
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 10, :color => 'red')
301
+ c.screen_rows.should == [
302
+ @controls[:red] + @full_line + @controls[:clear],
303
+ @controls[:red] + @full_line + @controls[:clear],
304
+ @controls[:red] + @left_filler + @remainder + @right_filler + @controls[:clear],
305
+ ]
306
+ end
307
+
308
+ it 'outputs bold' do
309
+ c = CommandLineReporter::Column.new(@text, :align => 'center', :width => 10, :bold => true)
310
+ c.screen_rows.should == [
311
+ @controls[:bold] + @full_line + @controls[:clear],
312
+ @controls[:bold] + @full_line + @controls[:clear],
313
+ @controls[:bold] + @left_filler + @remainder + @right_filler + @controls[:clear],
314
+ ]
315
+ end
111
316
  end
112
317
  end
113
318
 
114
319
  context 'account for padding' do
115
- it 'left justifies' do
116
- c = Column.new('x' * 25, :padding => 2, :width => 20)
117
- c.screen_rows.should == [' ' * 2 + 'x' * 16 + ' ' * 2, ' ' * 2 + 'x' * 9 + ' ' * 9]
320
+ context 'left justifies' do
321
+ before :each do
322
+ @text = 'x' * 25
323
+ @full_line = 'x' * 16
324
+ @remainder = 'x' * 9
325
+ @padding = ' ' * 2
326
+ @filler = ' ' * 7
327
+ end
328
+
329
+ it 'plain text' do
330
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :width => 20)
331
+ c.screen_rows.should == [
332
+ @padding + @full_line + @padding,
333
+ @padding + @remainder + @filler + @padding,
334
+ ]
335
+ end
336
+
337
+ it 'outputs red' do
338
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :width => 20, :color => 'red')
339
+ c.screen_rows.should == [
340
+ @padding + @controls[:red] + @full_line + @controls[:clear] + @padding,
341
+ @padding + @controls[:red] + @remainder + @filler + @controls[:clear] + @padding,
342
+ ]
343
+ end
344
+
345
+ it 'outputs bold' do
346
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :width => 20, :bold => true)
347
+ c.screen_rows.should == [
348
+ @padding + @controls[:bold] + @full_line + @controls[:clear] + @padding,
349
+ @padding + @controls[:bold] + @remainder + @filler + @controls[:clear] + @padding,
350
+ ]
351
+ end
118
352
  end
119
353
 
120
- it 'right justifies' do
121
- c = Column.new('x' * 25, :padding => 2, :align => 'right', :width => 20)
122
- c.screen_rows.should == [' ' * 2 + 'x' * 16 + ' ' * 2, ' ' * 9 + 'x' * 9 + ' ' * 2]
354
+ context 'right justifies' do
355
+ before :each do
356
+ @text = 'x' * 25
357
+ @full_line = 'x' * 16
358
+ @remainder = 'x' * 9
359
+ @padding = ' ' * 2
360
+ @filler = ' ' * 7
361
+ end
362
+
363
+ it 'plain text' do
364
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :align => 'right', :width => 20)
365
+ c.screen_rows.should == [
366
+ @padding + @full_line + @padding,
367
+ @padding + @filler + @remainder + @padding,
368
+ ]
369
+ end
370
+
371
+ it 'outputs red' do
372
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :padding => 2, :width => 20, :color => 'red')
373
+ c.screen_rows.should == [
374
+ @padding + @controls[:red] + @full_line + @controls[:clear] + @padding,
375
+ @padding + @controls[:red] + @filler + @remainder + @controls[:clear] + @padding,
376
+ ]
377
+ end
378
+
379
+ it 'outputs bold' do
380
+ c = CommandLineReporter::Column.new(@text, :align => 'right', :padding => 2, :width => 20, :bold => true)
381
+ c.screen_rows.should == [
382
+ @padding + @controls[:bold] + @full_line + @controls[:clear] + @padding,
383
+ @padding + @controls[:bold] + @filler + @remainder + @controls[:clear] + @padding,
384
+ ]
385
+ end
123
386
  end
124
387
 
125
- it 'center justifies' do
126
- c = Column.new('x' * 25, :padding => 2, :align => 'center', :width => 20)
127
- c.screen_rows.should == [' ' * 2 + 'x' * 16 + ' ' * 2, ' ' * 6 + 'x' * 9 + ' ' * 5]
388
+ context 'center justifies' do
389
+ before :each do
390
+ @text = 'x' * 25
391
+ @full_line = 'x' * 16
392
+ @remainder = 'x' * 9
393
+ @padding = ' ' * 2
394
+ @left_filler = ' ' * 4
395
+ @right_filler = ' ' * 3
396
+ end
397
+
398
+ it 'plain text' do
399
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :align => 'center', :width => 20)
400
+ c.screen_rows.should == [
401
+ @padding + @full_line + @padding,
402
+ @padding + @left_filler + @remainder + @right_filler + @padding,
403
+ ]
404
+ end
405
+
406
+ it 'outputs red' do
407
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :align => 'center', :width => 20, :color => 'red')
408
+ c.screen_rows.should == [
409
+ @padding + @controls[:red] + @full_line + @controls[:clear] + @padding,
410
+ @padding + @controls[:red] + @left_filler + @remainder + @right_filler + @controls[:clear] + @padding,
411
+ ]
412
+ end
413
+
414
+ it 'outputs bold' do
415
+ c = CommandLineReporter::Column.new(@text, :padding => 2, :align => 'center', :width => 20, :bold => true)
416
+ c.screen_rows.should == [
417
+ @padding + @controls[:bold] + @full_line + @controls[:clear] + @padding,
418
+ @padding + @controls[:bold] + @left_filler + @remainder + @right_filler + @controls[:clear] + @padding,
419
+ ]
420
+ end
128
421
  end
129
422
  end
130
423
  end
@@ -14,6 +14,14 @@ describe CommandLineReporter do
14
14
  @timestamp_regex = /\d{4}-\d{2}-\d{2} - (\d| )\d:\d{2}:\d{2}[AP]M/
15
15
  end
16
16
 
17
+ before :all do
18
+ @controls = {
19
+ :clear => "\e[0m",
20
+ :bold => "\e[1m",
21
+ :red => "\e[31m",
22
+ }
23
+ end
24
+
17
25
  describe '#formatter=' do
18
26
  it 'only allows allowed formatters' do
19
27
  expect {
@@ -120,6 +128,20 @@ describe CommandLineReporter do
120
128
  subject.header(:timestamp => true)
121
129
  }.to_not raise_error ArgumentError
122
130
  end
131
+
132
+ it 'accepts color' do
133
+ expect {
134
+ subject.should_receive(:puts).any_number_of_times
135
+ subject.header(:color => 'red')
136
+ }.to_not raise_error ArgumentError
137
+ end
138
+
139
+ it 'accepts bold' do
140
+ expect {
141
+ subject.should_receive(:puts).any_number_of_times
142
+ subject.header(:bold => true)
143
+ }.to_not raise_error ArgumentError
144
+ end
123
145
  end
124
146
 
125
147
  context 'alignment' do
@@ -216,6 +238,36 @@ describe CommandLineReporter do
216
238
  subject.header(:rule => '=')
217
239
  end
218
240
  end
241
+
242
+ context 'color' do
243
+ it 'single red line' do
244
+ subject.should_receive(:puts).with(@controls[:red] + 'Report' + @controls[:clear])
245
+ subject.should_receive(:puts)
246
+ subject.header(:color => 'red')
247
+ end
248
+
249
+ it 'multimple red lines' do
250
+ subject.should_receive(:puts).with(@controls[:red] + 'Report' + @controls[:clear])
251
+ subject.should_receive(:puts).with(@controls[:red] + '-' * 100 + @controls[:clear])
252
+ subject.should_receive(:puts)
253
+ subject.header(:color => 'red', :rule => true)
254
+ end
255
+ end
256
+
257
+ context 'bold' do
258
+ it 'single line' do
259
+ subject.should_receive(:puts).with(@controls[:bold] + 'Report' + @controls[:clear])
260
+ subject.should_receive(:puts)
261
+ subject.header(:bold => true)
262
+ end
263
+
264
+ it 'multimple lines' do
265
+ subject.should_receive(:puts).with(@controls[:bold] + 'Report' + @controls[:clear])
266
+ subject.should_receive(:puts).with(@controls[:bold] + '-' * 100 + @controls[:clear])
267
+ subject.should_receive(:puts)
268
+ subject.header(:bold => true, :rule => true)
269
+ end
270
+ end
219
271
  end
220
272
 
221
273
  describe '#horizontal_rule' do
@@ -257,6 +309,16 @@ describe CommandLineReporter do
257
309
  subject.horizontal_rule(:char => '=', :width => 50)
258
310
  end
259
311
  end
312
+
313
+ it 'outputs color' do
314
+ subject.should_receive(:puts).with(@controls[:red] + '-' * 100 + @controls[:clear])
315
+ subject.horizontal_rule(:color => 'red')
316
+ end
317
+
318
+ it 'outputs bold' do
319
+ subject.should_receive(:puts).with(@controls[:bold] + '-' * 100 + @controls[:clear])
320
+ subject.horizontal_rule(:bold => true)
321
+ end
260
322
  end
261
323
 
262
324
  describe '#vertical_spacing' do
@@ -341,6 +403,16 @@ describe CommandLineReporter do
341
403
  subject.datetime(:format => '%y/%m/%d')
342
404
  end
343
405
  end
406
+
407
+ it 'outputs color' do
408
+ subject.should_receive(:puts).with(/^\e\[31m#{@timestamp_regex}\e\[0m/)
409
+ subject.datetime(:color => 'red')
410
+ end
411
+
412
+ it 'outputs bold' do
413
+ subject.should_receive(:puts).with(/^\e\[1m#{@timestamp_regex}\e\[0m/)
414
+ subject.datetime(:bold => true)
415
+ end
344
416
  end
345
417
 
346
418
  describe '#aligned' do
@@ -371,6 +443,17 @@ describe CommandLineReporter do
371
443
  }.to raise_error
372
444
  end
373
445
  end
446
+
447
+ it 'outputs color' do
448
+ subject.should_receive(:puts).with(@controls[:red] + 'x' * 10 + @controls[:clear])
449
+ subject.aligned('x' * 10, :color => 'red')
450
+ end
451
+
452
+ it 'outputs bold' do
453
+ subject.should_receive(:puts).with(@controls[:bold] + 'x' * 10 + @controls[:clear])
454
+ subject.aligned('x' * 10, :bold => true)
455
+ end
456
+
374
457
  end
375
458
 
376
459
  describe '#footer' do
@@ -490,14 +573,14 @@ describe CommandLineReporter do
490
573
  subject.should_receive(:puts).with("\n")
491
574
  subject.should_receive(:puts).with(/^ *title$/)
492
575
  subject.should_receive(:puts).with(/^ *#{@timestamp_regex}$/)
493
- subject.header(:title => 'title', :align => 'right', :timestamp => true, :width => 80)
576
+ subject.footer(:title => 'title', :align => 'right', :timestamp => true, :width => 80)
494
577
  end
495
578
 
496
579
  it 'added with center alignment' do
497
580
  subject.should_receive(:puts).with("\n")
498
581
  subject.should_receive(:puts).with(/^ *title *$/)
499
582
  subject.should_receive(:puts).with(/^ *#{@timestamp_regex} *$/)
500
- subject.header(:title => 'title', :align => 'center', :timestamp => true, :width => 80)
583
+ subject.footer(:title => 'title', :align => 'center', :timestamp => true, :width => 80)
501
584
  end
502
585
  end
503
586
 
@@ -516,6 +599,20 @@ describe CommandLineReporter do
516
599
  subject.footer(:rule => '=')
517
600
  end
518
601
  end
602
+
603
+ it 'outputs red' do
604
+ subject.should_receive(:puts).with("\n")
605
+ subject.should_receive(:puts).with(@controls[:red] + 'title' + @controls[:clear])
606
+ subject.should_receive(:puts).with(/^\e\[31m#{@timestamp_regex}\e\[0m/)
607
+ subject.footer(:title => 'title', :timestamp => true, :color => 'red')
608
+ end
609
+
610
+ it 'outputs bold' do
611
+ subject.should_receive(:puts).with("\n")
612
+ subject.should_receive(:puts).with(@controls[:bold] + 'title' + @controls[:clear])
613
+ subject.should_receive(:puts).with(/^\e\[1m#{@timestamp_regex}\e\[0m/)
614
+ subject.footer(:title => 'title', :timestamp => true, :bold => true)
615
+ end
519
616
  end
520
617
 
521
618
  describe '#table' do
@@ -523,7 +620,6 @@ describe CommandLineReporter do
523
620
  subject.should_receive(:puts).any_number_of_times
524
621
  subject.should_receive(:table).once
525
622
  subject.table { }
526
- # subject.instance_variable_get(:@table).should_not be_nil
527
623
  end
528
624
 
529
625
  it 'requires a row to be defined' do
@@ -540,6 +636,7 @@ describe CommandLineReporter do
540
636
 
541
637
  it 'rejects invalid options' do
542
638
  expect {
639
+ subject.should_receive(:puts).any_number_of_times
543
640
  subject.table(:asdf => '100') { }
544
641
  }.to raise_error ArgumentError
545
642
  end
@@ -572,6 +669,9 @@ describe CommandLineReporter do
572
669
  end
573
670
 
574
671
  it 'accepts valid options' do
672
+ subject.should_receive(:column).once
673
+ subject.should_receive(:puts).any_number_of_times
674
+
575
675
  subject.table do
576
676
  subject.row do
577
677
  subject.column('asdf', :width => 30)
@@ -580,6 +680,7 @@ describe CommandLineReporter do
580
680
  end
581
681
 
582
682
  it 'rejects invalid options' do
683
+ subject.should_receive(:puts).any_number_of_times
583
684
  expect {
584
685
  subject.table do
585
686
  subject.row do