command_line_reporter 3.3.4 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,9 @@ describe CommandLineReporter::NestedFormatter do
5
5
 
6
6
  let(:controls) do
7
7
  {
8
- :clear => "\e[0m",
9
- :bold => "\e[1m",
10
- :red => "\e[31m",
8
+ clear: "\e[0m",
9
+ bold: "\e[1m",
10
+ red: "\e[31m"
11
11
  }
12
12
  end
13
13
 
@@ -40,25 +40,25 @@ describe CommandLineReporter::NestedFormatter do
40
40
  end
41
41
 
42
42
  it 'raises exception when there is an invalid argument' do
43
- expect {
44
- subject.format({:asdf => true}, lambda { })
45
- }.to raise_exception ArgumentError
43
+ expect do
44
+ subject.format({ asdf: true }, -> {})
45
+ end.to raise_exception ArgumentError
46
46
  end
47
47
 
48
48
  it 'raises an exception when a block is not given' do
49
- expect {
50
- subject.format({:message => 'test'})
51
- }.to raise_exception
49
+ expect do
50
+ subject.format(message: 'test')
51
+ end.to raise_exception Exception
52
52
  end
53
53
 
54
54
  it 'accepts valid arguments' do
55
55
  expect(subject).to receive(:puts).with('test')
56
56
  expect(subject).to receive(:puts).with('complete')
57
57
 
58
- expect {
59
- subject.format({:message => 'test'}, lambda { }) do
58
+ expect do
59
+ subject.format({ message: 'test' }, -> {}) do
60
60
  end
61
- }.not_to raise_exception
61
+ end.not_to raise_exception
62
62
  end
63
63
  end
64
64
 
@@ -78,28 +78,28 @@ describe CommandLineReporter::NestedFormatter do
78
78
  expect(subject).to receive(:puts).with('working')
79
79
  expect(subject).to receive(:puts).with('complete')
80
80
 
81
- subject.format({ }, lambda { })
81
+ subject.format({}, -> {})
82
82
  end
83
83
 
84
84
  it 'performs a wrapped report with color' do
85
85
  expect(subject).to receive(:puts).with("#{controls[:red]}working#{controls[:clear]}")
86
86
  expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
87
87
 
88
- subject.format({:color => 'red'}, lambda { })
88
+ subject.format({ color: 'red' }, -> {})
89
89
  end
90
90
 
91
91
  it 'performs a wrapped report with color' do
92
92
  expect(subject).to receive(:puts).with("#{controls[:bold]}working#{controls[:clear]}")
93
93
  expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
94
94
 
95
- subject.format({:bold => true}, lambda { })
95
+ subject.format({ bold: true }, -> {})
96
96
  end
97
97
 
98
98
  it 'performs a wrapped report overriding the message' do
99
99
  expect(subject).to receive(:puts).with('test')
100
100
  expect(subject).to receive(:puts).with('complete')
101
101
 
102
- subject.format({:message => 'test'}, lambda { })
102
+ subject.format({ message: 'test' }, -> {})
103
103
  end
104
104
 
105
105
  it 'performs an inline report' do
@@ -108,8 +108,8 @@ describe CommandLineReporter::NestedFormatter do
108
108
  expect(subject).to receive(:print).with('test2...')
109
109
  expect(subject).to receive(:puts).with('complete')
110
110
 
111
- subject.format({:message => 'test', :type => 'inline'}, lambda { })
112
- subject.format({:message => 'test2', :type => 'inline'}, lambda { })
111
+ subject.format({ message: 'test', type: 'inline' }, -> {})
112
+ subject.format({ message: 'test2', type: 'inline' }, -> {})
113
113
  end
114
114
 
115
115
  it 'overrides the default for all invocations of a wrapped report' do
@@ -119,8 +119,8 @@ describe CommandLineReporter::NestedFormatter do
119
119
  expect(subject).to receive(:puts).with('test2')
120
120
  expect(subject).to receive(:puts).with('done')
121
121
 
122
- subject.format({:message => 'test'}, lambda { })
123
- subject.format({:message => 'test2'}, lambda { })
122
+ subject.format({ message: 'test' }, -> {})
123
+ subject.format({ message: 'test2' }, -> {})
124
124
  end
125
125
 
126
126
  it 'overrides the default complete string for a wrapped report' do
@@ -129,8 +129,8 @@ describe CommandLineReporter::NestedFormatter do
129
129
  expect(subject).to receive(:puts).with('test2')
130
130
  expect(subject).to receive(:puts).with('finally')
131
131
 
132
- subject.format({:message => 'test', :complete => 'done'}, lambda { })
133
- subject.format({:message => 'test2', :complete => 'finally'}, lambda { })
132
+ subject.format({ message: 'test', complete: 'done' }, -> {})
133
+ subject.format({ message: 'test2', complete: 'finally' }, -> {})
134
134
  end
135
135
 
136
136
  it 'overrides the default complete string for an inline report' do
@@ -139,8 +139,8 @@ describe CommandLineReporter::NestedFormatter do
139
139
  expect(subject).to receive(:print).with('test2...')
140
140
  expect(subject).to receive(:puts).with('finally')
141
141
 
142
- subject.format({:message => 'test', :type => 'inline', :complete => 'done'}, lambda { })
143
- subject.format({:message => 'test2', :type => 'inline', :complete => 'finally'}, lambda { })
142
+ subject.format({ message: 'test', type: 'inline', complete: 'done' }, -> {})
143
+ subject.format({ message: 'test2', type: 'inline', complete: 'finally' }, -> {})
144
144
  end
145
145
 
146
146
  it 'performs another wrapped report to ensure defaul behavior' do
@@ -149,8 +149,8 @@ describe CommandLineReporter::NestedFormatter do
149
149
  expect(subject).to receive(:puts).with('test2')
150
150
  expect(subject).to receive(:puts).with('complete')
151
151
 
152
- subject.format({:message => 'test'}, lambda { })
153
- subject.format({:message => 'test2'}, lambda { })
152
+ subject.format({ message: 'test' }, -> {})
153
+ subject.format({ message: 'test2' }, -> {})
154
154
  end
155
155
  end
156
156
 
@@ -170,9 +170,9 @@ describe CommandLineReporter::NestedFormatter do
170
170
  expect(subject).to receive(:puts).with(' complete')
171
171
  expect(subject).to receive(:puts).with('complete')
172
172
 
173
- subject.format({:message => 'test'}, lambda {
174
- subject.format({:message => 'test2'}, lambda {})
175
- })
173
+ subject.format({ message: 'test' }, lambda do
174
+ subject.format({ message: 'test2' }, -> {})
175
+ end)
176
176
  end
177
177
 
178
178
  it 'indents the nested wrapped messages and outputs color' do
@@ -181,9 +181,9 @@ describe CommandLineReporter::NestedFormatter do
181
181
  expect(subject).to receive(:puts).with("#{controls[:red]} complete#{controls[:clear]}")
182
182
  expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
183
183
 
184
- subject.format({:message => 'test', :color => 'red'}, lambda {
185
- subject.format({:message => 'test2', :color => 'red'}, lambda {})
186
- })
184
+ subject.format({ message: 'test', color: 'red' }, lambda do
185
+ subject.format({ message: 'test2', color: 'red' }, -> {})
186
+ end)
187
187
  end
188
188
 
189
189
  it 'indents the nested wrapped messages and outputs bold' do
@@ -192,9 +192,9 @@ describe CommandLineReporter::NestedFormatter do
192
192
  expect(subject).to receive(:puts).with("#{controls[:bold]} complete#{controls[:clear]}")
193
193
  expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
194
194
 
195
- subject.format({:message => 'test', :bold => true}, lambda {
196
- subject.format({:message => 'test2', :bold => true}, lambda {})
197
- })
195
+ subject.format({ message: 'test', bold: true }, lambda do
196
+ subject.format({ message: 'test2', bold: true }, -> {})
197
+ end)
198
198
  end
199
199
 
200
200
  it 'indents the multiple nested wrapped messages' do
@@ -205,11 +205,11 @@ describe CommandLineReporter::NestedFormatter do
205
205
  expect(subject).to receive(:puts).with(' complete')
206
206
  expect(subject).to receive(:puts).with('complete')
207
207
 
208
- subject.format({:message => 'test'}, lambda {
209
- subject.format({:message => 'test2'}, lambda {
210
- subject.format({:message => 'test3'}, lambda { })
211
- })
212
- })
208
+ subject.format({ message: 'test' }, lambda do
209
+ subject.format({ message: 'test2' }, lambda do
210
+ subject.format({ message: 'test3' }, -> {})
211
+ end)
212
+ end)
213
213
  end
214
214
 
215
215
  it 'indents the nested wrapped and inline messages' do
@@ -218,9 +218,9 @@ describe CommandLineReporter::NestedFormatter do
218
218
  expect(subject).to receive(:puts).with('complete')
219
219
  expect(subject).to receive(:puts).with('complete')
220
220
 
221
- subject.format({:message => 'test'}, lambda {
222
- subject.format({:message => 'test2', :type => 'inline'}, lambda { })
223
- })
221
+ subject.format({ message: 'test' }, lambda do
222
+ subject.format({ message: 'test2', type: 'inline' }, -> {})
223
+ end)
224
224
  end
225
225
 
226
226
  it 'indents the multiple nested wrapped messages' do
@@ -231,11 +231,11 @@ describe CommandLineReporter::NestedFormatter do
231
231
  expect(subject).to receive(:puts).with(' complete')
232
232
  expect(subject).to receive(:puts).with('complete')
233
233
 
234
- subject.format({:message => 'test'}, lambda {
235
- subject.format({:message => 'test2'}, lambda {
236
- subject.format({:message => 'test3', :type => 'inline'}, lambda { })
237
- })
238
- })
234
+ subject.format({ message: 'test' }, lambda do
235
+ subject.format({ message: 'test2' }, lambda do
236
+ subject.format({ message: 'test3', type: 'inline' }, -> {})
237
+ end)
238
+ end)
239
239
  end
240
240
 
241
241
  it 'overrides the indent spacing of all messages' do
@@ -248,11 +248,11 @@ describe CommandLineReporter::NestedFormatter do
248
248
 
249
249
  subject.indent_size = 4
250
250
 
251
- subject.format({:message => 'test'}, lambda {
252
- subject.format({:message => 'test2'}, lambda {
253
- subject.format({:message => 'test3', :type => 'inline'}, lambda { })
254
- })
255
- })
251
+ subject.format({ message: 'test' }, lambda do
252
+ subject.format({ message: 'test2' }, lambda do
253
+ subject.format({ message: 'test3', type: 'inline' }, -> {})
254
+ end)
255
+ end)
256
256
  end
257
257
 
258
258
  it 'overrides the indent spacing of specific message' do
@@ -265,15 +265,15 @@ describe CommandLineReporter::NestedFormatter do
265
265
 
266
266
  subject.indent_size = 4
267
267
 
268
- subject.format({:message => 'test'}, lambda {
269
- subject.format({:message => 'test2', :indent_size => 6}, lambda {
270
- subject.format({:message => 'test3', :type => 'inline', :indent_size => 3}, lambda { })
271
- })
272
- })
268
+ subject.format({ message: 'test' }, lambda do
269
+ subject.format({ message: 'test2', indent_size: 6 }, lambda do
270
+ subject.format({ message: 'test3', type: 'inline', indent_size: 3 }, -> {})
271
+ end)
272
+ end)
273
273
  end
274
274
 
275
275
  it 'performs the sums specified in the block' do
276
- x,y,z = 0,0,0
276
+ x, y, z = 0, 0, 0
277
277
 
278
278
  expect(subject).to receive(:puts).with('sum x and 10')
279
279
  expect(subject).to receive(:puts).with(' y is the difference of 20 and x')
@@ -282,15 +282,15 @@ describe CommandLineReporter::NestedFormatter do
282
282
  expect(subject).to receive(:puts).with(' complete')
283
283
  expect(subject).to receive(:puts).with('complete')
284
284
 
285
- subject.format({:message => 'sum x and 10'}, lambda {
286
- x = x + 10
287
- subject.format({:message => 'y is the difference of 20 and x'}, lambda {
285
+ subject.format({ message: 'sum x and 10' }, lambda do
286
+ x += 10
287
+ subject.format({ message: 'y is the difference of 20 and x' }, lambda do
288
288
  y = 20 - x
289
- subject.format({:message => 'z = x + y'}, lambda {
289
+ subject.format({ message: 'z = x + y' }, lambda do
290
290
  z = x + y
291
- })
292
- })
293
- })
291
+ end)
292
+ end)
293
+ end)
294
294
 
295
295
  expect(x).to eq(10)
296
296
  expect(y).to eq(10)
@@ -4,21 +4,21 @@ describe OptionsValidator do
4
4
  subject { Class.new.extend(OptionsValidator) }
5
5
 
6
6
  it 'accepts single key options' do
7
- expect {
8
- subject.validate_options({:valid => true}, :valid)
9
- }.to_not raise_error
7
+ expect do
8
+ subject.validate_options({ valid: true }, :valid)
9
+ end.to_not raise_error Exception
10
10
  end
11
11
 
12
12
  it 'rejects invalid option hashes' do
13
- expect {
14
- subject.validate_options({:wrong => true}, :valid)
15
- }.to raise_error ArgumentError
13
+ expect do
14
+ subject.validate_options({ wrong: true }, :valid)
15
+ end.to raise_error ArgumentError
16
16
  end
17
17
 
18
18
  it 'accepts multi-key options' do
19
- expect {
20
- valid = [:valid, :another]
21
- subject.validate_options({:valid => true, :another => true}, *valid)
22
- }.to_not raise_error
19
+ expect do
20
+ valid = %i[valid another]
21
+ subject.validate_options({ valid: true, another: true }, *valid)
22
+ end.to_not raise_error Exception
23
23
  end
24
24
  end
@@ -12,9 +12,9 @@ describe CommandLineReporter::ProgressFormatter do
12
12
 
13
13
  let :controls do
14
14
  {
15
- :clear => "\e[0m",
16
- :bold => "\e[1m",
17
- :red => "\e[31m",
15
+ clear: "\e[0m",
16
+ bold: "\e[1m",
17
+ red: "\e[31m"
18
18
  }
19
19
  end
20
20
 
@@ -23,27 +23,21 @@ describe CommandLineReporter::ProgressFormatter do
23
23
  expect(subject).to receive(:print).exactly(10).times.with('.')
24
24
  expect(subject).to receive(:puts).exactly(1).times
25
25
 
26
- subject.format({}, lambda {
27
- 10.times {subject.progress}
28
- })
26
+ subject.format({}, -> { 10.times { subject.progress } })
29
27
  end
30
28
 
31
29
  it 'displays colored red dots for the indicator' do
32
30
  expect(subject).to receive(:print).exactly(10).times.with("#{controls[:red]}.#{controls[:clear]}")
33
31
  expect(subject).to receive(:puts).exactly(1).times
34
32
 
35
- subject.format({:color => 'red'}, lambda {
36
- 10.times {subject.progress}
37
- })
33
+ subject.format({ color: 'red' }, -> { 10.times { subject.progress } })
38
34
  end
39
35
 
40
36
  it 'displays BOLD dots for the indicator' do
41
37
  expect(subject).to receive(:print).exactly(10).times.with("#{controls[:bold]}.#{controls[:clear]}")
42
38
  expect(subject).to receive(:puts).exactly(1).times
43
39
 
44
- subject.format({:bold => true}, lambda {
45
- 10.times {subject.progress}
46
- })
40
+ subject.format({ bold: true }, -> { 10.times { subject.progress } })
47
41
  end
48
42
 
49
43
  it 'uses the defined indicator' do
@@ -51,19 +45,14 @@ describe CommandLineReporter::ProgressFormatter do
51
45
  expect(subject).to receive(:print).exactly(10).times.with('+')
52
46
  expect(subject).to receive(:puts)
53
47
 
54
- subject.format({}, lambda {
55
- 10.times {subject.progress}
56
- })
57
-
48
+ subject.format({}, -> { 10.times { subject.progress } })
58
49
  end
59
50
 
60
51
  it 'allows override of the indicator' do
61
52
  expect(subject).to receive(:print).exactly(10).times.with('=')
62
53
  expect(subject).to receive(:puts)
63
54
 
64
- subject.format({:indicator => '='}, lambda {
65
- 10.times {subject.progress}
66
- })
55
+ subject.format({ indicator: '=' }, -> { 10.times { subject.progress } })
67
56
  end
68
57
  end
69
58
 
@@ -72,18 +61,14 @@ describe CommandLineReporter::ProgressFormatter do
72
61
  expect(subject).to receive(:print).exactly(10).times.with('+')
73
62
  expect(subject).to receive(:puts)
74
63
 
75
- subject.format({}, lambda {
76
- 10.times {subject.progress('+')}
77
- })
64
+ subject.format({}, -> { 10.times { subject.progress('+') } })
78
65
  end
79
66
 
80
67
  it 'allows any indicator' do
81
68
  expect(subject).to receive(:print).exactly(10).times
82
69
  expect(subject).to receive(:puts)
83
70
 
84
- subject.format({}, lambda {
85
- 10.times {|i| subject.progress("#{i}")}
86
- })
71
+ subject.format({}, -> { 10.times { |i| subject.progress("#{i}") } })
87
72
  end
88
73
  end
89
74
  end
@@ -1,44 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CommandLineReporter::Row do
4
- let(:cols) { 10.times.map {|v| CommandLineReporter::Column.new("test#{v}")} }
4
+ let(:cols) { Array.new(10) { |v| CommandLineReporter::Column.new("test#{v}") } }
5
5
 
6
6
  describe '#initialize' do
7
+ subject { CommandLineReporter::Row }
8
+
7
9
  it 'accepts header' do
8
- expect(CommandLineReporter::Row.new(:header => true).header).to be true
10
+ expect(subject.new(header: true).header).to be true
9
11
  end
10
12
 
11
13
  it 'accepts color' do
12
- expect(CommandLineReporter::Row.new(:color => 'red').color).to eq('red')
14
+ expect(subject.new(color: 'red').color).to eq('red')
13
15
  end
14
16
 
15
17
  it 'accepts bold' do
16
- expect(CommandLineReporter::Row.new(:bold => true).bold).to be true
18
+ expect(subject.new(bold: true).bold).to be true
17
19
  end
18
20
 
19
21
  it 'output encoding should be ascii' do
20
- expect(CommandLineReporter::Row.new(:encoding => :ascii).encoding).to eq(:ascii)
22
+ expect(subject.new(encoding: :ascii).encoding).to eq(:ascii)
21
23
  end
22
24
 
23
25
  it 'output encoding should be unicode' do
24
- expect(CommandLineReporter::Row.new.encoding).to eq(:unicode)
26
+ expect(subject.new.encoding).to eq(:unicode)
25
27
  end
26
-
27
28
  end
28
29
 
29
30
  describe '#add' do
30
- subject { CommandLineReporter::Row.new }
31
+ subject { CommandLineReporter::Row }
31
32
 
32
33
  it 'columns' do
33
- subject.add(cols[0])
34
- expect(subject.columns.size).to eq(1)
35
- expect(subject.columns[0]).to eq(cols[0])
36
- subject.add(cols[1])
37
- expect(subject.columns).to eq(cols[0,2])
34
+ row = CommandLineReporter::Row.new
35
+ row.add(cols[0])
36
+ expect(row.columns.size).to eq(1)
37
+ expect(row.columns[0]).to eq(cols[0])
38
+ row.add(cols[1])
39
+ expect(row.columns).to eq(cols[0, 2])
38
40
  end
39
41
 
40
42
  it 'defaults colors on columns' do
41
- row = CommandLineReporter::Row.new(:color => 'red')
43
+ row = subject.new(color: 'red')
42
44
  row.add(cols[0])
43
45
  expect(row.columns[0].color).to eq('red')
44
46
  row.add(cols[1])
@@ -46,14 +48,14 @@ describe CommandLineReporter::Row do
46
48
  end
47
49
 
48
50
  it 'allows columns to override the row color' do
49
- col = CommandLineReporter::Column.new('test', :color => 'blue')
50
- row = CommandLineReporter::Row.new(:color => 'red')
51
+ col = CommandLineReporter::Column.new('test', color: 'blue')
52
+ row = subject.new(color: 'red')
51
53
  row.add(col)
52
54
  expect(row.columns[0].color).to eq('blue')
53
55
  end
54
56
 
55
57
  it 'supercedes bold on columns' do
56
- row = CommandLineReporter::Row.new(:bold => true)
58
+ row = subject.new(bold: true)
57
59
  row.add(cols[0])
58
60
  expect(row.columns[0].bold).to be true
59
61
  row.add(cols[1])
@@ -65,11 +67,11 @@ describe CommandLineReporter::Row do
65
67
  let :cols do
66
68
  [
67
69
  CommandLineReporter::Column.new('asdf'),
68
- CommandLineReporter::Column.new('qwer', :align => 'center'),
69
- CommandLineReporter::Column.new('zxcv', :align => 'right'),
70
- CommandLineReporter::Column.new('x' * 25, :align => 'left', :width => 10),
71
- CommandLineReporter::Column.new('x' * 25, :align => 'center', :width => 10),
72
- CommandLineReporter::Column.new('x' * 35, :align => 'left', :width => 10),
70
+ CommandLineReporter::Column.new('qwer', align: 'center'),
71
+ CommandLineReporter::Column.new('zxcv', align: 'right'),
72
+ CommandLineReporter::Column.new('x' * 25, align: 'left', width: 10),
73
+ CommandLineReporter::Column.new('x' * 25, align: 'center', width: 10),
74
+ CommandLineReporter::Column.new('x' * 35, align: 'left', width: 10)
73
75
  ]
74
76
  end
75
77