command_line_reporter 4.0.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/column_spec.rb DELETED
@@ -1,521 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CommandLineReporter::Column do
4
- subject { CommandLineReporter::Column }
5
-
6
- def screen_rows(args = {})
7
- described_class.new(text, {width: 5}.merge(args)).screen_rows
8
- end
9
-
10
- context '#initialize' do
11
- it 'rejects invalid options' do
12
- expect do
13
- subject.new('test', asdf: '1234')
14
- end.to raise_error ArgumentError
15
- end
16
-
17
- it 'defaults options hash' do
18
- expect do
19
- subject.new('test')
20
- end.to_not raise_error Exception
21
- end
22
-
23
- it 'defaults the width' do
24
- c = subject.new('test')
25
- expect(c.width).to eq(10)
26
- end
27
-
28
- it 'accepts the width' do
29
- c = subject.new('test', width: 50)
30
- expect(c.width).to eq(50)
31
- end
32
-
33
- it 'requires valid width' do
34
- expect do
35
- subject.new('test', width: 'asdf')
36
- end.to raise_error ArgumentError
37
- end
38
-
39
- it 'accepts text' do
40
- c = subject.new('asdf')
41
- expect(c.text).to eq('asdf')
42
- end
43
-
44
- it 'accepts color' do
45
- c = subject.new('asdf', color: 'red')
46
- expect(c.color).to eq('red')
47
- end
48
-
49
- it 'accepts bold' do
50
- c = subject.new('asdf', bold: true)
51
- expect(c.bold).to be true
52
- end
53
-
54
- it 'defaults the padding' do
55
- c = subject.new('test')
56
- expect(c.padding).to eq(0)
57
- end
58
-
59
- it 'accepts the padding' do
60
- c = subject.new('test', padding: 5)
61
- expect(c.padding).to eq(5)
62
- end
63
-
64
- it 'requires valid width' do
65
- expect do
66
- subject.new('test', padding: 'asdf')
67
- end.to raise_error ArgumentError
68
- end
69
- end
70
-
71
- context '#size' do
72
- it 'should have default width' do
73
- c = subject.new('test')
74
- expect(c.size).to eq(10)
75
- end
76
-
77
- it 'should have custom width' do
78
- c = subject.new('test', width: 5)
79
- expect(c.size).to eq(5)
80
- end
81
-
82
- it 'should be reduced by the padding' do
83
- c = subject.new('test', width: 5, padding: 1)
84
- expect(c.size).to eq(3)
85
- end
86
- end
87
-
88
- context '#required_width' do
89
- it 'is the length of the text plus twice the padding' do
90
- c = subject.new('test')
91
- expect(c.required_width).to eq(4)
92
- end
93
-
94
- it 'should be length of string plus twice default padding' do
95
- c = subject.new('test', padding: 1)
96
- expect(c.required_width).to eq(6)
97
- end
98
-
99
- it 'should be length of string plus twice custom padding' do
100
- c = subject.new('test', padding: 5)
101
- expect(c.required_width).to eq(14)
102
- end
103
- end
104
-
105
- context 'spanning columns' do
106
- it 'should adjust width for 2 default columns' do
107
- col = subject.new('test', span: 2)
108
- expect(col.width).to eq(20)
109
- expect(col.size).to eq(23)
110
- end
111
-
112
- it 'should adjust width for 2 custom sized columns' do
113
- col = subject.new('test', width: 20, span: 2)
114
- expect(col.width).to eq(40)
115
- expect(col.size).to eq(43)
116
- end
117
-
118
- it 'should adjust width for 3 default columns' do
119
- col = subject.new('test', span: 3)
120
- expect(col.width).to eq(30)
121
- expect(col.size).to eq(36)
122
- end
123
-
124
- it 'should adjust width for 3 custom sized columns' do
125
- col = subject.new('test', width: 20, span: 3)
126
- expect(col.width).to eq(60)
127
- expect(col.size).to eq(66)
128
- end
129
-
130
- it 'should adjust width for 4 default columns' do
131
- col = subject.new('test', span: 4)
132
- expect(col.width).to eq(40)
133
- expect(col.size).to eq(49)
134
- end
135
-
136
- it 'should adjust width for 2 custom sized columns' do
137
- col = subject.new('test', width: 20, span: 4)
138
- expect(col.width).to eq(80)
139
- expect(col.size).to eq(89)
140
- end
141
- end
142
-
143
- context '#screen_rows' do
144
- let :controls do
145
- {
146
- clear: "\e[0m",
147
- bold: "\e[1m",
148
- red: "\e[31m"
149
- }
150
- end
151
-
152
- context 'no wrapping' do
153
- context 'no padding' do
154
- it 'gives a single row' do
155
- c = subject.new('x' * 5)
156
- c.screen_rows.size == 1
157
- end
158
-
159
- it 'handles empty text' do
160
- c = subject.new
161
- expect(c.screen_rows[0]).to eq(' ' * 10)
162
- end
163
-
164
- context 'left justifies' do
165
- let(:text) { 'x' * 10 }
166
- let(:filler) { ' ' * 10 }
167
-
168
- it 'plain text' do
169
- c = subject.new(text, width: 20)
170
- expect(c.screen_rows[0]).to eq(text + filler)
171
- end
172
-
173
- it 'outputs red' do
174
- c = subject.new(text, align: 'left', width: 20, color: 'red')
175
- expect(c.screen_rows[0]).to eq(controls[:red] + text + filler + controls[:clear])
176
- end
177
-
178
- it 'outputs bold' do
179
- c = subject.new(text, align: 'left', width: 20, bold: true)
180
- expect(c.screen_rows[0]).to eq(controls[:bold] + text + filler + controls[:clear])
181
- end
182
- end
183
-
184
- context 'right justifies' do
185
- let(:text) { 'x' * 10 }
186
- let(:filler) { ' ' * 10 }
187
-
188
- it 'plain text' do
189
- c = subject.new(text, align: 'right', width: 20)
190
- expect(c.screen_rows[0]).to eq(filler + text)
191
- end
192
-
193
- it 'outputs red' do
194
- c = subject.new(text, align: 'right', width: 20, color: 'red')
195
- expect(c.screen_rows[0]).to eq(controls[:red] + filler + text + controls[:clear])
196
- end
197
-
198
- it 'outputs bold' do
199
- c = subject.new(text, align: 'right', width: 20, bold: true)
200
- expect(c.screen_rows[0]).to eq(controls[:bold] + filler + text + controls[:clear])
201
- end
202
- end
203
-
204
- context 'center justifies' do
205
- let(:text) { 'x' * 10 }
206
- let(:filler) { ' ' * 5 }
207
-
208
- it 'plain text' do
209
- c = subject.new(text, align: 'center', width: 20)
210
- expect(c.screen_rows[0]).to eq(filler + text + filler)
211
- end
212
-
213
- it 'outputs red' do
214
- c = subject.new(text, align: 'center', width: 20, color: 'red')
215
- expect(c.screen_rows[0]).to eq(controls[:red] + filler + text + filler + controls[:clear])
216
- end
217
-
218
- it 'outputs bold' do
219
- c = subject.new(text, align: 'center', width: 20, bold: true)
220
- expect(c.screen_rows[0]).to eq(controls[:bold] + filler + text + filler + controls[:clear])
221
- end
222
- end
223
- end
224
-
225
- context 'accounts for padding' do
226
- context 'left justifies' do
227
- let(:text) { 'x' * 10 }
228
- let(:padding) { ' ' * 5 }
229
- let(:filler) { ' ' * 10 }
230
-
231
- it 'plain text' do
232
- c = subject.new(text, padding: 5, width: 30)
233
- expect(c.screen_rows[0]).to eq(padding + text + filler + padding)
234
- end
235
-
236
- it 'outputs red' do
237
- c = subject.new(text, padding: 5, width: 30, color: 'red')
238
- expect(c.screen_rows[0]).to eq(padding + controls[:red] + text + filler + controls[:clear] + padding)
239
- end
240
-
241
- it 'outputs bold' do
242
- c = subject.new(text, padding: 5, width: 30, bold: true)
243
- expect(c.screen_rows[0]).to eq(padding + controls[:bold] + text + filler + controls[:clear] + padding)
244
- end
245
- end
246
-
247
- context 'right justifies' do
248
- let(:text) { 'x' * 10 }
249
- let(:padding) { ' ' * 5 }
250
- let(:filler) { ' ' * 10 }
251
-
252
- it 'plain text' do
253
- c = subject.new(text, align: 'right', padding: 5, width: 30)
254
- expect(c.screen_rows[0]).to eq(padding + filler + text + padding)
255
- end
256
-
257
- it 'outputs red' do
258
- c = subject.new(text, align: 'right', padding: 5, width: 30, color: 'red')
259
- expect(c.screen_rows[0]).to eq(padding + controls[:red] + filler + text + controls[:clear] + padding)
260
- end
261
-
262
- it 'outputs bold' do
263
- c = subject.new(text, align: 'right', padding: 5, width: 30, bold: true)
264
- expect(c.screen_rows[0]).to eq(padding + controls[:bold] + filler + text + controls[:clear] + padding)
265
- end
266
- end
267
-
268
- context 'right justifies' do
269
- let(:text) { 'x' * 10 }
270
- let(:padding) { ' ' * 5 }
271
- let(:filler) { ' ' * 5 }
272
-
273
- it 'plain text' do
274
- c = subject.new(text, align: 'center', padding: 5, width: 30)
275
- expect(c.screen_rows[0]).to eq(padding + filler + text + filler + padding)
276
- end
277
-
278
- it 'outputs red' do
279
- c = subject.new(text, align: 'center', padding: 5, width: 30, color: 'red')
280
- expect(c.screen_rows[0]).to eq(padding + controls[:red] + filler + text + filler + controls[:clear] + padding)
281
- end
282
-
283
- it 'outputs bold' do
284
- c = subject.new(text, align: 'center', padding: 5, width: 30, bold: true)
285
- expect(c.screen_rows[0]).to eq(padding + controls[:bold] + filler + text + filler + controls[:clear] + padding)
286
- end
287
- end
288
- end
289
- end
290
-
291
- context 'with wrapping' do
292
- context 'no padding' do
293
- context 'left justifies' do
294
- let(:text) { "one cooperative\n\nbag copy" }
295
-
296
- describe 'line-breaks' do
297
- it 'do not break output' do
298
- expect(screen_rows(width: 20)).to eq(['one cooperative ', ' ' * 20, 'bag copy '])
299
- end
300
- end
301
-
302
- describe 'wrap: word' do
303
- it 'tries to break lines between words' do
304
- expect(screen_rows(wrap: :word)).to eq(['one ', 'coope', 'rativ', 'e ', ' ', 'bag ', 'copy '])
305
- end
306
- end
307
-
308
- describe 'wrap: character' do
309
- it 'uses "character"-based wrapping by default' do
310
- expect(screen_rows).to eq(screen_rows(wrap: :character))
311
- end
312
-
313
- it 'ignores word-breaks' do
314
- expect(screen_rows).to eq(['one c', 'ooper', 'ative', ' ', ' ', 'bag c', 'opy '])
315
- end
316
- end
317
-
318
- it 'outputs color' do
319
- screen_rows(color: 'red').each do |row|
320
- expect(row).to start_with(controls[:red])
321
- expect(row).to end_with(controls[:clear])
322
- end
323
- end
324
-
325
- it 'outputs bold' do
326
- screen_rows(bold: true).each do |row|
327
- expect(row).to start_with(controls[:bold])
328
- expect(row).to end_with(controls[:clear])
329
- end
330
- end
331
- end
332
-
333
- context 'right justifies' do
334
- let(:text) { 'x' * 25 }
335
- let(:full_line) { 'x' * 10 }
336
- let(:remainder) { 'x' * 5 }
337
- let(:filler) { ' ' * 5 }
338
-
339
- it 'plain text' do
340
- c = subject.new(text, align: 'right', width: 10)
341
- expect(c.screen_rows).to eq([full_line, full_line, filler + remainder])
342
- end
343
-
344
- it 'outputs red' do
345
- c = subject.new(text, align: 'right', width: 10, color: 'red')
346
- expect(c.screen_rows).to eq(
347
- [
348
- controls[:red] + full_line + controls[:clear],
349
- controls[:red] + full_line + controls[:clear],
350
- controls[:red] + filler + remainder + controls[:clear]
351
- ]
352
- )
353
- end
354
-
355
- it 'outputs bold' do
356
- c = subject.new(text, align: 'right', width: 10, bold: true)
357
- expect(c.screen_rows).to eq(
358
- [
359
- controls[:bold] + full_line + controls[:clear],
360
- controls[:bold] + full_line + controls[:clear],
361
- controls[:bold] + filler + remainder + controls[:clear]
362
- ]
363
- )
364
- end
365
- end
366
-
367
- context 'center justifies' do
368
- let(:text) { 'x' * 25 }
369
- let(:full_line) { 'x' * 10 }
370
- let(:remainder) { 'x' * 5 }
371
- let(:left_filler) { ' ' * 3 }
372
- let(:right_filler) { ' ' * 2 }
373
-
374
- it 'plain text' do
375
- c = subject.new(text, align: 'center', width: 10)
376
- expect(c.screen_rows).to eq([full_line, full_line, ' ' * 3 + remainder + right_filler])
377
- end
378
-
379
- it 'outputs red' do
380
- c = subject.new(text, align: 'center', width: 10, color: 'red')
381
- expect(c.screen_rows).to eq(
382
- [
383
- controls[:red] + full_line + controls[:clear],
384
- controls[:red] + full_line + controls[:clear],
385
- controls[:red] + left_filler + remainder + right_filler + controls[:clear]
386
- ]
387
- )
388
- end
389
-
390
- it 'outputs bold' do
391
- c = subject.new(text, align: 'center', width: 10, bold: true)
392
- expect(c.screen_rows).to eq(
393
- [
394
- controls[:bold] + full_line + controls[:clear],
395
- controls[:bold] + full_line + controls[:clear],
396
- controls[:bold] + left_filler + remainder + right_filler + controls[:clear]
397
- ]
398
- )
399
- end
400
- end
401
- end
402
-
403
- context 'account for padding' do
404
- context 'left justifies' do
405
- let(:text) { 'x' * 25 }
406
- let(:full_line) { 'x' * 16 }
407
- let(:remainder) { 'x' * 9 }
408
- let(:padding) { ' ' * 2 }
409
- let(:filler) { ' ' * 7 }
410
-
411
- it 'plain text' do
412
- c = subject.new(text, padding: 2, width: 20)
413
- expect(c.screen_rows).to eq(
414
- [
415
- padding + full_line + padding,
416
- padding + remainder + filler + padding
417
- ]
418
- )
419
- end
420
-
421
- it 'outputs red' do
422
- c = subject.new(text, padding: 2, width: 20, color: 'red')
423
- expect(c.screen_rows).to eq(
424
- [
425
- padding + controls[:red] + full_line + controls[:clear] + padding,
426
- padding + controls[:red] + remainder + filler + controls[:clear] + padding
427
- ]
428
- )
429
- end
430
-
431
- it 'outputs bold' do
432
- c = subject.new(text, padding: 2, width: 20, bold: true)
433
- expect(c.screen_rows).to eq(
434
- [
435
- padding + controls[:bold] + full_line + controls[:clear] + padding,
436
- padding + controls[:bold] + remainder + filler + controls[:clear] + padding
437
- ]
438
- )
439
- end
440
- end
441
-
442
- context 'right justifies' do
443
- let(:text) { 'x' * 25 }
444
- let(:full_line) { 'x' * 16 }
445
- let(:remainder) { 'x' * 9 }
446
- let(:padding) { ' ' * 2 }
447
- let(:filler) { ' ' * 7 }
448
-
449
- it 'plain text' do
450
- c = subject.new(text, padding: 2, align: 'right', width: 20)
451
- expect(c.screen_rows).to eq(
452
- [
453
- padding + full_line + padding,
454
- padding + filler + remainder + padding
455
- ]
456
- )
457
- end
458
-
459
- it 'outputs red' do
460
- c = subject.new(text, align: 'right', padding: 2, width: 20, color: 'red')
461
- expect(c.screen_rows).to eq(
462
- [
463
- padding + controls[:red] + full_line + controls[:clear] + padding,
464
- padding + controls[:red] + filler + remainder + controls[:clear] + padding
465
- ]
466
- )
467
- end
468
-
469
- it 'outputs bold' do
470
- c = subject.new(text, align: 'right', padding: 2, width: 20, bold: true)
471
- expect(c.screen_rows).to eq(
472
- [
473
- padding + controls[:bold] + full_line + controls[:clear] + padding,
474
- padding + controls[:bold] + filler + remainder + controls[:clear] + padding
475
- ]
476
- )
477
- end
478
- end
479
-
480
- context 'center justifies' do
481
- let(:text) { 'x' * 25 }
482
- let(:full_line) { 'x' * 16 }
483
- let(:remainder) { 'x' * 9 }
484
- let(:padding) { ' ' * 2 }
485
- let(:left_filler) { ' ' * 4 }
486
- let(:right_filler) { ' ' * 3 }
487
-
488
- it 'plain text' do
489
- c = subject.new(text, padding: 2, align: 'center', width: 20)
490
- expect(c.screen_rows).to eq(
491
- [
492
- padding + full_line + padding,
493
- padding + left_filler + remainder + right_filler + padding
494
- ]
495
- )
496
- end
497
-
498
- it 'outputs red' do
499
- c = subject.new(text, padding: 2, align: 'center', width: 20, color: 'red')
500
- expect(c.screen_rows).to eq(
501
- [
502
- padding + controls[:red] + full_line + controls[:clear] + padding,
503
- padding + controls[:red] + left_filler + remainder + right_filler + controls[:clear] + padding
504
- ]
505
- )
506
- end
507
-
508
- it 'outputs bold' do
509
- c = subject.new(text, padding: 2, align: 'center', width: 20, bold: true)
510
- expect(c.screen_rows).to eq(
511
- [
512
- padding + controls[:bold] + full_line + controls[:clear] + padding,
513
- padding + controls[:bold] + left_filler + remainder + right_filler + controls[:clear] + padding
514
- ]
515
- )
516
- end
517
- end
518
- end
519
- end
520
- end
521
- end