command_line_reporter 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -12
- data/lib/{column.rb → command_line_reporter/column.rb} +8 -3
- data/lib/{nested_formatter.rb → command_line_reporter/formatter/nested.rb} +0 -1
- data/lib/{progress_formatter.rb → command_line_reporter/formatter/progress.rb} +0 -1
- data/lib/{options_validator.rb → command_line_reporter/options_validator.rb} +0 -0
- data/lib/{row.rb → command_line_reporter/row.rb} +4 -5
- data/lib/command_line_reporter/table.rb +130 -0
- data/lib/{version.rb → command_line_reporter/version.rb} +1 -1
- data/lib/command_line_reporter.rb +9 -2
- data/spec/column_spec.rb +193 -202
- data/spec/command_line_reporter_spec.rb +146 -146
- data/spec/nested_formatter_spec.rb +101 -91
- data/spec/options_validator_spec.rb +0 -1
- data/spec/progress_formatter_spec.rb +20 -18
- data/spec/row_spec.rb +56 -52
- data/spec/spec_helper.rb +4 -2
- data/spec/table_spec.rb +54 -16
- metadata +54 -57
- data/examples/capture.rb +0 -32
- data/examples/nested.rb +0 -38
- data/examples/progress.rb +0 -68
- data/examples/quiet.rb +0 -40
- data/examples/simple.rb +0 -23
- data/examples/table.rb +0 -71
- data/examples/variable.rb +0 -30
- data/lib/table.rb +0 -96
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'nested_formatter'
|
3
2
|
|
4
3
|
describe CommandLineReporter::NestedFormatter do
|
5
4
|
subject { CommandLineReporter::NestedFormatter.instance }
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
let(:controls) do
|
7
|
+
{
|
9
8
|
:clear => "\e[0m",
|
10
9
|
:bold => "\e[1m",
|
11
10
|
:red => "\e[31m",
|
@@ -13,9 +12,20 @@ describe CommandLineReporter::NestedFormatter do
|
|
13
12
|
end
|
14
13
|
|
15
14
|
describe '#method default values' do
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
describe '#message_string' do
|
16
|
+
subject { super().message_string }
|
17
|
+
it { should == 'working' }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#complete_string' do
|
21
|
+
subject { super().complete_string }
|
22
|
+
it { should == 'complete' }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#indent_size' do
|
26
|
+
subject { super().indent_size }
|
27
|
+
it { should eq 2 }
|
28
|
+
end
|
19
29
|
end
|
20
30
|
|
21
31
|
describe '#format' do
|
@@ -30,25 +40,25 @@ describe CommandLineReporter::NestedFormatter do
|
|
30
40
|
end
|
31
41
|
|
32
42
|
it 'raises exception when there is an invalid argument' do
|
33
|
-
|
43
|
+
expect {
|
34
44
|
subject.format({:asdf => true}, lambda { })
|
35
|
-
}.
|
45
|
+
}.to raise_exception ArgumentError
|
36
46
|
end
|
37
47
|
|
38
48
|
it 'raises an exception when a block is not given' do
|
39
|
-
|
49
|
+
expect {
|
40
50
|
subject.format({:message => 'test'})
|
41
|
-
}.
|
51
|
+
}.to raise_exception
|
42
52
|
end
|
43
53
|
|
44
54
|
it 'accepts valid arguments' do
|
45
|
-
subject.
|
46
|
-
subject.
|
55
|
+
expect(subject).to receive(:puts).with('test')
|
56
|
+
expect(subject).to receive(:puts).with('complete')
|
47
57
|
|
48
|
-
|
58
|
+
expect {
|
49
59
|
subject.format({:message => 'test'}, lambda { }) do
|
50
60
|
end
|
51
|
-
}.
|
61
|
+
}.not_to raise_exception
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
@@ -65,38 +75,38 @@ describe CommandLineReporter::NestedFormatter do
|
|
65
75
|
end
|
66
76
|
|
67
77
|
it 'performs a wrapped report' do
|
68
|
-
subject.
|
69
|
-
subject.
|
78
|
+
expect(subject).to receive(:puts).with('working')
|
79
|
+
expect(subject).to receive(:puts).with('complete')
|
70
80
|
|
71
81
|
subject.format({ }, lambda { })
|
72
82
|
end
|
73
83
|
|
74
84
|
it 'performs a wrapped report with color' do
|
75
|
-
subject.
|
76
|
-
subject.
|
85
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}working#{controls[:clear]}")
|
86
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
|
77
87
|
|
78
88
|
subject.format({:color => 'red'}, lambda { })
|
79
89
|
end
|
80
90
|
|
81
91
|
it 'performs a wrapped report with color' do
|
82
|
-
subject.
|
83
|
-
subject.
|
92
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}working#{controls[:clear]}")
|
93
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
|
84
94
|
|
85
95
|
subject.format({:bold => true}, lambda { })
|
86
96
|
end
|
87
97
|
|
88
98
|
it 'performs a wrapped report overriding the message' do
|
89
|
-
subject.
|
90
|
-
subject.
|
99
|
+
expect(subject).to receive(:puts).with('test')
|
100
|
+
expect(subject).to receive(:puts).with('complete')
|
91
101
|
|
92
102
|
subject.format({:message => 'test'}, lambda { })
|
93
103
|
end
|
94
104
|
|
95
105
|
it 'performs an inline report' do
|
96
|
-
subject.
|
97
|
-
subject.
|
98
|
-
subject.
|
99
|
-
subject.
|
106
|
+
expect(subject).to receive(:print).with('test...')
|
107
|
+
expect(subject).to receive(:puts).with('complete')
|
108
|
+
expect(subject).to receive(:print).with('test2...')
|
109
|
+
expect(subject).to receive(:puts).with('complete')
|
100
110
|
|
101
111
|
subject.format({:message => 'test', :type => 'inline'}, lambda { })
|
102
112
|
subject.format({:message => 'test2', :type => 'inline'}, lambda { })
|
@@ -104,40 +114,40 @@ describe CommandLineReporter::NestedFormatter do
|
|
104
114
|
|
105
115
|
it 'overrides the default for all invocations of a wrapped report' do
|
106
116
|
subject.complete_string = 'done'
|
107
|
-
subject.
|
108
|
-
subject.
|
109
|
-
subject.
|
110
|
-
subject.
|
117
|
+
expect(subject).to receive(:puts).with('test')
|
118
|
+
expect(subject).to receive(:puts).with('done')
|
119
|
+
expect(subject).to receive(:puts).with('test2')
|
120
|
+
expect(subject).to receive(:puts).with('done')
|
111
121
|
|
112
122
|
subject.format({:message => 'test'}, lambda { })
|
113
123
|
subject.format({:message => 'test2'}, lambda { })
|
114
124
|
end
|
115
125
|
|
116
126
|
it 'overrides the default complete string for a wrapped report' do
|
117
|
-
subject.
|
118
|
-
subject.
|
119
|
-
subject.
|
120
|
-
subject.
|
127
|
+
expect(subject).to receive(:puts).with('test')
|
128
|
+
expect(subject).to receive(:puts).with('done')
|
129
|
+
expect(subject).to receive(:puts).with('test2')
|
130
|
+
expect(subject).to receive(:puts).with('finally')
|
121
131
|
|
122
132
|
subject.format({:message => 'test', :complete => 'done'}, lambda { })
|
123
133
|
subject.format({:message => 'test2', :complete => 'finally'}, lambda { })
|
124
134
|
end
|
125
135
|
|
126
136
|
it 'overrides the default complete string for an inline report' do
|
127
|
-
subject.
|
128
|
-
subject.
|
129
|
-
subject.
|
130
|
-
subject.
|
137
|
+
expect(subject).to receive(:print).with('test...')
|
138
|
+
expect(subject).to receive(:puts).with('done')
|
139
|
+
expect(subject).to receive(:print).with('test2...')
|
140
|
+
expect(subject).to receive(:puts).with('finally')
|
131
141
|
|
132
142
|
subject.format({:message => 'test', :type => 'inline', :complete => 'done'}, lambda { })
|
133
143
|
subject.format({:message => 'test2', :type => 'inline', :complete => 'finally'}, lambda { })
|
134
144
|
end
|
135
145
|
|
136
146
|
it 'performs another wrapped report to ensure defaul behavior' do
|
137
|
-
subject.
|
138
|
-
subject.
|
139
|
-
subject.
|
140
|
-
subject.
|
147
|
+
expect(subject).to receive(:puts).with('test')
|
148
|
+
expect(subject).to receive(:puts).with('complete')
|
149
|
+
expect(subject).to receive(:puts).with('test2')
|
150
|
+
expect(subject).to receive(:puts).with('complete')
|
141
151
|
|
142
152
|
subject.format({:message => 'test'}, lambda { })
|
143
153
|
subject.format({:message => 'test2'}, lambda { })
|
@@ -155,10 +165,10 @@ describe CommandLineReporter::NestedFormatter do
|
|
155
165
|
end
|
156
166
|
|
157
167
|
it 'indents the nested wrapped messages' do
|
158
|
-
subject.
|
159
|
-
subject.
|
160
|
-
subject.
|
161
|
-
subject.
|
168
|
+
expect(subject).to receive(:puts).with('test')
|
169
|
+
expect(subject).to receive(:puts).with(' test2')
|
170
|
+
expect(subject).to receive(:puts).with(' complete')
|
171
|
+
expect(subject).to receive(:puts).with('complete')
|
162
172
|
|
163
173
|
subject.format({:message => 'test'}, lambda {
|
164
174
|
subject.format({:message => 'test2'}, lambda {})
|
@@ -166,10 +176,10 @@ describe CommandLineReporter::NestedFormatter do
|
|
166
176
|
end
|
167
177
|
|
168
178
|
it 'indents the nested wrapped messages and outputs color' do
|
169
|
-
subject.
|
170
|
-
subject.
|
171
|
-
subject.
|
172
|
-
subject.
|
179
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}test#{controls[:clear]}")
|
180
|
+
expect(subject).to receive(:puts).with("#{controls[:red]} test2#{controls[:clear]}")
|
181
|
+
expect(subject).to receive(:puts).with("#{controls[:red]} complete#{controls[:clear]}")
|
182
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
|
173
183
|
|
174
184
|
subject.format({:message => 'test', :color => 'red'}, lambda {
|
175
185
|
subject.format({:message => 'test2', :color => 'red'}, lambda {})
|
@@ -177,10 +187,10 @@ describe CommandLineReporter::NestedFormatter do
|
|
177
187
|
end
|
178
188
|
|
179
189
|
it 'indents the nested wrapped messages and outputs bold' do
|
180
|
-
subject.
|
181
|
-
subject.
|
182
|
-
subject.
|
183
|
-
subject.
|
190
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}test#{controls[:clear]}")
|
191
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]} test2#{controls[:clear]}")
|
192
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]} complete#{controls[:clear]}")
|
193
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
|
184
194
|
|
185
195
|
subject.format({:message => 'test', :bold => true}, lambda {
|
186
196
|
subject.format({:message => 'test2', :bold => true}, lambda {})
|
@@ -188,12 +198,12 @@ describe CommandLineReporter::NestedFormatter do
|
|
188
198
|
end
|
189
199
|
|
190
200
|
it 'indents the multiple nested wrapped messages' do
|
191
|
-
subject.
|
192
|
-
subject.
|
193
|
-
subject.
|
194
|
-
subject.
|
195
|
-
subject.
|
196
|
-
subject.
|
201
|
+
expect(subject).to receive(:puts).with('test')
|
202
|
+
expect(subject).to receive(:puts).with(' test2')
|
203
|
+
expect(subject).to receive(:puts).with(' test3')
|
204
|
+
expect(subject).to receive(:puts).with(' complete')
|
205
|
+
expect(subject).to receive(:puts).with(' complete')
|
206
|
+
expect(subject).to receive(:puts).with('complete')
|
197
207
|
|
198
208
|
subject.format({:message => 'test'}, lambda {
|
199
209
|
subject.format({:message => 'test2'}, lambda {
|
@@ -203,10 +213,10 @@ describe CommandLineReporter::NestedFormatter do
|
|
203
213
|
end
|
204
214
|
|
205
215
|
it 'indents the nested wrapped and inline messages' do
|
206
|
-
subject.
|
207
|
-
subject.
|
208
|
-
subject.
|
209
|
-
subject.
|
216
|
+
expect(subject).to receive(:puts).with('test')
|
217
|
+
expect(subject).to receive(:print).with(' test2...')
|
218
|
+
expect(subject).to receive(:puts).with('complete')
|
219
|
+
expect(subject).to receive(:puts).with('complete')
|
210
220
|
|
211
221
|
subject.format({:message => 'test'}, lambda {
|
212
222
|
subject.format({:message => 'test2', :type => 'inline'}, lambda { })
|
@@ -214,12 +224,12 @@ describe CommandLineReporter::NestedFormatter do
|
|
214
224
|
end
|
215
225
|
|
216
226
|
it 'indents the multiple nested wrapped messages' do
|
217
|
-
subject.
|
218
|
-
subject.
|
219
|
-
subject.
|
220
|
-
subject.
|
221
|
-
subject.
|
222
|
-
subject.
|
227
|
+
expect(subject).to receive(:puts).with('test')
|
228
|
+
expect(subject).to receive(:puts).with(' test2')
|
229
|
+
expect(subject).to receive(:print).with(' test3...')
|
230
|
+
expect(subject).to receive(:puts).with('complete')
|
231
|
+
expect(subject).to receive(:puts).with(' complete')
|
232
|
+
expect(subject).to receive(:puts).with('complete')
|
223
233
|
|
224
234
|
subject.format({:message => 'test'}, lambda {
|
225
235
|
subject.format({:message => 'test2'}, lambda {
|
@@ -229,12 +239,12 @@ describe CommandLineReporter::NestedFormatter do
|
|
229
239
|
end
|
230
240
|
|
231
241
|
it 'overrides the indent spacing of all messages' do
|
232
|
-
subject.
|
233
|
-
subject.
|
234
|
-
subject.
|
235
|
-
subject.
|
236
|
-
subject.
|
237
|
-
subject.
|
242
|
+
expect(subject).to receive(:puts).with('test')
|
243
|
+
expect(subject).to receive(:puts).with(' test2')
|
244
|
+
expect(subject).to receive(:print).with(' test3...')
|
245
|
+
expect(subject).to receive(:puts).with('complete')
|
246
|
+
expect(subject).to receive(:puts).with(' complete')
|
247
|
+
expect(subject).to receive(:puts).with('complete')
|
238
248
|
|
239
249
|
subject.indent_size = 4
|
240
250
|
|
@@ -246,12 +256,12 @@ describe CommandLineReporter::NestedFormatter do
|
|
246
256
|
end
|
247
257
|
|
248
258
|
it 'overrides the indent spacing of specific message' do
|
249
|
-
subject.
|
250
|
-
subject.
|
251
|
-
subject.
|
252
|
-
subject.
|
253
|
-
subject.
|
254
|
-
subject.
|
259
|
+
expect(subject).to receive(:puts).with('test')
|
260
|
+
expect(subject).to receive(:puts).with(' test2')
|
261
|
+
expect(subject).to receive(:print).with(' test3...')
|
262
|
+
expect(subject).to receive(:puts).with('complete')
|
263
|
+
expect(subject).to receive(:puts).with(' complete')
|
264
|
+
expect(subject).to receive(:puts).with('complete')
|
255
265
|
|
256
266
|
subject.indent_size = 4
|
257
267
|
|
@@ -265,12 +275,12 @@ describe CommandLineReporter::NestedFormatter do
|
|
265
275
|
it 'performs the sums specified in the block' do
|
266
276
|
x,y,z = 0,0,0
|
267
277
|
|
268
|
-
subject.
|
269
|
-
subject.
|
270
|
-
subject.
|
271
|
-
subject.
|
272
|
-
subject.
|
273
|
-
subject.
|
278
|
+
expect(subject).to receive(:puts).with('sum x and 10')
|
279
|
+
expect(subject).to receive(:puts).with(' y is the difference of 20 and x')
|
280
|
+
expect(subject).to receive(:puts).with(' z = x + y')
|
281
|
+
expect(subject).to receive(:puts).with(' complete')
|
282
|
+
expect(subject).to receive(:puts).with(' complete')
|
283
|
+
expect(subject).to receive(:puts).with('complete')
|
274
284
|
|
275
285
|
subject.format({:message => 'sum x and 10'}, lambda {
|
276
286
|
x = x + 10
|
@@ -282,9 +292,9 @@ describe CommandLineReporter::NestedFormatter do
|
|
282
292
|
})
|
283
293
|
})
|
284
294
|
|
285
|
-
x.
|
286
|
-
y.
|
287
|
-
z.
|
295
|
+
expect(x).to eq(10)
|
296
|
+
expect(y).to eq(10)
|
297
|
+
expect(z).to eq(20)
|
288
298
|
end
|
289
299
|
end
|
290
300
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'progress_formatter'
|
3
2
|
|
4
3
|
describe CommandLineReporter::ProgressFormatter do
|
5
4
|
subject { CommandLineReporter::ProgressFormatter.instance }
|
6
5
|
|
7
6
|
describe '#method default values' do
|
8
|
-
|
7
|
+
describe '#indicator' do
|
8
|
+
subject { super().indicator }
|
9
|
+
it { should == '.' }
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
let :controls do
|
14
|
+
{
|
13
15
|
:clear => "\e[0m",
|
14
16
|
:bold => "\e[1m",
|
15
17
|
:red => "\e[31m",
|
@@ -18,8 +20,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
18
20
|
|
19
21
|
describe '#format' do
|
20
22
|
it 'displays dots for the indicator' do
|
21
|
-
subject.
|
22
|
-
subject.
|
23
|
+
expect(subject).to receive(:print).exactly(10).times.with('.')
|
24
|
+
expect(subject).to receive(:puts).exactly(1).times
|
23
25
|
|
24
26
|
subject.format({}, lambda {
|
25
27
|
10.times {subject.progress}
|
@@ -27,8 +29,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'displays colored red dots for the indicator' do
|
30
|
-
subject.
|
31
|
-
subject.
|
32
|
+
expect(subject).to receive(:print).exactly(10).times.with("#{controls[:red]}.#{controls[:clear]}")
|
33
|
+
expect(subject).to receive(:puts).exactly(1).times
|
32
34
|
|
33
35
|
subject.format({:color => 'red'}, lambda {
|
34
36
|
10.times {subject.progress}
|
@@ -36,8 +38,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'displays BOLD dots for the indicator' do
|
39
|
-
subject.
|
40
|
-
subject.
|
41
|
+
expect(subject).to receive(:print).exactly(10).times.with("#{controls[:bold]}.#{controls[:clear]}")
|
42
|
+
expect(subject).to receive(:puts).exactly(1).times
|
41
43
|
|
42
44
|
subject.format({:bold => true}, lambda {
|
43
45
|
10.times {subject.progress}
|
@@ -46,8 +48,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
46
48
|
|
47
49
|
it 'uses the defined indicator' do
|
48
50
|
subject.indicator = '+'
|
49
|
-
subject.
|
50
|
-
subject.
|
51
|
+
expect(subject).to receive(:print).exactly(10).times.with('+')
|
52
|
+
expect(subject).to receive(:puts)
|
51
53
|
|
52
54
|
subject.format({}, lambda {
|
53
55
|
10.times {subject.progress}
|
@@ -56,8 +58,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'allows override of the indicator' do
|
59
|
-
subject.
|
60
|
-
subject.
|
61
|
+
expect(subject).to receive(:print).exactly(10).times.with('=')
|
62
|
+
expect(subject).to receive(:puts)
|
61
63
|
|
62
64
|
subject.format({:indicator => '='}, lambda {
|
63
65
|
10.times {subject.progress}
|
@@ -67,8 +69,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
67
69
|
|
68
70
|
describe '#progress' do
|
69
71
|
it 'allows override of the indicator' do
|
70
|
-
subject.
|
71
|
-
subject.
|
72
|
+
expect(subject).to receive(:print).exactly(10).times.with('+')
|
73
|
+
expect(subject).to receive(:puts)
|
72
74
|
|
73
75
|
subject.format({}, lambda {
|
74
76
|
10.times {subject.progress('+')}
|
@@ -76,8 +78,8 @@ describe CommandLineReporter::ProgressFormatter do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
it 'allows any indicator' do
|
79
|
-
subject.
|
80
|
-
subject.
|
81
|
+
expect(subject).to receive(:print).exactly(10).times
|
82
|
+
expect(subject).to receive(:puts)
|
81
83
|
|
82
84
|
subject.format({}, lambda {
|
83
85
|
10.times {|i| subject.progress("#{i}")}
|
data/spec/row_spec.rb
CHANGED
@@ -1,63 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'row'
|
3
2
|
|
4
3
|
describe CommandLineReporter::Row do
|
5
|
-
|
6
|
-
@cols = 10.times.map {|v| CommandLineReporter::Column.new("test#{v}")}
|
7
|
-
end
|
4
|
+
let(:cols) { 10.times.map {|v| CommandLineReporter::Column.new("test#{v}")} }
|
8
5
|
|
9
6
|
describe '#initialize' do
|
10
7
|
it 'accepts header' do
|
11
|
-
CommandLineReporter::Row.new(:header => true).header.
|
8
|
+
expect(CommandLineReporter::Row.new(:header => true).header).to be_true
|
12
9
|
end
|
13
10
|
|
14
11
|
it 'accepts color' do
|
15
|
-
CommandLineReporter::Row.new(:color => 'red').color.
|
12
|
+
expect(CommandLineReporter::Row.new(:color => 'red').color).to eq('red')
|
16
13
|
end
|
17
14
|
|
18
15
|
it 'accepts bold' do
|
19
|
-
CommandLineReporter::Row.new(:bold => true).bold.
|
16
|
+
expect(CommandLineReporter::Row.new(:bold => true).bold).to be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'output encoding should be ascii' do
|
20
|
+
expect(CommandLineReporter::Row.new(:encoding => :ascii).encoding).to eq(:ascii)
|
20
21
|
end
|
22
|
+
|
23
|
+
it 'output encoding should be unicode' do
|
24
|
+
expect(CommandLineReporter::Row.new.encoding).to be_false
|
25
|
+
end
|
26
|
+
|
21
27
|
end
|
22
28
|
|
23
29
|
describe '#add' do
|
24
30
|
subject { CommandLineReporter::Row.new }
|
25
31
|
|
26
32
|
it 'columns' do
|
27
|
-
subject.add(
|
28
|
-
subject.columns.size.
|
29
|
-
subject.columns[0].
|
30
|
-
subject.add(
|
31
|
-
subject.columns.
|
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])
|
32
38
|
end
|
33
39
|
|
34
40
|
it 'defaults colors on columns' do
|
35
41
|
row = CommandLineReporter::Row.new(:color => 'red')
|
36
|
-
row.add(
|
37
|
-
row.columns[0].color.
|
38
|
-
row.add(
|
39
|
-
row.columns[1].color.
|
42
|
+
row.add(cols[0])
|
43
|
+
expect(row.columns[0].color).to eq('red')
|
44
|
+
row.add(cols[1])
|
45
|
+
expect(row.columns[1].color).to eq('red')
|
40
46
|
end
|
41
47
|
|
42
48
|
it 'allows columns to override the row color' do
|
43
49
|
col = CommandLineReporter::Column.new('test', :color => 'blue')
|
44
50
|
row = CommandLineReporter::Row.new(:color => 'red')
|
45
51
|
row.add(col)
|
46
|
-
row.columns[0].color.
|
52
|
+
expect(row.columns[0].color).to eq('blue')
|
47
53
|
end
|
48
54
|
|
49
55
|
it 'supercedes bold on columns' do
|
50
56
|
row = CommandLineReporter::Row.new(:bold => true)
|
51
|
-
row.add(
|
52
|
-
row.columns[0].bold.
|
53
|
-
row.add(
|
54
|
-
row.columns[1].bold.
|
57
|
+
row.add(cols[0])
|
58
|
+
expect(row.columns[0].bold).to be_true
|
59
|
+
row.add(cols[1])
|
60
|
+
expect(row.columns[1].bold).to be_true
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
64
|
describe '#output' do
|
59
|
-
|
60
|
-
|
65
|
+
let :cols do
|
66
|
+
[
|
61
67
|
CommandLineReporter::Column.new('asdf'),
|
62
68
|
CommandLineReporter::Column.new('qwer', :align => 'center'),
|
63
69
|
CommandLineReporter::Column.new('zxcv', :align => 'right'),
|
@@ -67,56 +73,54 @@ describe CommandLineReporter::Row do
|
|
67
73
|
]
|
68
74
|
end
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@ten_xs = 'x{10,10}'
|
77
|
-
end
|
76
|
+
let(:one_space) { ' ' }
|
77
|
+
let(:three_spaces) { ' {3,3}' }
|
78
|
+
let(:six_spaces) { ' {6,6}' }
|
79
|
+
let(:nine_spaces) { ' {9,9}' }
|
80
|
+
let(:five_xs) { 'x{5,5}' }
|
81
|
+
let(:ten_xs) { 'x{10,10}' }
|
78
82
|
|
79
83
|
context 'no border' do
|
80
84
|
context 'no wrap' do
|
81
85
|
it 'outputs a single column' do
|
82
|
-
subject.add(
|
83
|
-
subject.
|
86
|
+
subject.add(cols[0])
|
87
|
+
expect(subject).to receive(:puts).with(/^asdf#{@six_pieces}/)
|
84
88
|
subject.output
|
85
89
|
end
|
86
90
|
it 'outputs three columns' do
|
87
|
-
subject.add(
|
88
|
-
subject.add(
|
89
|
-
subject.add(
|
90
|
-
subject.
|
91
|
+
subject.add(cols[0])
|
92
|
+
subject.add(cols[1])
|
93
|
+
subject.add(cols[2])
|
94
|
+
expect(subject).to receive(:puts).with(/^asdf#{six_spaces}#{one_space}#{three_spaces}qwer#{three_spaces}#{one_space}#{six_spaces}zxcv $/)
|
91
95
|
subject.output
|
92
96
|
end
|
93
97
|
end
|
94
98
|
|
95
99
|
context 'with wrapping' do
|
96
100
|
it 'outputs a single column' do
|
97
|
-
subject.add(
|
98
|
-
subject.
|
99
|
-
subject.
|
100
|
-
subject.
|
101
|
+
subject.add(cols[3])
|
102
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}$/)
|
103
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}$/)
|
104
|
+
expect(subject).to receive(:puts).with(/^#{five_xs}#{six_spaces}$/)
|
101
105
|
subject.output
|
102
106
|
end
|
103
107
|
|
104
108
|
it 'outputs multiple columns of the same size' do
|
105
|
-
subject.add(
|
106
|
-
subject.add(
|
107
|
-
subject.
|
108
|
-
subject.
|
109
|
-
subject.
|
109
|
+
subject.add(cols[3])
|
110
|
+
subject.add(cols[4])
|
111
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}#{ten_xs}#{one_space}$/)
|
112
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}#{ten_xs}#{one_space}$/)
|
113
|
+
expect(subject).to receive(:puts).with(/^#{five_xs}#{nine_spaces}#{five_xs}#{three_spaces}$/)
|
110
114
|
subject.output
|
111
115
|
end
|
112
116
|
|
113
117
|
it 'outputs multiple columns with different sizes' do
|
114
|
-
subject.add(
|
115
|
-
subject.add(
|
116
|
-
subject.
|
117
|
-
subject.
|
118
|
-
subject.
|
119
|
-
subject.
|
118
|
+
subject.add(cols[5])
|
119
|
+
subject.add(cols[3])
|
120
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}#{ten_xs}#{one_space}$/)
|
121
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}#{ten_xs}#{one_space}$/)
|
122
|
+
expect(subject).to receive(:puts).with(/^#{ten_xs}#{one_space}#{five_xs}#{six_spaces}$/)
|
123
|
+
expect(subject).to receive(:puts).with(/^#{five_xs} {5,17}$/)
|
120
124
|
subject.output
|
121
125
|
end
|
122
126
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'command_line_reporter'
|
4
|
+
|
5
|
+
require_relative 'support/helpers/stdout'
|
6
|
+
require_relative 'support/matchers/argument'
|