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,301 +1,301 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Columnist::NestedFormatter do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#method default values' do
|
15
|
-
describe '#message_string' do
|
16
|
-
subject { super().message_string }
|
17
|
-
it { should == 'working' }
|
4
|
+
subject { Columnist::NestedFormatter.instance }
|
5
|
+
|
6
|
+
let(:controls) do
|
7
|
+
{
|
8
|
+
:clear => "\e[0m",
|
9
|
+
:bold => "\e[1m",
|
10
|
+
:red => "\e[31m",
|
11
|
+
}
|
18
12
|
end
|
19
13
|
|
20
|
-
describe '#
|
21
|
-
|
22
|
-
|
14
|
+
describe '#method default values' do
|
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
|
23
29
|
end
|
24
30
|
|
25
|
-
describe '#
|
26
|
-
|
27
|
-
|
31
|
+
describe '#format' do
|
32
|
+
context 'argument validation' do
|
33
|
+
before :each do
|
34
|
+
@indent_size = subject.indent_size
|
35
|
+
end
|
36
|
+
|
37
|
+
# Restore the singleton to its original state to ensure clean tests
|
38
|
+
after :each do
|
39
|
+
subject.indent_size = @indent_size
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises exception when there is an invalid argument' do
|
43
|
+
expect {
|
44
|
+
subject.format({ :asdf => true }, lambda {})
|
45
|
+
}.to raise_exception ArgumentError
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises an exception when a block is not given' do
|
49
|
+
expect {
|
50
|
+
subject.format({ :message => 'test' })
|
51
|
+
}.to raise_exception
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'accepts valid arguments' do
|
55
|
+
expect(subject).to receive(:puts).with('test')
|
56
|
+
expect(subject).to receive(:puts).with('complete')
|
57
|
+
|
58
|
+
expect {
|
59
|
+
subject.format({ :message => 'test' }, lambda {}) do
|
60
|
+
end
|
61
|
+
}.not_to raise_exception
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'not nested' do
|
66
|
+
before :each do
|
67
|
+
@complete_string = subject.complete_string
|
68
|
+
@indent_size = subject.indent_size
|
69
|
+
end
|
70
|
+
|
71
|
+
# Restore the singleton to its original state to ensure clean tests
|
72
|
+
after :each do
|
73
|
+
subject.complete_string = @complete_string
|
74
|
+
subject.indent_size = @indent_size
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'performs a wrapped report' do
|
78
|
+
expect(subject).to receive(:puts).with('working')
|
79
|
+
expect(subject).to receive(:puts).with('complete')
|
80
|
+
|
81
|
+
subject.format({}, lambda {})
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'performs a wrapped report with color' do
|
85
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}working#{controls[:clear]}")
|
86
|
+
expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
|
87
|
+
|
88
|
+
subject.format({ :color => 'red' }, lambda {})
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'performs a wrapped report with color' do
|
92
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}working#{controls[:clear]}")
|
93
|
+
expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
|
94
|
+
|
95
|
+
subject.format({ :bold => true }, lambda {})
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'performs a wrapped report overriding the message' do
|
99
|
+
expect(subject).to receive(:puts).with('test')
|
100
|
+
expect(subject).to receive(:puts).with('complete')
|
101
|
+
|
102
|
+
subject.format({ :message => 'test' }, lambda {})
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'performs an inline report' do
|
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')
|
110
|
+
|
111
|
+
subject.format({ :message => 'test', :type => 'inline' }, lambda {})
|
112
|
+
subject.format({ :message => 'test2', :type => 'inline' }, lambda {})
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'overrides the default for all invocations of a wrapped report' do
|
116
|
+
subject.complete_string = 'done'
|
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')
|
121
|
+
|
122
|
+
subject.format({ :message => 'test' }, lambda {})
|
123
|
+
subject.format({ :message => 'test2' }, lambda {})
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'overrides the default complete string for a wrapped report' do
|
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')
|
131
|
+
|
132
|
+
subject.format({ :message => 'test', :complete => 'done' }, lambda {})
|
133
|
+
subject.format({ :message => 'test2', :complete => 'finally' }, lambda {})
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'overrides the default complete string for an inline report' do
|
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')
|
141
|
+
|
142
|
+
subject.format({ :message => 'test', :type => 'inline', :complete => 'done' }, lambda {})
|
143
|
+
subject.format({ :message => 'test2', :type => 'inline', :complete => 'finally' }, lambda {})
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'performs another wrapped report to ensure defaul behavior' do
|
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')
|
151
|
+
|
152
|
+
subject.format({ :message => 'test' }, lambda {})
|
153
|
+
subject.format({ :message => 'test2' }, lambda {})
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'nested commands' do
|
158
|
+
before :each do
|
159
|
+
@indent_size = subject.indent_size
|
160
|
+
end
|
161
|
+
|
162
|
+
# Restore the singleton to its original state to ensure clean tests
|
163
|
+
after :each do
|
164
|
+
subject.indent_size = @indent_size
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'indents the nested wrapped messages' do
|
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')
|
172
|
+
|
173
|
+
subject.format({ :message => 'test' }, lambda {
|
174
|
+
subject.format({ :message => 'test2' }, lambda {})
|
175
|
+
})
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'indents the nested wrapped messages and outputs color' do
|
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]}")
|
183
|
+
|
184
|
+
subject.format({ :message => 'test', :color => 'red' }, lambda {
|
185
|
+
subject.format({ :message => 'test2', :color => 'red' }, lambda {})
|
186
|
+
})
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'indents the nested wrapped messages and outputs bold' do
|
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]}")
|
194
|
+
|
195
|
+
subject.format({ :message => 'test', :bold => true }, lambda {
|
196
|
+
subject.format({ :message => 'test2', :bold => true }, lambda {})
|
197
|
+
})
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'indents the multiple nested wrapped messages' do
|
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')
|
207
|
+
|
208
|
+
subject.format({ :message => 'test' }, lambda {
|
209
|
+
subject.format({ :message => 'test2' }, lambda {
|
210
|
+
subject.format({ :message => 'test3' }, lambda {})
|
211
|
+
})
|
212
|
+
})
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'indents the nested wrapped and inline messages' do
|
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')
|
220
|
+
|
221
|
+
subject.format({ :message => 'test' }, lambda {
|
222
|
+
subject.format({ :message => 'test2', :type => 'inline' }, lambda {})
|
223
|
+
})
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'indents the multiple nested wrapped messages' do
|
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')
|
233
|
+
|
234
|
+
subject.format({ :message => 'test' }, lambda {
|
235
|
+
subject.format({ :message => 'test2' }, lambda {
|
236
|
+
subject.format({ :message => 'test3', :type => 'inline' }, lambda {})
|
237
|
+
})
|
238
|
+
})
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'overrides the indent spacing of all messages' do
|
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')
|
248
|
+
|
249
|
+
subject.indent_size = 4
|
250
|
+
|
251
|
+
subject.format({ :message => 'test' }, lambda {
|
252
|
+
subject.format({ :message => 'test2' }, lambda {
|
253
|
+
subject.format({ :message => 'test3', :type => 'inline' }, lambda {})
|
254
|
+
})
|
255
|
+
})
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'overrides the indent spacing of specific message' do
|
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')
|
265
|
+
|
266
|
+
subject.indent_size = 4
|
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
|
+
})
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'performs the sums specified in the block' do
|
276
|
+
x, y, z = 0, 0, 0
|
277
|
+
|
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')
|
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 {
|
288
|
+
y = 20 - x
|
289
|
+
subject.format({ :message => 'z = x + y' }, lambda {
|
290
|
+
z = x + y
|
291
|
+
})
|
292
|
+
})
|
293
|
+
})
|
294
|
+
|
295
|
+
expect(x).to eq(10)
|
296
|
+
expect(y).to eq(10)
|
297
|
+
expect(z).to eq(20)
|
298
|
+
end
|
299
|
+
end
|
28
300
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#format' do
|
32
|
-
context 'argument validation' do
|
33
|
-
before :each do
|
34
|
-
@indent_size = subject.indent_size
|
35
|
-
end
|
36
|
-
|
37
|
-
# Restore the singleton to its original state to ensure clean tests
|
38
|
-
after :each do
|
39
|
-
subject.indent_size = @indent_size
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises exception when there is an invalid argument' do
|
43
|
-
expect {
|
44
|
-
subject.format({:asdf => true}, lambda { })
|
45
|
-
}.to raise_exception ArgumentError
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'raises an exception when a block is not given' do
|
49
|
-
expect {
|
50
|
-
subject.format({:message => 'test'})
|
51
|
-
}.to raise_exception
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'accepts valid arguments' do
|
55
|
-
expect(subject).to receive(:puts).with('test')
|
56
|
-
expect(subject).to receive(:puts).with('complete')
|
57
|
-
|
58
|
-
expect {
|
59
|
-
subject.format({:message => 'test'}, lambda { }) do
|
60
|
-
end
|
61
|
-
}.not_to raise_exception
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'not nested' do
|
66
|
-
before :each do
|
67
|
-
@complete_string = subject.complete_string
|
68
|
-
@indent_size = subject.indent_size
|
69
|
-
end
|
70
|
-
|
71
|
-
# Restore the singleton to its original state to ensure clean tests
|
72
|
-
after :each do
|
73
|
-
subject.complete_string = @complete_string
|
74
|
-
subject.indent_size = @indent_size
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'performs a wrapped report' do
|
78
|
-
expect(subject).to receive(:puts).with('working')
|
79
|
-
expect(subject).to receive(:puts).with('complete')
|
80
|
-
|
81
|
-
subject.format({ }, lambda { })
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'performs a wrapped report with color' do
|
85
|
-
expect(subject).to receive(:puts).with("#{controls[:red]}working#{controls[:clear]}")
|
86
|
-
expect(subject).to receive(:puts).with("#{controls[:red]}complete#{controls[:clear]}")
|
87
|
-
|
88
|
-
subject.format({:color => 'red'}, lambda { })
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'performs a wrapped report with color' do
|
92
|
-
expect(subject).to receive(:puts).with("#{controls[:bold]}working#{controls[:clear]}")
|
93
|
-
expect(subject).to receive(:puts).with("#{controls[:bold]}complete#{controls[:clear]}")
|
94
|
-
|
95
|
-
subject.format({:bold => true}, lambda { })
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'performs a wrapped report overriding the message' do
|
99
|
-
expect(subject).to receive(:puts).with('test')
|
100
|
-
expect(subject).to receive(:puts).with('complete')
|
101
|
-
|
102
|
-
subject.format({:message => 'test'}, lambda { })
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'performs an inline report' do
|
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')
|
110
|
-
|
111
|
-
subject.format({:message => 'test', :type => 'inline'}, lambda { })
|
112
|
-
subject.format({:message => 'test2', :type => 'inline'}, lambda { })
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'overrides the default for all invocations of a wrapped report' do
|
116
|
-
subject.complete_string = 'done'
|
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')
|
121
|
-
|
122
|
-
subject.format({:message => 'test'}, lambda { })
|
123
|
-
subject.format({:message => 'test2'}, lambda { })
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'overrides the default complete string for a wrapped report' do
|
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')
|
131
|
-
|
132
|
-
subject.format({:message => 'test', :complete => 'done'}, lambda { })
|
133
|
-
subject.format({:message => 'test2', :complete => 'finally'}, lambda { })
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'overrides the default complete string for an inline report' do
|
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')
|
141
|
-
|
142
|
-
subject.format({:message => 'test', :type => 'inline', :complete => 'done'}, lambda { })
|
143
|
-
subject.format({:message => 'test2', :type => 'inline', :complete => 'finally'}, lambda { })
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'performs another wrapped report to ensure defaul behavior' do
|
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')
|
151
|
-
|
152
|
-
subject.format({:message => 'test'}, lambda { })
|
153
|
-
subject.format({:message => 'test2'}, lambda { })
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'nested commands' do
|
158
|
-
before :each do
|
159
|
-
@indent_size = subject.indent_size
|
160
|
-
end
|
161
|
-
|
162
|
-
# Restore the singleton to its original state to ensure clean tests
|
163
|
-
after :each do
|
164
|
-
subject.indent_size = @indent_size
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'indents the nested wrapped messages' do
|
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')
|
172
|
-
|
173
|
-
subject.format({:message => 'test'}, lambda {
|
174
|
-
subject.format({:message => 'test2'}, lambda {})
|
175
|
-
})
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'indents the nested wrapped messages and outputs color' do
|
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]}")
|
183
|
-
|
184
|
-
subject.format({:message => 'test', :color => 'red'}, lambda {
|
185
|
-
subject.format({:message => 'test2', :color => 'red'}, lambda {})
|
186
|
-
})
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'indents the nested wrapped messages and outputs bold' do
|
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]}")
|
194
|
-
|
195
|
-
subject.format({:message => 'test', :bold => true}, lambda {
|
196
|
-
subject.format({:message => 'test2', :bold => true}, lambda {})
|
197
|
-
})
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'indents the multiple nested wrapped messages' do
|
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')
|
207
|
-
|
208
|
-
subject.format({:message => 'test'}, lambda {
|
209
|
-
subject.format({:message => 'test2'}, lambda {
|
210
|
-
subject.format({:message => 'test3'}, lambda { })
|
211
|
-
})
|
212
|
-
})
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'indents the nested wrapped and inline messages' do
|
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')
|
220
|
-
|
221
|
-
subject.format({:message => 'test'}, lambda {
|
222
|
-
subject.format({:message => 'test2', :type => 'inline'}, lambda { })
|
223
|
-
})
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'indents the multiple nested wrapped messages' do
|
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')
|
233
|
-
|
234
|
-
subject.format({:message => 'test'}, lambda {
|
235
|
-
subject.format({:message => 'test2'}, lambda {
|
236
|
-
subject.format({:message => 'test3', :type => 'inline'}, lambda { })
|
237
|
-
})
|
238
|
-
})
|
239
|
-
end
|
240
|
-
|
241
|
-
it 'overrides the indent spacing of all messages' do
|
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')
|
248
|
-
|
249
|
-
subject.indent_size = 4
|
250
|
-
|
251
|
-
subject.format({:message => 'test'}, lambda {
|
252
|
-
subject.format({:message => 'test2'}, lambda {
|
253
|
-
subject.format({:message => 'test3', :type => 'inline'}, lambda { })
|
254
|
-
})
|
255
|
-
})
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'overrides the indent spacing of specific message' do
|
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')
|
265
|
-
|
266
|
-
subject.indent_size = 4
|
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
|
-
})
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'performs the sums specified in the block' do
|
276
|
-
x,y,z = 0,0,0
|
277
|
-
|
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')
|
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 {
|
288
|
-
y = 20 - x
|
289
|
-
subject.format({:message => 'z = x + y'}, lambda {
|
290
|
-
z = x + y
|
291
|
-
})
|
292
|
-
})
|
293
|
-
})
|
294
|
-
|
295
|
-
expect(x).to eq(10)
|
296
|
-
expect(y).to eq(10)
|
297
|
-
expect(z).to eq(20)
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
301
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OptionsValidator do
|
4
|
-
|
4
|
+
subject { Class.new.extend(OptionsValidator) }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
it 'accepts single key options' do
|
7
|
+
expect {
|
8
|
+
subject.validate_options({ :valid => true }, :valid)
|
9
|
+
}.to_not raise_error
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
it 'rejects invalid option hashes' do
|
13
|
+
expect {
|
14
|
+
subject.validate_options({ :wrong => true }, :valid)
|
15
|
+
}.to raise_error ArgumentError
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
23
|
+
end
|
24
24
|
end
|