bbcloud 0.6.2 → 0.7

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.
Files changed (54) hide show
  1. data/bbcloud.gemspec +1 -3
  2. data/lib/bbcloud/commands/servers-show.rb +1 -1
  3. data/lib/bbcloud/version.rb +1 -1
  4. metadata +26 -61
  5. data/lib/bbcloud/commands/servers-restart.rb +0 -30
  6. data/lib/bbcloud/vendor/hirb/.gemspec +0 -22
  7. data/lib/bbcloud/vendor/hirb/CHANGELOG.rdoc +0 -106
  8. data/lib/bbcloud/vendor/hirb/LICENSE.txt +0 -22
  9. data/lib/bbcloud/vendor/hirb/README.rdoc +0 -182
  10. data/lib/bbcloud/vendor/hirb/Rakefile +0 -35
  11. data/lib/bbcloud/vendor/hirb/lib/bond/completions/hirb.rb +0 -15
  12. data/lib/bbcloud/vendor/hirb/lib/hirb/console.rb +0 -43
  13. data/lib/bbcloud/vendor/hirb/lib/hirb/dynamic_view.rb +0 -113
  14. data/lib/bbcloud/vendor/hirb/lib/hirb/formatter.rb +0 -116
  15. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/auto_table.rb +0 -24
  16. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/object_table.rb +0 -14
  17. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/parent_child_tree.rb +0 -24
  18. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/filters.rb +0 -10
  19. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/resizer.rb +0 -82
  20. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table.rb +0 -323
  21. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/tree.rb +0 -181
  22. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/vertical_table.rb +0 -37
  23. data/lib/bbcloud/vendor/hirb/lib/hirb/helpers.rb +0 -17
  24. data/lib/bbcloud/vendor/hirb/lib/hirb/import_object.rb +0 -10
  25. data/lib/bbcloud/vendor/hirb/lib/hirb/menu.rb +0 -221
  26. data/lib/bbcloud/vendor/hirb/lib/hirb/pager.rb +0 -95
  27. data/lib/bbcloud/vendor/hirb/lib/hirb/string.rb +0 -44
  28. data/lib/bbcloud/vendor/hirb/lib/hirb/util.rb +0 -96
  29. data/lib/bbcloud/vendor/hirb/lib/hirb/version.rb +0 -3
  30. data/lib/bbcloud/vendor/hirb/lib/hirb/view.rb +0 -284
  31. data/lib/bbcloud/vendor/hirb/lib/hirb/views/couch_db.rb +0 -11
  32. data/lib/bbcloud/vendor/hirb/lib/hirb/views/misc_db.rb +0 -15
  33. data/lib/bbcloud/vendor/hirb/lib/hirb/views/mongo_db.rb +0 -14
  34. data/lib/bbcloud/vendor/hirb/lib/hirb/views/orm.rb +0 -11
  35. data/lib/bbcloud/vendor/hirb/lib/hirb/views/rails.rb +0 -19
  36. data/lib/bbcloud/vendor/hirb/lib/hirb/views.rb +0 -8
  37. data/lib/bbcloud/vendor/hirb/lib/hirb.rb +0 -81
  38. data/lib/bbcloud/vendor/hirb/test/auto_table_test.rb +0 -30
  39. data/lib/bbcloud/vendor/hirb/test/console_test.rb +0 -27
  40. data/lib/bbcloud/vendor/hirb/test/deps.rip +0 -4
  41. data/lib/bbcloud/vendor/hirb/test/dynamic_view_test.rb +0 -94
  42. data/lib/bbcloud/vendor/hirb/test/formatter_test.rb +0 -171
  43. data/lib/bbcloud/vendor/hirb/test/hirb_test.rb +0 -39
  44. data/lib/bbcloud/vendor/hirb/test/import_test.rb +0 -9
  45. data/lib/bbcloud/vendor/hirb/test/menu_test.rb +0 -239
  46. data/lib/bbcloud/vendor/hirb/test/object_table_test.rb +0 -79
  47. data/lib/bbcloud/vendor/hirb/test/pager_test.rb +0 -162
  48. data/lib/bbcloud/vendor/hirb/test/resizer_test.rb +0 -62
  49. data/lib/bbcloud/vendor/hirb/test/table_test.rb +0 -550
  50. data/lib/bbcloud/vendor/hirb/test/test_helper.rb +0 -61
  51. data/lib/bbcloud/vendor/hirb/test/tree_test.rb +0 -184
  52. data/lib/bbcloud/vendor/hirb/test/util_test.rb +0 -59
  53. data/lib/bbcloud/vendor/hirb/test/view_test.rb +0 -172
  54. data/lib/bbcloud/vendor/hirb/test/views_test.rb +0 -13
@@ -1,62 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- describe "Resizer" do
4
- def table(options)
5
- @table = Helpers::Table.new [options[:field_lengths].keys.inject({}) {|t,e| t[e] = '1'; t}]
6
- @table.field_lengths = options[:field_lengths]
7
- @table.width = options[:width]
8
- @table.max_fields = options[:max_fields] if options[:max_fields]
9
- @width, @field_lengths = @table.width, @table.field_lengths
10
- @table
11
- end
12
-
13
- it "resize ensures columns total doesn't exceed max width" do
14
- table :field_lengths=>{:f1=>135, :f2=>45, :f3=>4, :f4=>55}, :width=>195
15
- Helpers::Table::Resizer.resize!(@table)
16
- @field_lengths.values.inject {|a,e| a+=e}.should <= @width
17
- end
18
-
19
- it "resize sets columns by relative lengths" do
20
- table :field_lengths=>{:a=>30, :b=>30, :c=>40}, :width=>60
21
- Helpers::Table::Resizer.resize!(@table)
22
- @field_lengths.values.inject {|a,e| a+=e}.should <= @width
23
- @field_lengths.values.uniq.size.should.not == 1
24
- end
25
-
26
- it "resize sets all columns roughly equal when adusting long fields don't work" do
27
- table :field_lengths=>{:field1=>10, :field2=>15, :field3=>100}, :width=>20
28
- Helpers::Table::Resizer.resize!(@table)
29
- @field_lengths.values.inject {|a,e| a+=e}.should <= @width
30
- @field_lengths.values.each {|e| e.should <= 4 }
31
- end
32
-
33
- describe "add_extra_width and max_fields" do
34
- def table_and_resize(options={})
35
- defaults = {:field_lengths=>{:f1=>135, :f2=>30, :f3=>4, :f4=>100}, :width=>195, :max_fields=>{:f1=>80, :f4=>30} }
36
- @table = table defaults.merge(options)
37
- # repeated from table since instance variables aren't copied b/n contexts
38
- @width, @field_lengths = @table.width, @table.field_lengths
39
- Helpers::Table::Resizer.resize! @table
40
- end
41
-
42
- it "doesn't add to already maxed out field" do
43
- table_and_resize
44
- @field_lengths[:f3].should == 4
45
- end
46
-
47
- it "restricted before adding width" do
48
- table_and_resize
49
- @field_lengths[:f4].should <= 30
50
- end
51
-
52
- it "adds to restricted field" do
53
- table_and_resize
54
- @field_lengths[:f1].should <= 80
55
- end
56
-
57
- it "adds to unrestricted field" do
58
- table_and_resize :field_lengths=>{:f1=>135, :f2=>70, :f3=>4, :f4=>100}
59
- @field_lengths[:f2].should == 70
60
- end
61
- end
62
- end
@@ -1,550 +0,0 @@
1
- # encoding: UTF-8
2
- require File.join(File.dirname(__FILE__), 'test_helper')
3
-
4
- describe "Table" do
5
- def table(*args)
6
- Helpers::Table.render(*args)
7
- end
8
- before_all { reset_config }
9
-
10
- describe "basic table" do
11
- it "renders" do
12
- expected_table = <<-TABLE.unindent
13
- +---+---+
14
- | a | b |
15
- +---+---+
16
- | 1 | 2 |
17
- | 3 | 4 |
18
- +---+---+
19
- 2 rows in set
20
- TABLE
21
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}]).should == expected_table
22
- end
23
-
24
- it "with no headers renders" do
25
- expected_table = <<-TABLE.unindent
26
- +---+---+
27
- | 1 | 2 |
28
- +---+---+
29
- 1 row in set
30
- TABLE
31
- table([{:a=>1, :b=>2}], :headers=>false).should == expected_table
32
- end
33
-
34
- it "with no headers and nil fields renders" do
35
- expected_table = <<-TABLE.unindent
36
- +---+---+
37
- | 1 | |
38
- +---+---+
39
- 1 row in set
40
- TABLE
41
- table([{:a=>1, :b=>nil}], :headers=>false).should == expected_table
42
- end
43
-
44
- it "with string keys renders" do
45
- expected_table = <<-TABLE.unindent
46
- +---+---+
47
- | a | b |
48
- +---+---+
49
- | 1 | 2 |
50
- | 3 | 4 |
51
- +---+---+
52
- 2 rows in set
53
- TABLE
54
- table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}]).should == expected_table
55
- end
56
-
57
- it "with array only rows renders" do
58
- expected_table = <<-TABLE.unindent
59
- +---+---+
60
- | 0 | 1 |
61
- +---+---+
62
- | 1 | 2 |
63
- | 3 | 4 |
64
- +---+---+
65
- 2 rows in set
66
- TABLE
67
- table([[1,2], [3,4]]).should == expected_table
68
- end
69
-
70
- it "with too many fields defaults to vertical table" do
71
- rows = [Array.new(25, "A"* 10)]
72
- Helpers::VerticalTable.expects(:render).with(rows, anything)
73
- capture_stderr { table(rows)}.should =~ /Error/
74
- end
75
-
76
- it "with no rows renders" do
77
- table([]).should == "0 rows in set"
78
- end
79
-
80
- it "with invalid rows raises an argumenterror" do
81
- lambda { table(:a=>1) }.should.raise(ArgumentError).message.should =~ /Table must/
82
- end
83
-
84
- it "renders utf8" do
85
- expected_table = <<-TABLE.unindent
86
- +--------------------+
87
- | name |
88
- +--------------------+
89
- | アイウエオカキ |
90
- | クケコサシスセソタチツテ |
91
- | Tata l'asticote |
92
- | toto létoile PAOLI |
93
- +--------------------+
94
- 4 rows in set
95
- TABLE
96
- table([{:name=>"アイウエオカキ"}, {:name=>"クケコサシスセソタチツテ"}, {:name=>"Tata l'asticote"}, {:name=>"toto létoile PAOLI"}]).should == expected_table
97
- end
98
-
99
- it "stringifies newlines and tabs and renders" do
100
- expected_table = <<-TABLE.unindent
101
- +-----+---+
102
- | a | b |
103
- +-----+---+
104
- | 1#{'\n'} | 2 |
105
- | 3#{'\t'} | 4 |
106
- +-----+---+
107
- 2 rows in set
108
- TABLE
109
- value = [{'a'=>"1\n", 'b'=>2}, {'a'=>"3\t", 'b'=>4}]
110
- table(value).should == expected_table
111
- value.should == [{'a'=>"1\n", 'b'=>2}, {'a'=>"3\t", 'b'=>4}]
112
- end
113
-
114
- it "with a field of only array values renders values comma joined" do
115
- expected_table = <<-TABLE.unindent
116
- +----+------+
117
- | a | b |
118
- +----+------+
119
- | 1 | 1, 2 |
120
- | ok | 3, 4 |
121
- +----+------+
122
- 2 rows in set
123
- TABLE
124
- table([{:a=>1, :b=>[1,2]}, {:a=>'ok', :b=>[3,4]}]).should == expected_table
125
- end
126
-
127
- it "with filter class default doesn't override explicit filters" do
128
- expected_table = <<-TABLE.unindent
129
- +------+-------+
130
- | name | value |
131
- +------+-------+
132
- | a | 1 |
133
- +------+-------+
134
- 1 row in set
135
- TABLE
136
- table([{:name=>'a', :value=>{:b=>1}}], :filters=>{:value=>:size}).should == expected_table
137
- end
138
- end
139
-
140
- describe "table with" do
141
- it "fields option renders" do
142
- expected_table = <<-TABLE.unindent
143
- +---+---+
144
- | b | a |
145
- +---+---+
146
- | 2 | 1 |
147
- | 4 | 3 |
148
- +---+---+
149
- 2 rows in set
150
- TABLE
151
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :a]).should == expected_table
152
- end
153
-
154
- it "fields option and array only rows" do
155
- expected_table = <<-TABLE.unindent
156
- +---+---+
157
- | 0 | 2 |
158
- +---+---+
159
- | 1 | 3 |
160
- +---+---+
161
- 1 row in set
162
- TABLE
163
- table([[1,2,3]], :fields=>[0,2]).should == expected_table
164
- end
165
-
166
- it "fields and number options copies fields option and does not modify it" do
167
- options = {:fields=>[:f1], :number=>true}
168
- table([{:f1=>1, :f2=>2}], options)
169
- options[:fields].should == [:f1]
170
- end
171
-
172
- it "invalid fields option renders empty columns" do
173
- expected_table = <<-TABLE.unindent
174
- +---+---+
175
- | b | c |
176
- +---+---+
177
- | 2 | |
178
- | 4 | |
179
- +---+---+
180
- 2 rows in set
181
- TABLE
182
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :c]).should == expected_table
183
- end
184
-
185
- it "invalid field in max_fields option renders" do
186
- expected_table = <<-TABLE.unindent
187
- +------------+---+
188
- | a | b |
189
- +------------+---+
190
- | AAAAAAA... | 2 |
191
- +------------+---+
192
- 1 row in set
193
- TABLE
194
- table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>10,:c=>10}).should == expected_table
195
- end
196
-
197
- it "max_fields option with fields less than 3 characters renders" do
198
- expected_table = <<-TABLE.unindent
199
- +----+---+
200
- | a | b |
201
- +----+---+
202
- | AA | 2 |
203
- +----+---+
204
- 1 row in set
205
- TABLE
206
- table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>2}, :resize=>false).should == expected_table
207
- end
208
-
209
- it "max_fields option without resize renders" do
210
- expected_table = <<-TABLE.unindent
211
- +------------+---+
212
- | a | b |
213
- +------------+---+
214
- | AAAAAAA... | 2 |
215
- +------------+---+
216
- 1 row in set
217
- TABLE
218
- table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>10}, :resize=>false).should == expected_table
219
- end
220
-
221
- it "max_fields option with percentage renders" do
222
- expected_table = <<-TABLE.unindent
223
- +------------------+---+
224
- | a | b |
225
- +------------------+---+
226
- | AAAAAAAAAAAAA... | 2 |
227
- +------------------+---+
228
- 1 row in set
229
- TABLE
230
- table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>'0.15'}).should == expected_table
231
- end
232
-
233
- it "max_width option renders" do
234
- expected_table = <<-TABLE.unindent
235
- +-----------+---+------------+
236
- | a | b | c |
237
- +-----------+---+------------+
238
- | AAAAAA... | 2 | CCCCCCCCCC |
239
- +-----------+---+------------+
240
- 1 row in set
241
- TABLE
242
- table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}], :max_width=>30).should == expected_table
243
- end
244
-
245
- it "resize option false renders full table" do
246
- expected_table = <<-TABLE.unindent
247
- +----------------------------------------------------+---+------------+
248
- | a | b | c |
249
- +----------------------------------------------------+---+------------+
250
- | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | 2 | CCCCCCCCCC |
251
- +----------------------------------------------------+---+------------+
252
- 1 row in set
253
- TABLE
254
- table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}], :resize=>false).should == expected_table
255
- end
256
-
257
- it "global width renders" do
258
- expected_table = <<-TABLE.unindent
259
- +-----------+---+------------+
260
- | a | b | c |
261
- +-----------+---+------------+
262
- | AAAAAA... | 2 | CCCCCCCCCC |
263
- +-----------+---+------------+
264
- 1 row in set
265
- TABLE
266
- View.load_config
267
- View.resize(30)
268
- table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}]).should == expected_table
269
- reset_config
270
- end
271
-
272
- it "headers option and headers longer than fields renders" do
273
- expected_table = <<-TABLE.unindent
274
- +---+---------+---------+
275
- | a | field B | field C |
276
- +---+---------+---------+
277
- | A | 2 | C |
278
- +---+---------+---------+
279
- 1 row in set
280
- TABLE
281
- table([{:a=> "A", :b=>2, :c=>"C"}], :headers=>{:b=>"field B", :c=>"field C"}).should == expected_table
282
- end
283
-
284
- it "headers option and headers shortened by max_fields renders" do
285
- expected_table = <<-TABLE.unindent
286
- +-------+---+
287
- | fi... | b |
288
- +-------+---+
289
- | A | 2 |
290
- +-------+---+
291
- 1 row in set
292
- TABLE
293
- table([{:a=> "A", :b=>2}], :headers=>{:a=>"field A"}, :max_fields=>{:a=>5}, :resize=>false).should == expected_table
294
- end
295
-
296
- it "headers option as an array renders" do
297
- expected_table = <<-TABLE.unindent
298
- +---+---+
299
- | A | B |
300
- +---+---+
301
- | 1 | 2 |
302
- | 3 | 4 |
303
- +---+---+
304
- 2 rows in set
305
- TABLE
306
- table([[1,2], [3,4]], :headers=>['A', 'B']).should == expected_table
307
- end
308
-
309
- it "header_filter option renders" do
310
- expected_table = <<-TABLE.unindent
311
- +---+---+
312
- | A | B |
313
- +---+---+
314
- | 2 | 3 |
315
- +---+---+
316
- 1 row in set
317
- TABLE
318
- table([{:a=> 2, :b=>3}], :header_filter=>:capitalize).should == expected_table
319
- end
320
-
321
- it "filters option renders" do
322
- expected_table = <<-TABLE.unindent
323
- +-----------+---+
324
- | 0 | 1 |
325
- +-----------+---+
326
- | s,o,m,e | 2 |
327
- | t,h,i,n,g | 1 |
328
- +-----------+---+
329
- 2 rows in set
330
- TABLE
331
- table([['some', {:num=>2}], ['thing', {:num=>1}]], :filters=>{0=>lambda {|e| e.split("").join(",")},
332
- 1=>[:[], :num]}).should == expected_table
333
- end
334
-
335
- it "filters option calls Filters method and renders" do
336
- module ::Hirb::Helpers::Table::Filters
337
- def semicolon_join(arr); arr.join('; '); end
338
- end
339
-
340
- expected_table = <<-TABLE.unindent
341
- +------+------------------------------+
342
- | 0 | 1 |
343
- +------+------------------------------+
344
- | some | unsightly; unreadable; array |
345
- +------+------------------------------+
346
- 1 row in set
347
- TABLE
348
- table([[['some'], %w{unsightly unreadable array}]], :filters=>{1=>:semicolon_join}).should == expected_table
349
- end
350
-
351
- it "number option renders" do
352
- expected_table = <<-TABLE.unindent
353
- +--------+---+---+
354
- | number | 0 | 1 |
355
- +--------+---+---+
356
- | 1 | a | b |
357
- | 2 | c | d |
358
- +--------+---+---+
359
- 2 rows in set
360
- TABLE
361
- table([['a','b'], ['c', 'd']], :number=>true).should == expected_table
362
- end
363
-
364
- it "description option false renders" do
365
- expected_table = <<-TABLE.unindent
366
- +---+---+
367
- | 0 | 1 |
368
- +---+---+
369
- | a | b |
370
- | c | d |
371
- +---+---+
372
- TABLE
373
- table([['a','b'], ['c', 'd']], :description=>false).should == expected_table
374
- end
375
-
376
- it "vertical option renders vertical table" do
377
- expected_table = <<-TABLE.unindent
378
- *** 1. row ***
379
- a: 1
380
- b: 2
381
- *** 2. row ***
382
- a: 3
383
- b: 4
384
- 2 rows in set
385
- TABLE
386
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :vertical=>true).should == expected_table
387
- end
388
-
389
- it "vertical option renders vertical table with newlines" do
390
- expected_table = <<-TABLE.unindent
391
- *** 1. row ***
392
- a: 1
393
- b: 2
394
- *** 2. row ***
395
- a: 3
396
- b: 4
397
- and one
398
- 2 rows in set
399
- TABLE
400
- table([{:a=>1, :b=>2}, {:a=>3, :b=>"4\nand one"}], :vertical=>true).should == expected_table
401
- end
402
-
403
- it "vertical option renders vertical table successively" do
404
- expected_table = <<-TABLE.unindent
405
- *** 1. row ***
406
- a: 1
407
- b: 2
408
- *** 2. row ***
409
- a: 3
410
- b: 4
411
- 2 rows in set
412
- TABLE
413
- options = {:vertical=>true}
414
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], options).should == expected_table
415
- table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], options).should == expected_table
416
- end
417
-
418
- it "hide_empty and vertical options renders" do
419
- expected_table = <<-TABLE.unindent
420
- *** 1. row ***
421
- b: 2
422
- *** 2. row ***
423
- a: 3
424
- 2 rows in set
425
- TABLE
426
- table([{:a=>'', :b=>2}, {:a=>3, :b=>nil}], :hide_empty=>true, :vertical=>true).should == expected_table
427
- end
428
-
429
- it "all_fields option renders all fields" do
430
- expected_table = <<-TABLE.unindent
431
- +---+---+---+
432
- | a | b | c |
433
- +---+---+---+
434
- | 1 | 2 | |
435
- | 3 | | 4 |
436
- +---+---+---+
437
- 2 rows in set
438
- TABLE
439
- table([{:a=>1, :b=>2}, {:a=>3, :c=>4}], :all_fields=>true).should == expected_table
440
- end
441
-
442
- it "change_fields option renders" do
443
- expected_table = <<-TABLE.unindent
444
- +------+-------+
445
- | name | value |
446
- +------+-------+
447
- | 1 | 2 |
448
- | 2 | 3 |
449
- +------+-------+
450
- 2 rows in set
451
- TABLE
452
- table([[1,2],[2,3]], :change_fields=>{0=>'name', 1=>'value'}).should == expected_table
453
- table([[1,2],[2,3]], :change_fields=>['name', 'value']).should == expected_table
454
- end
455
-
456
- it "change_fields and fields option renders" do
457
- expected_table = <<-TABLE.unindent
458
- +------+
459
- | name |
460
- +------+
461
- | 1 |
462
- | 2 |
463
- +------+
464
- 2 rows in set
465
- TABLE
466
- table([[1,2],[2,3]], :change_fields=>['name', 'value'], :fields=>['name']).should == expected_table
467
- end
468
-
469
- it "invalid fields in change_fields options are ignored" do
470
- expected_table = <<-TABLE.unindent
471
- +------+-------+
472
- | name | value |
473
- +------+-------+
474
- | 1 | 2 |
475
- | 2 | 3 |
476
- +------+-------+
477
- 2 rows in set
478
- TABLE
479
- table([{:a=>1,:b=>2}, {:a=>2,:b=>3}], :change_fields=>{:a=>'name', :b=>'value', :c=>'time'}).should == expected_table
480
- table([[1,2],[2,3]], :change_fields=>['name', 'value','time']).should == expected_table
481
- end
482
-
483
- it "filter_any option filters any value" do
484
- expected_table = <<-TABLE.unindent
485
- +---------+
486
- | a |
487
- +---------+
488
- | {:b=>1} |
489
- | 2 |
490
- +---------+
491
- 2 rows in set
492
- TABLE
493
- table([{:a=>{:b=>1}}, {:a=>2}], :filter_any=>true).should == expected_table
494
- end
495
-
496
- it "filter_classes option overrides class-wide filter_classes" do
497
- expected_table = <<-TABLE.unindent
498
- +---+
499
- | a |
500
- +---+
501
- | 1 |
502
- +---+
503
- 1 row in set
504
- TABLE
505
- table([{:a=>{:b=>1}}], :filter_classes=>{Hash=>:size}).should == expected_table
506
- end
507
- end
508
-
509
- describe "table with callbacks" do
510
- before_all {
511
- Helpers::Table.send(:define_method, :and_one_callback) do |obj, opt|
512
- obj.each {|row| row.each {|k,v| row[k] += opt[:add] } }
513
- obj
514
- end
515
- }
516
- it "detects and runs them" do
517
- expected_table = <<-TABLE.unindent
518
- +---+---+
519
- | a | b |
520
- +---+---+
521
- | 2 | 3 |
522
- | 4 | 5 |
523
- +---+---+
524
- 2 rows in set
525
- TABLE
526
- table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}], :add=>1).should == expected_table
527
- end
528
-
529
- it "doesn't run callbacks in delete_callbacks option" do
530
- Helpers::Table.send(:define_method, :and_two_callback) do |obj, opt|
531
- obj.each {|row| row.each {|k,v| row[k] = row[k] * 2 } }
532
- obj
533
- end
534
-
535
- expected_table = <<-TABLE.unindent
536
- +---+---+
537
- | a | b |
538
- +---+---+
539
- | 2 | 3 |
540
- | 4 | 5 |
541
- +---+---+
542
- 2 rows in set
543
- TABLE
544
- table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}], :add=>1, :delete_callbacks=>[:and_two]).should == expected_table
545
-
546
- Helpers::Table.send(:remove_method, :and_two_callback)
547
- end
548
- after_all { Helpers::Table.send(:remove_method, :and_one_callback) }
549
- end
550
- end
@@ -1,61 +0,0 @@
1
- require 'bacon'
2
- require 'bacon/bits'
3
- require 'mocha'
4
- require 'mocha-on-bacon'
5
- require 'hirb'
6
- include Hirb
7
-
8
- module TestHelpers
9
- # set these to avoid invoking stty multiple times which doubles test suite running time
10
- ENV["LINES"] = ENV["COLUMNS"] = "20"
11
- def reset_terminal_size
12
- ENV["LINES"] = ENV["COLUMNS"] = "20"
13
- end
14
-
15
- def capture_stdout(&block)
16
- original_stdout = $stdout
17
- $stdout = fake = StringIO.new
18
- begin
19
- yield
20
- ensure
21
- $stdout = original_stdout
22
- end
23
- fake.string
24
- end
25
-
26
- def capture_stderr(&block)
27
- original_stderr = $stderr
28
- $stderr = fake = StringIO.new
29
- begin
30
- yield
31
- ensure
32
- $stderr = original_stderr
33
- end
34
- fake.string
35
- end
36
-
37
- def reset_config
38
- View.instance_eval "@config = nil"
39
- end
40
- end
41
-
42
- class Bacon::Context
43
- include TestHelpers
44
- end
45
-
46
- class String
47
- def unindent(num=nil)
48
- regex = num ? /^\s{#{num}}/ : /^\s*/
49
- gsub(regex, '').chomp
50
- end
51
- end
52
-
53
- # mocks IRB for View + Pager
54
- module ::IRB
55
- class Irb
56
- def initialize(context)
57
- @context = context
58
- end
59
- def output_value; end
60
- end
61
- end