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.
- checksums.yaml +4 -4
- data/lib/command_line_reporter/column.rb +12 -8
- data/lib/command_line_reporter/formatter/nested.rb +5 -2
- data/lib/command_line_reporter/formatter/progress.rb +2 -2
- data/lib/command_line_reporter/row.rb +4 -2
- data/lib/command_line_reporter/table.rb +28 -25
- data/lib/command_line_reporter/version.rb +1 -1
- data/lib/command_line_reporter.rb +12 -5
- metadata +15 -50
- data/spec/column_spec.rb +0 -521
- data/spec/command_line_reporter_spec.rb +0 -693
- data/spec/nested_formatter_spec.rb +0 -301
- data/spec/options_validator_spec.rb +0 -24
- data/spec/progress_formatter_spec.rb +0 -74
- data/spec/row_spec.rb +0 -131
- data/spec/spec_helper.rb +0 -6
- data/spec/support/helpers/stdout.rb +0 -8
- data/spec/support/matchers/argument.rb +0 -5
- data/spec/table_spec.rb +0 -171
|
@@ -1,693 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe CommandLineReporter do
|
|
4
|
-
let :use_class do
|
|
5
|
-
Class.new do
|
|
6
|
-
include CommandLineReporter
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
let(:timestamp_regex) { /\d{4}-\d{2}-\d{2} - (\d| )\d:\d{2}:\d{2}[AP]M/ }
|
|
11
|
-
|
|
12
|
-
let :controls do
|
|
13
|
-
{
|
|
14
|
-
clear: "\e[0m",
|
|
15
|
-
bold: "\e[1m",
|
|
16
|
-
red: "\e[31m"
|
|
17
|
-
}
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
let(:linechar) { "\u2501" == 'u2501' ? '-' : "\u2501" }
|
|
21
|
-
|
|
22
|
-
subject { use_class.new }
|
|
23
|
-
|
|
24
|
-
describe '#formatter=' do
|
|
25
|
-
it 'only allows allowed formatters' do
|
|
26
|
-
expect do
|
|
27
|
-
subject.formatter = 'asfd'
|
|
28
|
-
end.to raise_error ArgumentError
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'specifies the progress formatter' do
|
|
32
|
-
subject.formatter = 'progress'
|
|
33
|
-
expect(subject.formatter.class).to eq(CommandLineReporter::ProgressFormatter)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'specifies the nested formatter' do
|
|
37
|
-
subject.formatter = 'nested'
|
|
38
|
-
expect(subject.formatter.class).to eq(CommandLineReporter::NestedFormatter)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe '#report' do
|
|
43
|
-
it 'uses the nested formatter as default' do
|
|
44
|
-
capture_stdout do
|
|
45
|
-
subject.report {}
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
expect(subject.formatter.class).to eq(CommandLineReporter::NestedFormatter)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'uses the progress formatter' do
|
|
52
|
-
capture_stdout do
|
|
53
|
-
subject.formatter = 'progress'
|
|
54
|
-
subject.report {}
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
expect(subject.formatter.class).to eq(CommandLineReporter::ProgressFormatter)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'does not mask other application errors when a formatter is not set' do
|
|
61
|
-
capture_stdout do
|
|
62
|
-
subject.report do
|
|
63
|
-
# rubocop:disable Style/RedundantSelf
|
|
64
|
-
expect { self.some_method_that_does_not_exist }.to raise_error(NoMethodError)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe '#header' do
|
|
71
|
-
context 'argument validation' do
|
|
72
|
-
it 'does not accept an invalid option' do
|
|
73
|
-
expect do
|
|
74
|
-
subject.header(asdf: 'tests')
|
|
75
|
-
end.to raise_error ArgumentError
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'accepts a title' do
|
|
79
|
-
expect do
|
|
80
|
-
allow(subject).to receive(:puts)
|
|
81
|
-
subject.header(title: 'test')
|
|
82
|
-
end.to_not raise_error Exception
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'does not allow a title > width' do
|
|
86
|
-
expect do
|
|
87
|
-
subject.header(title: 'xxxxxxxxxxx', width: 5)
|
|
88
|
-
end.to raise_error ArgumentError
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'accepts width' do
|
|
92
|
-
expect do
|
|
93
|
-
allow(subject).to receive(:puts)
|
|
94
|
-
subject.header(width: 100)
|
|
95
|
-
end.to_not raise_error Exception
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'ensure width is a number' do
|
|
99
|
-
expect do
|
|
100
|
-
subject.header(width: 'adf')
|
|
101
|
-
end.to raise_error ArgumentError
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it 'accepts align' do
|
|
105
|
-
expect do
|
|
106
|
-
allow(subject).to receive(:puts)
|
|
107
|
-
subject.header(align: 'center')
|
|
108
|
-
end.to_not raise_error Exception
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'ensure align is a valid value' do
|
|
112
|
-
expect do
|
|
113
|
-
subject.header(align: :asdf)
|
|
114
|
-
end.to raise_error ArgumentError
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it 'accepts spacing' do
|
|
118
|
-
expect do
|
|
119
|
-
allow(subject).to receive(:puts)
|
|
120
|
-
subject.header(spacing: 2)
|
|
121
|
-
end.to_not raise_error Exception
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'accepts timestamp' do
|
|
125
|
-
expect do
|
|
126
|
-
allow(subject).to receive(:puts)
|
|
127
|
-
subject.header(timestamp: true)
|
|
128
|
-
end.to_not raise_error Exception
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'accepts color' do
|
|
132
|
-
expect do
|
|
133
|
-
allow(subject).to receive(:puts)
|
|
134
|
-
subject.header(color: 'red')
|
|
135
|
-
end.to_not raise_error Exception
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it 'accepts bold' do
|
|
139
|
-
expect do
|
|
140
|
-
allow(subject).to receive(:puts)
|
|
141
|
-
subject.header(bold: true)
|
|
142
|
-
end.to_not raise_error Exception
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context 'alignment' do
|
|
147
|
-
before :each do
|
|
148
|
-
@title = 'test11test'
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it 'left aligns title by default' do
|
|
152
|
-
expect(subject).to receive(:puts).with(@title)
|
|
153
|
-
expect(subject).to receive(:puts).with("\n")
|
|
154
|
-
subject.header(title: @title) {}
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it 'left aligns title' do
|
|
158
|
-
expect(subject).to receive(:puts).with(@title)
|
|
159
|
-
expect(subject).to receive(:puts).with("\n")
|
|
160
|
-
subject.header(title: @title, align: 'left') {}
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it 'right aligns title using default width' do
|
|
164
|
-
expect(subject).to receive(:puts).with(' ' * 90 + @title)
|
|
165
|
-
expect(subject).to receive(:puts).with("\n")
|
|
166
|
-
subject.header(title: @title, align: 'right')
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it 'right aligns title using specified width' do
|
|
170
|
-
expect(subject).to receive(:puts).with(' ' * 40 + @title)
|
|
171
|
-
expect(subject).to receive(:puts).with("\n")
|
|
172
|
-
subject.header(title: @title, align: 'right', width: 50)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'center aligns title using default width' do
|
|
176
|
-
expect(subject).to receive(:puts).with(' ' * 45 + @title)
|
|
177
|
-
expect(subject).to receive(:puts).with("\n")
|
|
178
|
-
subject.header(title: @title, align: 'center')
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it 'center aligns title using specified width' do
|
|
182
|
-
expect(subject).to receive(:puts).with(' ' * 35 + @title)
|
|
183
|
-
expect(subject).to receive(:puts).with("\n")
|
|
184
|
-
subject.header(title: @title, align: 'center', width: 80)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
context 'spacing' do
|
|
189
|
-
it 'defaults to a single line of spacing between report' do
|
|
190
|
-
expect(subject).to receive(:puts).with('title')
|
|
191
|
-
expect(subject).to receive(:puts).with("\n")
|
|
192
|
-
subject.header(title: 'title')
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
it 'uses the defined spacing between report' do
|
|
196
|
-
expect(subject).to receive(:puts).with('title')
|
|
197
|
-
expect(subject).to receive(:puts).with("\n" * 3)
|
|
198
|
-
subject.header(title: 'title', spacing: 3)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
context 'timestamp subheading' do
|
|
203
|
-
it 'is added with default alignment' do
|
|
204
|
-
expect(subject).to receive(:puts).with('title')
|
|
205
|
-
expect(subject).to receive(:puts).with(/^#{timestamp_regex}/)
|
|
206
|
-
expect(subject).to receive(:puts).with("\n")
|
|
207
|
-
subject.header(title: 'title', timestamp: true)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it 'added with right alignment' do
|
|
211
|
-
expect(subject).to receive(:puts).with(/^ *title$/)
|
|
212
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex}$/)
|
|
213
|
-
expect(subject).to receive(:puts).with("\n")
|
|
214
|
-
subject.header(title: 'title', align: 'right', timestamp: true, width: 80)
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it 'added with center alignment' do
|
|
218
|
-
expect(subject).to receive(:puts).with(/^ *title *$/)
|
|
219
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex} *$/)
|
|
220
|
-
expect(subject).to receive(:puts).with("\n")
|
|
221
|
-
subject.header(title: 'title', align: 'center', timestamp: true, width: 80)
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
context 'horizontal rule' do
|
|
226
|
-
it 'uses dashes by default' do
|
|
227
|
-
expect(subject).to receive(:puts)
|
|
228
|
-
expect(subject).to receive(:puts).with(linechar * 100)
|
|
229
|
-
expect(subject).to receive(:puts)
|
|
230
|
-
subject.header(rule: true)
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it 'uses = as the rule character' do
|
|
234
|
-
expect(subject).to receive(:puts)
|
|
235
|
-
expect(subject).to receive(:puts).with('=' * 100)
|
|
236
|
-
expect(subject).to receive(:puts)
|
|
237
|
-
subject.header(rule: '=')
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
context 'color' do
|
|
242
|
-
it 'single red line' do
|
|
243
|
-
expect(subject).to receive(:puts).with(controls[:red] + 'Report' + controls[:clear])
|
|
244
|
-
expect(subject).to receive(:puts)
|
|
245
|
-
subject.header(color: 'red')
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it 'multimple red lines' do
|
|
249
|
-
expect(subject).to receive(:puts).with(controls[:red] + 'Report' + controls[:clear])
|
|
250
|
-
expect(subject).to receive(:puts).with(controls[:red] + linechar * 100 + controls[:clear])
|
|
251
|
-
expect(subject).to receive(:puts)
|
|
252
|
-
subject.header(color: 'red', rule: true)
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
context 'bold' do
|
|
257
|
-
it 'single line' do
|
|
258
|
-
expect(subject).to receive(:puts).with(controls[:bold] + 'Report' + controls[:clear])
|
|
259
|
-
expect(subject).to receive(:puts)
|
|
260
|
-
subject.header(bold: true)
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it 'multimple lines' do
|
|
264
|
-
expect(subject).to receive(:puts).with(controls[:bold] + 'Report' + controls[:clear])
|
|
265
|
-
expect(subject).to receive(:puts).with(controls[:bold] + linechar * 100 + controls[:clear])
|
|
266
|
-
expect(subject).to receive(:puts)
|
|
267
|
-
subject.header(bold: true, rule: true)
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
describe '#horizontal_rule' do
|
|
273
|
-
context 'argument validation' do
|
|
274
|
-
it 'does not allow invalid options' do
|
|
275
|
-
expect do
|
|
276
|
-
subject.horizontal_rule(asdf: true)
|
|
277
|
-
end.to raise_error ArgumentError
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it 'accepts char' do
|
|
281
|
-
expect do
|
|
282
|
-
expect(subject).to receive(:puts)
|
|
283
|
-
subject.horizontal_rule(char: '*')
|
|
284
|
-
end.to_not raise_error Exception
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
it 'accepts width' do
|
|
288
|
-
expect do
|
|
289
|
-
expect(subject).to receive(:puts)
|
|
290
|
-
subject.horizontal_rule(width: 10)
|
|
291
|
-
end.to_not raise_error Exception
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
context 'drawing' do
|
|
296
|
-
it 'writes a 100 yard dash by default' do
|
|
297
|
-
expect(subject).to receive(:puts).with(linechar * 100)
|
|
298
|
-
subject.horizontal_rule
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
it 'writes a 100 yard asterisk' do
|
|
302
|
-
expect(subject).to receive(:puts).with('*' * 100)
|
|
303
|
-
subject.horizontal_rule(char: '*')
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it 'writes a 50 yard equals' do
|
|
307
|
-
expect(subject).to receive(:puts).with('=' * 50)
|
|
308
|
-
subject.horizontal_rule(char: '=', width: 50)
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
it 'outputs color' do
|
|
313
|
-
expect(subject).to receive(:puts).with(controls[:red] + linechar * 100 + controls[:clear])
|
|
314
|
-
subject.horizontal_rule(color: 'red')
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
it 'outputs bold' do
|
|
318
|
-
expect(subject).to receive(:puts).with(controls[:bold] + linechar * 100 + controls[:clear])
|
|
319
|
-
subject.horizontal_rule(bold: true)
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
describe '#vertical_spacing' do
|
|
324
|
-
it 'accepts a fixnum as a valid argument' do
|
|
325
|
-
expect do
|
|
326
|
-
subject.vertical_spacing('asdf')
|
|
327
|
-
end.to raise_error ArgumentError
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it 'prints carriage returns for the number of lines' do
|
|
331
|
-
expect(subject).to receive(:print).with("\0").and_return(nil)
|
|
332
|
-
expect(subject).to receive(:puts).with("\n" * 3).and_return("\n\n\n")
|
|
333
|
-
subject.vertical_spacing(0)
|
|
334
|
-
subject.vertical_spacing(3)
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
describe '#datetime' do
|
|
339
|
-
context 'argument validation' do
|
|
340
|
-
it 'does not allow invalid options' do
|
|
341
|
-
expect do
|
|
342
|
-
subject.datetime(asdf: true)
|
|
343
|
-
end.to raise_error ArgumentError
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
it 'accepts align' do
|
|
347
|
-
expect do
|
|
348
|
-
expect(subject).to receive(:puts)
|
|
349
|
-
subject.datetime(align: 'left')
|
|
350
|
-
end.to_not raise_error Exception
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
it 'accepts width' do
|
|
354
|
-
expect do
|
|
355
|
-
expect(subject).to receive(:puts)
|
|
356
|
-
subject.datetime(width: 70)
|
|
357
|
-
end.to_not raise_error Exception
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
it 'accepts format' do
|
|
361
|
-
expect do
|
|
362
|
-
expect(subject).to receive(:puts)
|
|
363
|
-
subject.datetime(format: '%m/%d/%Y')
|
|
364
|
-
end.to_not raise_error Exception
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
it 'does not allow invalid width' do
|
|
368
|
-
expect do
|
|
369
|
-
subject.datetime(align: 'right', width: 'asdf')
|
|
370
|
-
end.to raise_error Exception
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
it 'does not allow invalid align' do
|
|
374
|
-
expect do
|
|
375
|
-
subject.datetime(align: 1234)
|
|
376
|
-
end.to raise_error Exception
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
it 'does not allow a timestamp format larger than the width' do
|
|
380
|
-
expect do
|
|
381
|
-
subject.datetime(width: 8)
|
|
382
|
-
end.to raise_error Exception
|
|
383
|
-
end
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
context 'display' do
|
|
387
|
-
it 'a default format - left aligned' do
|
|
388
|
-
expect(subject).to receive(:puts).with(/^#{timestamp_regex} *$/)
|
|
389
|
-
subject.datetime
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
it 'a default format - right aligned' do
|
|
393
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex}$/)
|
|
394
|
-
subject.datetime(align: 'right')
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
it 'a default format - center aligned' do
|
|
398
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex} *$/)
|
|
399
|
-
subject.datetime(align: 'center')
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
it 'a modified format' do
|
|
403
|
-
expect(subject).to receive(:puts).with(%r/^\d{2}\/\d{2}\/\d{2} *$/)
|
|
404
|
-
subject.datetime(format: '%y/%m/%d')
|
|
405
|
-
end
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
it 'outputs color' do
|
|
409
|
-
expect(subject).to receive(:puts).with(/^\e\[31m#{timestamp_regex}\e\[0m/)
|
|
410
|
-
subject.datetime(color: 'red')
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
it 'outputs bold' do
|
|
414
|
-
expect(subject).to receive(:puts).with(/^\e\[1m#{timestamp_regex}\e\[0m/)
|
|
415
|
-
subject.datetime(bold: true)
|
|
416
|
-
end
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
describe '#aligned' do
|
|
420
|
-
context 'argument validation' do
|
|
421
|
-
it 'accepts align' do
|
|
422
|
-
expect do
|
|
423
|
-
allow(subject).to receive(:puts)
|
|
424
|
-
subject.aligned('test', align: 'left')
|
|
425
|
-
end.to_not raise_error Exception
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
it 'does not allow invalid align values' do
|
|
429
|
-
expect do
|
|
430
|
-
subject.aligned('test', align: 1234)
|
|
431
|
-
end.to raise_error NoMethodError
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
it 'accepts width' do
|
|
435
|
-
expect do
|
|
436
|
-
allow(subject).to receive(:puts)
|
|
437
|
-
subject.aligned('test', width: 40)
|
|
438
|
-
end.to_not raise_error Exception
|
|
439
|
-
end
|
|
440
|
-
|
|
441
|
-
it 'does not allow invalid width values' do
|
|
442
|
-
expect do
|
|
443
|
-
subject.aligned('test', align: 'right', width: 'asdf')
|
|
444
|
-
end.to raise_error Exception
|
|
445
|
-
end
|
|
446
|
-
end
|
|
447
|
-
|
|
448
|
-
it 'outputs color' do
|
|
449
|
-
expect(subject).to receive(:puts).with(controls[:red] + 'x' * 10 + controls[:clear])
|
|
450
|
-
subject.aligned('x' * 10, color: 'red')
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
it 'outputs bold' do
|
|
454
|
-
expect(subject).to receive(:puts).with(controls[:bold] + 'x' * 10 + controls[:clear])
|
|
455
|
-
subject.aligned('x' * 10, bold: true)
|
|
456
|
-
end
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
describe '#footer' do
|
|
460
|
-
context 'argument validation' do
|
|
461
|
-
it 'accepts title' do
|
|
462
|
-
expect do
|
|
463
|
-
allow(subject).to receive(:puts)
|
|
464
|
-
subject.footer(title: 'test')
|
|
465
|
-
end.to_not raise_error Exception
|
|
466
|
-
end
|
|
467
|
-
|
|
468
|
-
it 'accepts align' do
|
|
469
|
-
expect do
|
|
470
|
-
allow(subject).to receive(:puts)
|
|
471
|
-
subject.footer(align: 'right')
|
|
472
|
-
end.to_not raise_error Exception
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
it 'does not accept invalid align' do
|
|
476
|
-
expect do
|
|
477
|
-
subject.header(align: 1234)
|
|
478
|
-
end.to raise_error NoMethodError
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
it 'accepts width' do
|
|
482
|
-
expect do
|
|
483
|
-
allow(subject).to receive(:puts)
|
|
484
|
-
subject.footer(width: 50)
|
|
485
|
-
end.to_not raise_error Exception
|
|
486
|
-
end
|
|
487
|
-
|
|
488
|
-
it 'does not accept invalid width' do
|
|
489
|
-
expect do
|
|
490
|
-
subject.footer(width: 'asdf')
|
|
491
|
-
end.to raise_error ArgumentError
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
it 'does not allow title > width' do
|
|
495
|
-
expect do
|
|
496
|
-
subject.footer(title: 'testtesttest', width: 6)
|
|
497
|
-
end.to raise_error ArgumentError
|
|
498
|
-
end
|
|
499
|
-
|
|
500
|
-
it 'accepts spacing' do
|
|
501
|
-
expect do
|
|
502
|
-
allow(subject).to receive(:puts)
|
|
503
|
-
subject.footer(spacing: 3)
|
|
504
|
-
end.to_not raise_error Exception
|
|
505
|
-
end
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
context 'alignment' do
|
|
509
|
-
before :each do
|
|
510
|
-
@title = 'test12test'
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
it 'left aligns the title by default' do
|
|
514
|
-
expect(subject).to receive(:puts).with("\n")
|
|
515
|
-
expect(subject).to receive(:puts).with(@title)
|
|
516
|
-
subject.footer(title: @title)
|
|
517
|
-
end
|
|
518
|
-
|
|
519
|
-
it 'left aligns the title' do
|
|
520
|
-
expect(subject).to receive(:puts).with("\n")
|
|
521
|
-
expect(subject).to receive(:puts).with(@title)
|
|
522
|
-
subject.footer(title: @title, align: 'left')
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
it 'right aligns the title' do
|
|
526
|
-
expect(subject).to receive(:puts).with("\n")
|
|
527
|
-
expect(subject).to receive(:puts).with(' ' * 90 + @title)
|
|
528
|
-
subject.footer(title: @title, align: 'right')
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
it 'right aligns the title using width' do
|
|
532
|
-
expect(subject).to receive(:puts).with("\n")
|
|
533
|
-
expect(subject).to receive(:puts).with(' ' * 40 + @title)
|
|
534
|
-
subject.footer(title: @title, align: 'right', width: 50)
|
|
535
|
-
end
|
|
536
|
-
|
|
537
|
-
it 'center aligns the title' do
|
|
538
|
-
expect(subject).to receive(:puts).with("\n")
|
|
539
|
-
expect(subject).to receive(:puts).with(' ' * 45 + @title)
|
|
540
|
-
subject.footer(title: @title, align: 'center')
|
|
541
|
-
end
|
|
542
|
-
|
|
543
|
-
it 'center aligns the title using width' do
|
|
544
|
-
expect(subject).to receive(:puts).with("\n")
|
|
545
|
-
expect(subject).to receive(:puts).with(' ' * 35 + @title)
|
|
546
|
-
subject.footer(title: @title, align: 'center', width: 80)
|
|
547
|
-
end
|
|
548
|
-
end
|
|
549
|
-
|
|
550
|
-
context 'spacing' do
|
|
551
|
-
it 'defaults to a single line of spacing between report' do
|
|
552
|
-
expect(subject).to receive(:puts).with("\n")
|
|
553
|
-
expect(subject).to receive(:puts).with('title')
|
|
554
|
-
subject.footer(title: 'title')
|
|
555
|
-
end
|
|
556
|
-
|
|
557
|
-
it 'uses the defined spacing between report' do
|
|
558
|
-
expect(subject).to receive(:puts).with("\n" * 3)
|
|
559
|
-
expect(subject).to receive(:puts).with('title')
|
|
560
|
-
subject.footer(title: 'title', spacing: 3)
|
|
561
|
-
end
|
|
562
|
-
end
|
|
563
|
-
|
|
564
|
-
context 'timestamp subheading' do
|
|
565
|
-
it 'is added with default alignment' do
|
|
566
|
-
expect(subject).to receive(:puts).with("\n")
|
|
567
|
-
expect(subject).to receive(:puts).with('title')
|
|
568
|
-
expect(subject).to receive(:puts).with(/^#{timestamp_regex}/)
|
|
569
|
-
subject.footer(title: 'title', timestamp: true)
|
|
570
|
-
end
|
|
571
|
-
|
|
572
|
-
it 'added with right alignment' do
|
|
573
|
-
expect(subject).to receive(:puts).with("\n")
|
|
574
|
-
expect(subject).to receive(:puts).with(/^ *title$/)
|
|
575
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex}$/)
|
|
576
|
-
subject.footer(title: 'title', align: 'right', timestamp: true, width: 80)
|
|
577
|
-
end
|
|
578
|
-
|
|
579
|
-
it 'added with center alignment' do
|
|
580
|
-
expect(subject).to receive(:puts).with("\n")
|
|
581
|
-
expect(subject).to receive(:puts).with(/^ *title *$/)
|
|
582
|
-
expect(subject).to receive(:puts).with(/^ *#{timestamp_regex} *$/)
|
|
583
|
-
subject.footer(title: 'title', align: 'center', timestamp: true, width: 80)
|
|
584
|
-
end
|
|
585
|
-
end
|
|
586
|
-
|
|
587
|
-
context 'horizontal rule' do
|
|
588
|
-
it 'uses dashes by default' do
|
|
589
|
-
expect(subject).to receive(:puts)
|
|
590
|
-
expect(subject).to receive(:puts).with(linechar * 100)
|
|
591
|
-
expect(subject).to receive(:puts)
|
|
592
|
-
subject.footer(rule: true)
|
|
593
|
-
end
|
|
594
|
-
|
|
595
|
-
it 'uses = as the rule character' do
|
|
596
|
-
expect(subject).to receive(:puts)
|
|
597
|
-
expect(subject).to receive(:puts).with('=' * 100)
|
|
598
|
-
expect(subject).to receive(:puts)
|
|
599
|
-
subject.footer(rule: '=')
|
|
600
|
-
end
|
|
601
|
-
end
|
|
602
|
-
|
|
603
|
-
it 'outputs red' do
|
|
604
|
-
expect(subject).to receive(:puts).with("\n")
|
|
605
|
-
expect(subject).to receive(:puts).with(controls[:red] + 'title' + controls[:clear])
|
|
606
|
-
expect(subject).to 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
|
-
expect(subject).to receive(:puts).with("\n")
|
|
612
|
-
expect(subject).to receive(:puts).with(controls[:bold] + 'title' + controls[:clear])
|
|
613
|
-
expect(subject).to receive(:puts).with(/^\e\[1m#{timestamp_regex}\e\[0m/)
|
|
614
|
-
subject.footer(title: 'title', timestamp: true, bold: true)
|
|
615
|
-
end
|
|
616
|
-
end
|
|
617
|
-
|
|
618
|
-
describe '#table' do
|
|
619
|
-
it 'instantiates the table class' do
|
|
620
|
-
allow(subject).to receive(:puts)
|
|
621
|
-
expect(subject).to receive(:table).once
|
|
622
|
-
subject.table {}
|
|
623
|
-
end
|
|
624
|
-
|
|
625
|
-
it 'requires a row to be defined' do
|
|
626
|
-
expect do
|
|
627
|
-
subject.table
|
|
628
|
-
end.to raise_error LocalJumpError
|
|
629
|
-
end
|
|
630
|
-
|
|
631
|
-
it 'accepts valid options' do
|
|
632
|
-
expect do
|
|
633
|
-
subject.table(border: true) {}
|
|
634
|
-
end.to_not raise_error Exception
|
|
635
|
-
end
|
|
636
|
-
|
|
637
|
-
it 'rejects invalid options' do
|
|
638
|
-
expect do
|
|
639
|
-
allow(subject).to receive(:puts)
|
|
640
|
-
subject.table(asdf: '100') {}
|
|
641
|
-
end.to raise_error ArgumentError
|
|
642
|
-
end
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
describe '#row' do
|
|
646
|
-
it 'instantiates a row class' do
|
|
647
|
-
expect(subject).to receive(:row).once
|
|
648
|
-
allow(subject).to receive(:puts)
|
|
649
|
-
|
|
650
|
-
subject.table do
|
|
651
|
-
subject.row do
|
|
652
|
-
end
|
|
653
|
-
end
|
|
654
|
-
end
|
|
655
|
-
end
|
|
656
|
-
|
|
657
|
-
describe '#column' do
|
|
658
|
-
it 'instantiates multiple columns' do
|
|
659
|
-
expect(subject).to receive(:column).exactly(3).times
|
|
660
|
-
allow(subject).to receive(:puts)
|
|
661
|
-
|
|
662
|
-
subject.table do
|
|
663
|
-
subject.row do
|
|
664
|
-
subject.column('asdf')
|
|
665
|
-
subject.column('qwer')
|
|
666
|
-
subject.column('zxcv')
|
|
667
|
-
end
|
|
668
|
-
end
|
|
669
|
-
end
|
|
670
|
-
|
|
671
|
-
it 'accepts valid options' do
|
|
672
|
-
expect(subject).to receive(:column).once
|
|
673
|
-
allow(subject).to receive(:puts)
|
|
674
|
-
|
|
675
|
-
subject.table do
|
|
676
|
-
subject.row do
|
|
677
|
-
subject.column('asdf', width: 30)
|
|
678
|
-
end
|
|
679
|
-
end
|
|
680
|
-
end
|
|
681
|
-
|
|
682
|
-
it 'rejects invalid options' do
|
|
683
|
-
allow(subject).to receive(:puts)
|
|
684
|
-
expect do
|
|
685
|
-
subject.table do
|
|
686
|
-
subject.row do
|
|
687
|
-
subject.column('asdf', asdf: 30)
|
|
688
|
-
end
|
|
689
|
-
end
|
|
690
|
-
end.to raise_error ArgumentError
|
|
691
|
-
end
|
|
692
|
-
end
|
|
693
|
-
end
|