columnist 1.1.0 → 1.2.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/columnist/column.rb +37 -14
- data/lib/columnist/formatter/nested.rb +48 -48
- data/lib/columnist/formatter/progress.rb +22 -22
- data/lib/columnist/options_validator.rb +3 -3
- data/lib/columnist/row.rb +7 -7
- data/lib/columnist/table.rb +8 -8
- data/lib/columnist.rb +132 -132
- data/spec/column_spec.rb +383 -383
- data/spec/columnist.rb +626 -626
- data/spec/nested_formatter_spec.rb +292 -292
- data/spec/options_validator_spec.rb +17 -17
- data/spec/progress_formatter_spec.rb +74 -74
- data/spec/row_spec.rb +107 -107
- data/spec/support/helpers/stdout.rb +3 -3
- data/spec/support/matchers/argument.rb +12 -12
- data/spec/table_spec.rb +134 -134
- metadata +9 -9
@@ -1,89 +1,89 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Columnist::ProgressFormatter do
|
4
|
-
|
4
|
+
subject { Columnist::ProgressFormatter.instance }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe '#method default values' do
|
7
|
+
describe '#indicator' do
|
8
|
+
subject { super().indicator }
|
9
|
+
it { should == '.' }
|
10
|
+
end
|
10
11
|
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let :controls do
|
14
|
-
{
|
15
|
-
:clear => "\e[0m",
|
16
|
-
:bold => "\e[1m",
|
17
|
-
:red => "\e[31m",
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#format' do
|
22
|
-
it 'displays dots for the indicator' do
|
23
|
-
expect(subject).to receive(:print).exactly(10).times.with('.')
|
24
|
-
expect(subject).to receive(:puts).exactly(1).times
|
25
|
-
|
26
|
-
subject.format({}, lambda {
|
27
|
-
10.times {subject.progress}
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'displays colored red dots for the indicator' do
|
32
|
-
expect(subject).to receive(:print).exactly(10).times.with("#{controls[:red]}.#{controls[:clear]}")
|
33
|
-
expect(subject).to receive(:puts).exactly(1).times
|
34
12
|
|
35
|
-
|
36
|
-
|
37
|
-
|
13
|
+
let :controls do
|
14
|
+
{
|
15
|
+
:clear => "\e[0m",
|
16
|
+
:bold => "\e[1m",
|
17
|
+
:red => "\e[31m",
|
18
|
+
}
|
38
19
|
end
|
39
20
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
21
|
+
describe '#format' do
|
22
|
+
it 'displays dots for the indicator' do
|
23
|
+
expect(subject).to receive(:print).exactly(10).times.with('.')
|
24
|
+
expect(subject).to receive(:puts).exactly(1).times
|
25
|
+
|
26
|
+
subject.format({}, lambda {
|
27
|
+
10.times { subject.progress }
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'displays colored red dots for the indicator' do
|
32
|
+
expect(subject).to receive(:print).exactly(10).times.with("#{controls[:red]}.#{controls[:clear]}")
|
33
|
+
expect(subject).to receive(:puts).exactly(1).times
|
34
|
+
|
35
|
+
subject.format({ :color => 'red' }, lambda {
|
36
|
+
10.times { subject.progress }
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'displays BOLD dots for the indicator' do
|
41
|
+
expect(subject).to receive(:print).exactly(10).times.with("#{controls[:bold]}.#{controls[:clear]}")
|
42
|
+
expect(subject).to receive(:puts).exactly(1).times
|
43
|
+
|
44
|
+
subject.format({ :bold => true }, lambda {
|
45
|
+
10.times { subject.progress }
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'uses the defined indicator' do
|
50
|
+
subject.indicator = '+'
|
51
|
+
expect(subject).to receive(:print).exactly(10).times.with('+')
|
52
|
+
expect(subject).to receive(:puts)
|
53
|
+
|
54
|
+
subject.format({}, lambda {
|
55
|
+
10.times { subject.progress }
|
56
|
+
})
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'allows override of the indicator' do
|
61
|
+
expect(subject).to receive(:print).exactly(10).times.with('=')
|
62
|
+
expect(subject).to receive(:puts)
|
63
|
+
|
64
|
+
subject.format({ :indicator => '=' }, lambda {
|
65
|
+
10.times { subject.progress }
|
66
|
+
})
|
67
|
+
end
|
47
68
|
end
|
48
69
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
subject.format({}, lambda {
|
55
|
-
10.times {subject.progress}
|
56
|
-
})
|
57
|
-
|
58
|
-
end
|
70
|
+
describe '#progress' do
|
71
|
+
it 'allows override of the indicator' do
|
72
|
+
expect(subject).to receive(:print).exactly(10).times.with('+')
|
73
|
+
expect(subject).to receive(:puts)
|
59
74
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
subject.format({:indicator => '='}, lambda {
|
65
|
-
10.times {subject.progress}
|
66
|
-
})
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '#progress' do
|
71
|
-
it 'allows override of the indicator' do
|
72
|
-
expect(subject).to receive(:print).exactly(10).times.with('+')
|
73
|
-
expect(subject).to receive(:puts)
|
74
|
-
|
75
|
-
subject.format({}, lambda {
|
76
|
-
10.times {subject.progress('+')}
|
77
|
-
})
|
78
|
-
end
|
75
|
+
subject.format({}, lambda {
|
76
|
+
10.times { subject.progress('+') }
|
77
|
+
})
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
it 'allows any indicator' do
|
81
|
+
expect(subject).to receive(:print).exactly(10).times
|
82
|
+
expect(subject).to receive(:puts)
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
subject.format({}, lambda {
|
85
|
+
10.times { |i| subject.progress(" #{i}") }
|
86
|
+
})
|
87
|
+
end
|
87
88
|
end
|
88
|
-
end
|
89
89
|
end
|
data/spec/row_spec.rb
CHANGED
@@ -1,129 +1,129 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Columnist::Row do
|
4
|
-
|
4
|
+
let(:cols) { 10.times.map { |v| Columnist::Column.new("test#{v}") } }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it 'accepts color' do
|
12
|
-
expect(Columnist::Row.new(:color => 'red').color).to eq('red')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'accepts bold' do
|
16
|
-
expect(Columnist::Row.new(:bold => true).bold).to be_true
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'output encoding should be ascii' do
|
20
|
-
expect(Columnist::Row.new(:encoding => :ascii).encoding).to eq(:ascii)
|
21
|
-
end
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'accepts header' do
|
8
|
+
expect(Columnist::Row.new(:header => true).header).to be_true
|
9
|
+
end
|
22
10
|
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
it 'accepts color' do
|
12
|
+
expect(Columnist::Row.new(:color => 'red').color).to eq('red')
|
13
|
+
end
|
26
14
|
|
27
|
-
|
15
|
+
it 'accepts bold' do
|
16
|
+
expect(Columnist::Row.new(:bold => true).bold).to be_true
|
17
|
+
end
|
28
18
|
|
29
|
-
|
30
|
-
|
19
|
+
it 'output encoding should be ascii' do
|
20
|
+
expect(Columnist::Row.new(:encoding => :ascii).encoding).to eq(:ascii)
|
21
|
+
end
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
expect(subject.columns[0]).to eq(cols[0])
|
36
|
-
subject.add(cols[1])
|
37
|
-
expect(subject.columns).to eq(cols[0,2])
|
38
|
-
end
|
23
|
+
it 'output encoding should be unicode' do
|
24
|
+
expect(Columnist::Row.new.encoding).to eq(:unicode)
|
25
|
+
end
|
39
26
|
|
40
|
-
it 'defaults colors on columns' do
|
41
|
-
row = Columnist::Row.new(:color => 'red')
|
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')
|
46
27
|
end
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
row = Columnist::Row.new(:color => 'red')
|
51
|
-
row.add(col)
|
52
|
-
expect(row.columns[0].color).to eq('blue')
|
53
|
-
end
|
29
|
+
describe '#add' do
|
30
|
+
subject { Columnist::Row.new }
|
54
31
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#output' do
|
65
|
-
let :cols do
|
66
|
-
[
|
67
|
-
Columnist::Column.new('asdf'),
|
68
|
-
Columnist::Column.new('qwer', :align => 'center'),
|
69
|
-
Columnist::Column.new('zxcv', :align => 'right'),
|
70
|
-
Columnist::Column.new('x' * 25, :align => 'left', :width => 10),
|
71
|
-
Columnist::Column.new('x' * 25, :align => 'center', :width => 10),
|
72
|
-
Columnist::Column.new('x' * 35, :align => 'left', :width => 10),
|
73
|
-
]
|
74
|
-
end
|
32
|
+
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])
|
38
|
+
end
|
75
39
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
context 'no border' do
|
84
|
-
context 'no wrap' do
|
85
|
-
it 'outputs a single column' do
|
86
|
-
subject.add(cols[0])
|
87
|
-
expect(subject).to receive(:puts).with(/^asdf#{@six_pieces}/)
|
88
|
-
subject.output
|
40
|
+
it 'defaults colors on columns' do
|
41
|
+
row = Columnist::Row.new(:color => 'red')
|
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')
|
89
46
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
47
|
+
|
48
|
+
it 'allows columns to override the row color' do
|
49
|
+
col = Columnist::Column.new('test', :color => 'blue')
|
50
|
+
row = Columnist::Row.new(:color => 'red')
|
51
|
+
row.add(col)
|
52
|
+
expect(row.columns[0].color).to eq('blue')
|
96
53
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
expect(subject).to receive(:puts).with(/^#{five_xs}#{six_spaces}$/)
|
105
|
-
subject.output
|
54
|
+
|
55
|
+
it 'supercedes bold on columns' do
|
56
|
+
row = Columnist::Row.new(:bold => true)
|
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
|
106
61
|
end
|
62
|
+
end
|
107
63
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
64
|
+
describe '#output' do
|
65
|
+
let :cols do
|
66
|
+
[
|
67
|
+
Columnist::Column.new('asdf'),
|
68
|
+
Columnist::Column.new('qwer', :align => 'center'),
|
69
|
+
Columnist::Column.new('zxcv', :align => 'right'),
|
70
|
+
Columnist::Column.new('x' * 25, :align => 'left', :width => 10),
|
71
|
+
Columnist::Column.new('x' * 25, :align => 'center', :width => 10),
|
72
|
+
Columnist::Column.new('x' * 35, :align => 'left', :width => 10),
|
73
|
+
]
|
115
74
|
end
|
116
75
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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}' }
|
82
|
+
|
83
|
+
context 'no border' do
|
84
|
+
context 'no wrap' do
|
85
|
+
it 'outputs a single column' do
|
86
|
+
subject.add(cols[0])
|
87
|
+
expect(subject).to receive(:puts).with(/^asdf#{@six_pieces}/)
|
88
|
+
subject.output
|
89
|
+
end
|
90
|
+
it 'outputs three columns' do
|
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 $/)
|
95
|
+
subject.output
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with wrapping' do
|
100
|
+
it 'outputs a single column' do
|
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}$/)
|
105
|
+
subject.output
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'outputs multiple columns of the same size' do
|
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}$/)
|
114
|
+
subject.output
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'outputs multiple columns with different sizes' do
|
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}$/)
|
124
|
+
subject.output
|
125
|
+
end
|
126
|
+
end
|
125
127
|
end
|
126
|
-
end
|
127
128
|
end
|
128
|
-
end
|
129
129
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
RSpec::Matchers.define :accepts_argument do |expected|
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
match do
|
3
|
+
expected.call.should raise_exception ArgumentError
|
4
|
+
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# failure_message_for_should do |actual|
|
7
|
+
# 'should raise an ArgumentError'
|
8
|
+
# end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# failure_message_for_should_not do |actual|
|
11
|
+
# 'should not raise ArgumentError'
|
12
|
+
# end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# description do
|
15
|
+
# 'validates options argument'
|
16
|
+
# end
|
17
17
|
end
|