amazing_print 1.5.0 → 1.7.2

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -38
  3. data/README.md +2 -2
  4. data/lib/amazing_print/core_ext/awesome_method_array.rb +1 -1
  5. data/lib/amazing_print/custom_defaults.rb +7 -1
  6. data/lib/amazing_print/ext/active_record.rb +32 -2
  7. data/lib/amazing_print/ext/mongoid.rb +14 -2
  8. data/lib/amazing_print/ext/nobrainer.rb +2 -2
  9. data/lib/amazing_print/ext_loader.rb +27 -0
  10. data/lib/amazing_print/formatters/base_formatter.rb +12 -3
  11. data/lib/amazing_print/formatters/hash_formatter.rb +28 -11
  12. data/lib/amazing_print/formatters/mswin_helper.rb +4 -4
  13. data/lib/amazing_print/formatters/object_formatter.rb +1 -1
  14. data/lib/amazing_print/formatters/struct_formatter.rb +1 -1
  15. data/lib/amazing_print/inspector.rb +6 -3
  16. data/lib/amazing_print/version.rb +1 -1
  17. data/lib/amazing_print.rb +2 -8
  18. metadata +7 -61
  19. data/.gitignore +0 -35
  20. data/Appraisals +0 -50
  21. data/Gemfile +0 -15
  22. data/Gemfile.lock +0 -83
  23. data/LICENSE +0 -22
  24. data/Rakefile +0 -25
  25. data/spec/active_record_helper.rb +0 -43
  26. data/spec/colors_spec.rb +0 -120
  27. data/spec/core_ext/logger_spec.rb +0 -70
  28. data/spec/ext/action_controller_spec.rb +0 -40
  29. data/spec/ext/action_view_spec.rb +0 -24
  30. data/spec/ext/active_model_spec.rb +0 -37
  31. data/spec/ext/active_record_spec.rb +0 -298
  32. data/spec/ext/active_support_spec.rb +0 -37
  33. data/spec/ext/mongo_mapper_spec.rb +0 -265
  34. data/spec/ext/mongoid_spec.rb +0 -72
  35. data/spec/ext/nobrainer_spec.rb +0 -64
  36. data/spec/ext/nokogiri_spec.rb +0 -52
  37. data/spec/ext/ostruct_spec.rb +0 -24
  38. data/spec/ext/ripple_spec.rb +0 -53
  39. data/spec/ext/sequel_spec.rb +0 -45
  40. data/spec/formats_spec.rb +0 -792
  41. data/spec/methods_spec.rb +0 -520
  42. data/spec/misc_spec.rb +0 -206
  43. data/spec/objects_spec.rb +0 -225
  44. data/spec/sequel_helper.rb +0 -18
  45. data/spec/spec_helper.rb +0 -112
  46. data/spec/support/active_record_data/3_2_diana.txt +0 -24
  47. data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
  48. data/spec/support/active_record_data/3_2_multi.txt +0 -50
  49. data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
  50. data/spec/support/active_record_data/4_0_diana.txt +0 -98
  51. data/spec/support/active_record_data/4_0_multi.txt +0 -198
  52. data/spec/support/active_record_data/4_1_diana.txt +0 -97
  53. data/spec/support/active_record_data/4_1_multi.txt +0 -196
  54. data/spec/support/active_record_data/4_2_diana.txt +0 -109
  55. data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
  56. data/spec/support/active_record_data/4_2_multi.txt +0 -220
  57. data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
  58. data/spec/support/active_record_data/5_0_diana.txt +0 -105
  59. data/spec/support/active_record_data/5_0_multi.txt +0 -212
  60. data/spec/support/active_record_data/5_1_diana.txt +0 -104
  61. data/spec/support/active_record_data/5_1_multi.txt +0 -210
  62. data/spec/support/active_record_data/5_2_diana.txt +0 -104
  63. data/spec/support/active_record_data/5_2_multi.txt +0 -210
  64. data/spec/support/active_record_data/6_0_diana.txt +0 -104
  65. data/spec/support/active_record_data/6_0_multi.txt +0 -210
  66. data/spec/support/active_record_data/6_1_diana.txt +0 -109
  67. data/spec/support/active_record_data/6_1_multi.txt +0 -220
  68. data/spec/support/active_record_data.rb +0 -22
  69. data/spec/support/ext_verifier.rb +0 -46
  70. data/spec/support/mongoid_versions.rb +0 -24
  71. data/spec/support/rails_versions.rb +0 -57
data/spec/formats_spec.rb DELETED
@@ -1,792 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # rubocop:disable Lint/ConstantDefinitionInBlock
4
-
5
- require 'spec_helper'
6
- require 'bigdecimal'
7
- require 'set'
8
-
9
- RSpec.describe 'AmazingPrint' do
10
- describe 'Array' do
11
- before do
12
- @arr = [1, :two, 'three', [nil, [true, false]]]
13
- end
14
-
15
- it 'empty array' do
16
- expect([].ai).to eq('[]')
17
- end
18
-
19
- it 'plain multiline' do
20
- expect(@arr.ai(plain: true)).to eq <<~EOS.strip
21
- [
22
- [0] 1,
23
- [1] :two,
24
- [2] "three",
25
- [3] [
26
- [0] nil,
27
- [1] [
28
- [0] true,
29
- [1] false
30
- ]
31
- ]
32
- ]
33
- EOS
34
- end
35
-
36
- it 'plain multiline without index' do
37
- expect(@arr.ai(plain: true, index: false)).to eq <<~EOS.strip
38
- [
39
- 1,
40
- :two,
41
- "three",
42
- [
43
- nil,
44
- [
45
- true,
46
- false
47
- ]
48
- ]
49
- ]
50
- EOS
51
- end
52
-
53
- it 'plain multiline indented' do
54
- expect(@arr.ai(plain: true, indent: 2)).to eq <<~EOS.strip
55
- [
56
- [0] 1,
57
- [1] :two,
58
- [2] "three",
59
- [3] [
60
- [0] nil,
61
- [1] [
62
- [0] true,
63
- [1] false
64
- ]
65
- ]
66
- ]
67
- EOS
68
- end
69
-
70
- it 'plain multiline indented without index' do
71
- expect(@arr.ai(plain: true, indent: 2, index: false)).to eq <<~EOS.strip
72
- [
73
- 1,
74
- :two,
75
- "three",
76
- [
77
- nil,
78
- [
79
- true,
80
- false
81
- ]
82
- ]
83
- ]
84
- EOS
85
- end
86
-
87
- it 'plain single line' do
88
- expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]')
89
- end
90
-
91
- it 'colored multiline (default)' do
92
- expect(@arr.ai).to eq <<~EOS.strip
93
- [
94
- \e[1;37m[0] \e[0m\e[1;34m1\e[0m,
95
- \e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
96
- \e[1;37m[2] \e[0m\e[0;33m"three"\e[0m,
97
- \e[1;37m[3] \e[0m[
98
- \e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
99
- \e[1;37m[1] \e[0m[
100
- \e[1;37m[0] \e[0m\e[1;32mtrue\e[0m,
101
- \e[1;37m[1] \e[0m\e[1;31mfalse\e[0m
102
- ]
103
- ]
104
- ]
105
- EOS
106
- end
107
-
108
- it 'colored multiline indented' do
109
- expect(@arr.ai(indent: 8)).to eq <<~EOS.strip
110
- [
111
- \e[1;37m[0] \e[0m\e[1;34m1\e[0m,
112
- \e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
113
- \e[1;37m[2] \e[0m\e[0;33m"three"\e[0m,
114
- \e[1;37m[3] \e[0m[
115
- \e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
116
- \e[1;37m[1] \e[0m[
117
- \e[1;37m[0] \e[0m\e[1;32mtrue\e[0m,
118
- \e[1;37m[1] \e[0m\e[1;31mfalse\e[0m
119
- ]
120
- ]
121
- ]
122
- EOS
123
- end
124
-
125
- it 'colored single line' do
126
- expect(@arr.ai(multiline: false)).to eq("[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]")
127
- end
128
- end
129
-
130
- #------------------------------------------------------------------------------
131
- describe 'Nested Array' do
132
- before do
133
- @arr = [1, 2]
134
- @arr << @arr
135
- end
136
-
137
- it 'plain multiline' do
138
- expect(@arr.ai(plain: true)).to eq <<~EOS.strip
139
- [
140
- [0] 1,
141
- [1] 2,
142
- [2] [...]
143
- ]
144
- EOS
145
- end
146
-
147
- it 'plain multiline without index' do
148
- expect(@arr.ai(plain: true, index: false)).to eq <<~EOS.strip
149
- [
150
- 1,
151
- 2,
152
- [...]
153
- ]
154
- EOS
155
- end
156
-
157
- it 'plain single line' do
158
- expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, 2, [...] ]')
159
- end
160
- end
161
-
162
- #------------------------------------------------------------------------------
163
- describe 'Limited Output Array' do
164
- before do
165
- @arr = (1..1000).to_a
166
- end
167
-
168
- it 'plain limited output large' do
169
- expect(@arr.ai(plain: true, limit: true)).to eq <<~EOS.strip
170
- [
171
- [ 0] 1,
172
- [ 1] 2,
173
- [ 2] 3,
174
- [ 3] .. [996],
175
- [997] 998,
176
- [998] 999,
177
- [999] 1000
178
- ]
179
- EOS
180
- end
181
-
182
- it 'plain limited output small' do
183
- @arr = @arr[0..3]
184
- expect(@arr.ai(plain: true, limit: true)).to eq <<~EOS.strip
185
- [
186
- [0] 1,
187
- [1] 2,
188
- [2] 3,
189
- [3] 4
190
- ]
191
- EOS
192
- end
193
-
194
- it 'plain limited output with 10 lines' do
195
- expect(@arr.ai(plain: true, limit: 10)).to eq <<~EOS.strip
196
- [
197
- [ 0] 1,
198
- [ 1] 2,
199
- [ 2] 3,
200
- [ 3] 4,
201
- [ 4] 5,
202
- [ 5] .. [995],
203
- [996] 997,
204
- [997] 998,
205
- [998] 999,
206
- [999] 1000
207
- ]
208
- EOS
209
- end
210
-
211
- it 'plain limited output with 11 lines' do
212
- expect(@arr.ai(plain: true, limit: 11)).to eq <<~EOS.strip
213
- [
214
- [ 0] 1,
215
- [ 1] 2,
216
- [ 2] 3,
217
- [ 3] 4,
218
- [ 4] 5,
219
- [ 5] .. [994],
220
- [995] 996,
221
- [996] 997,
222
- [997] 998,
223
- [998] 999,
224
- [999] 1000
225
- ]
226
- EOS
227
- end
228
- end
229
-
230
- #------------------------------------------------------------------------------
231
- describe 'Limited Output Hash' do
232
- before do
233
- @hash = ('a'..'z').inject({}) { |h, v| h.merge({ v => v.to_sym }) }
234
- end
235
-
236
- it 'plain limited output' do
237
- expect(@hash.ai(sort_keys: true, plain: true, limit: true)).to eq <<~EOS.strip
238
- {
239
- "a" => :a,
240
- "b" => :b,
241
- "c" => :c,
242
- "d" => :d .. "w" => :w,
243
- "x" => :x,
244
- "y" => :y,
245
- "z" => :z
246
- }
247
- EOS
248
- end
249
- end
250
-
251
- #------------------------------------------------------------------------------
252
- describe 'Hash' do
253
- before do
254
- @hash = { 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }
255
- end
256
-
257
- it 'empty hash' do
258
- expect({}.ai).to eq('{}')
259
- end
260
-
261
- it 'plain multiline' do
262
- expect(@hash.ai(plain: true)).to eq <<~EOS.strip
263
- {
264
- 1 => {
265
- :sym => {
266
- "str" => {
267
- [ 1, 2, 3 ] => {
268
- { :k => :v } => Hash < Object
269
- }
270
- }
271
- }
272
- }
273
- }
274
- EOS
275
- end
276
-
277
- it 'new hash syntax' do
278
- expect(@hash.ai(plain: true, ruby19_syntax: true)).to eq <<~EOS.strip
279
- {
280
- 1 => {
281
- sym: {
282
- "str" => {
283
- [ 1, 2, 3 ] => {
284
- { k: :v } => Hash < Object
285
- }
286
- }
287
- }
288
- }
289
- }
290
- EOS
291
- end
292
-
293
- it 'plain multiline indented' do
294
- expect(@hash.ai(plain: true, indent: 1)).to eq <<~EOS.strip
295
- {
296
- 1 => {
297
- :sym => {
298
- "str" => {
299
- [ 1, 2, 3 ] => {
300
- { :k => :v } => Hash < Object
301
- }
302
- }
303
- }
304
- }
305
- }
306
- EOS
307
- end
308
-
309
- it 'plain single line' do
310
- expect(@hash.ai(plain: true,
311
- multiline: false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }')
312
- end
313
-
314
- it 'colored multiline (default)' do
315
- expect(@hash.ai).to eq <<~EOS.strip
316
- {
317
- 1\e[0;37m => \e[0m{
318
- :sym\e[0;37m => \e[0m{
319
- "str"\e[0;37m => \e[0m{
320
- [ 1, 2, 3 ]\e[0;37m => \e[0m{
321
- { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
322
- }
323
- }
324
- }
325
- }
326
- }
327
- EOS
328
- end
329
-
330
- it 'colored with new hash syntax' do
331
- expect(@hash.ai(ruby19_syntax: true)).to eq <<~EOS.strip
332
- {
333
- 1\e[0;37m => \e[0m{
334
- sym: {
335
- "str"\e[0;37m => \e[0m{
336
- [ 1, 2, 3 ]\e[0;37m => \e[0m{
337
- { k: :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
338
- }
339
- }
340
- }
341
- }
342
- }
343
- EOS
344
- end
345
-
346
- it 'colored multiline indented' do
347
- expect(@hash.ai(indent: 2)).to eq <<~EOS.strip
348
- {
349
- 1\e[0;37m => \e[0m{
350
- :sym\e[0;37m => \e[0m{
351
- "str"\e[0;37m => \e[0m{
352
- [ 1, 2, 3 ]\e[0;37m => \e[0m{
353
- { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m
354
- }
355
- }
356
- }
357
- }
358
- }
359
- EOS
360
- end
361
-
362
- it 'colored single line' do
363
- expect(@hash.ai(multiline: false)).to eq("{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }")
364
- end
365
- end
366
-
367
- #------------------------------------------------------------------------------
368
- describe 'Nested Hash' do
369
- before do
370
- @hash = {}
371
- @hash[:a] = @hash
372
- end
373
-
374
- it 'plain multiline' do
375
- expect(@hash.ai(plain: true)).to eq <<~EOS.strip
376
- {
377
- :a => {...}
378
- }
379
- EOS
380
- end
381
-
382
- it 'plain single line' do
383
- expect(@hash.ai(plain: true, multiline: false)).to eq('{ :a => {...} }')
384
- end
385
- end
386
-
387
- #------------------------------------------------------------------------------
388
- describe 'Hash with several keys' do
389
- before do
390
- @hash = { 'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha' }
391
- end
392
-
393
- it 'plain multiline' do
394
- out = @hash.ai(plain: true)
395
- expect(out).to eq <<~EOS.strip
396
- {
397
- "b" => "b",
398
- :a => "a",
399
- :z => "z",
400
- "alpha" => "alpha"
401
- }
402
- EOS
403
- end
404
-
405
- it 'plain multiline with sorted keys' do
406
- expect(@hash.ai(plain: true, sort_keys: true)).to eq <<~EOS.strip
407
- {
408
- :a => "a",
409
- "alpha" => "alpha",
410
- "b" => "b",
411
- :z => "z"
412
- }
413
- EOS
414
- end
415
- end
416
-
417
- #------------------------------------------------------------------------------
418
- describe 'Negative options[:indent]' do
419
- #
420
- # With Ruby < 1.9 the order of hash keys is not defined so we can't
421
- # reliably compare the output string.
422
- #
423
- it 'hash keys must be left aligned' do
424
- hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
425
- out = hash.ai(plain: true, indent: -4, sort_keys: true)
426
- expect(out).to eq <<~EOS.strip
427
- {
428
- [ 0, 0, 255 ] => :yellow,
429
- "magenta" => "rgb(255, 0, 255)",
430
- :red => "rgb(255, 0, 0)"
431
- }
432
- EOS
433
- end
434
-
435
- it 'nested hash keys should be indented (array of hashes)' do
436
- arr = [{ a: 1, bb: 22, ccc: 333 }, { 1 => :a, 22 => :bb, 333 => :ccc }]
437
- out = arr.ai(plain: true, indent: -4, sort_keys: true)
438
- expect(out).to eq <<~EOS.strip
439
- [
440
- [0] {
441
- :a => 1,
442
- :bb => 22,
443
- :ccc => 333
444
- },
445
- [1] {
446
- 1 => :a,
447
- 22 => :bb,
448
- 333 => :ccc
449
- }
450
- ]
451
- EOS
452
- end
453
-
454
- it 'nested hash keys should be indented (hash of hashes)' do
455
- arr = { first: { a: 1, bb: 22, ccc: 333 }, second: { 1 => :a, 22 => :bb, 333 => :ccc } }
456
- out = arr.ai(plain: true, indent: -4, sort_keys: true)
457
- expect(out).to eq <<~EOS.strip
458
- {
459
- :first => {
460
- :a => 1,
461
- :bb => 22,
462
- :ccc => 333
463
- },
464
- :second => {
465
- 1 => :a,
466
- 22 => :bb,
467
- 333 => :ccc
468
- }
469
- }
470
- EOS
471
- end
472
- end
473
-
474
- #
475
- # With Ruby 1.9 syntax
476
- #
477
- it 'hash keys must be left aligned' do
478
- hash = { [0, 0, 255] => :yellow, :bloodiest_red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
479
- out = hash.ai(plain: true, indent: -2, ruby19_syntax: true, sort_keys: true)
480
- expect(out).to eq <<~EOS.strip
481
- {
482
- [ 0, 0, 255 ] => :yellow,
483
- bloodiest_red: "rgb(255, 0, 0)",
484
- "magenta" => "rgb(255, 0, 255)"
485
- }
486
- EOS
487
- end
488
-
489
- #------------------------------------------------------------------------------
490
- describe 'Class' do
491
- it 'shows superclass (plain)' do
492
- expect(self.class.ai(plain: true)).to eq("#{self.class} < #{self.class.superclass}")
493
- end
494
-
495
- it 'shows superclass (color)' do
496
- expect(self.class.ai).to eq(AmazingPrint::Colors.yellow("#{self.class} < #{self.class.superclass}"))
497
- end
498
- end
499
-
500
- #------------------------------------------------------------------------------
501
- describe 'File' do
502
- it 'displays a file (plain)', unix: true do
503
- File.open(__FILE__, 'r') do |f|
504
- expect(f.ai(plain: true)).to eq("#{f.inspect}\n" + `ls -alF #{f.path}`.chop)
505
- end
506
- end
507
-
508
- it 'displays a file (plain) akin to powershell Get-ChildItem', mswin: true do
509
- File.open(__FILE__, 'r') do |f|
510
- expect(f.ai(plain: true)).to eq("#{f.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(f.path).to_s)
511
- end
512
- end
513
- end
514
-
515
- #------------------------------------------------------------------------------
516
- describe 'Dir' do
517
- it 'displays a direcory (plain)', unix: true do
518
- Dir.open(File.dirname(__FILE__)) do |d|
519
- expect(d.ai(plain: true)).to eq("#{d.inspect}\n" + `ls -alF #{d.path}`.chop)
520
- end
521
- end
522
-
523
- it 'displays a directory (plain) akin to powershell Get-ChildItem', mswin: true do
524
- Dir.open(File.dirname(__FILE__)) do |d|
525
- expect(d.ai(plain: true)).to eq("#{d.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(d.path).to_s)
526
- end
527
- end
528
- end
529
-
530
- #------------------------------------------------------------------------------
531
- describe 'BigDecimal and Rational' do
532
- it 'presents BigDecimal object with arbitrary precision' do
533
- big = BigDecimal('201020102010201020102010201020102010.4')
534
- expect(big.ai(plain: true)).to eq('201020102010201020102010201020102010.4')
535
- end
536
-
537
- it 'presents Rational object with arbitrary precision' do
538
- rat = Rational(201_020_102_010_201_020_102_010_201_020_102_010, 2)
539
- out = rat.ai(plain: true)
540
- expect(out).to eq('100510051005100510051005100510051005/1')
541
- end
542
- end
543
-
544
- #------------------------------------------------------------------------------
545
- describe 'Utility methods' do
546
- it 'merges options' do
547
- ap = AmazingPrint::Inspector.new
548
- ap.send(:merge_options!, { color: { array: :black }, indent: 0 })
549
- options = ap.instance_variable_get('@options')
550
- expect(options[:color][:array]).to eq(:black)
551
- expect(options[:indent]).to eq(0)
552
- end
553
- end
554
-
555
- #------------------------------------------------------------------------------
556
- describe 'Set' do
557
- before do
558
- @arr = [1, :two, 'three']
559
- @set = Set.new(@arr)
560
- end
561
-
562
- it 'empty set' do
563
- expect(Set.new.ai).to eq([].ai)
564
- end
565
-
566
- it 'plain multiline' do
567
- expect(@set.ai(plain: true)).to eq(@arr.ai(plain: true))
568
- end
569
-
570
- it 'plain multiline indented' do
571
- expect(@set.ai(plain: true, indent: 1)).to eq(@arr.ai(plain: true, indent: 1))
572
- end
573
-
574
- it 'plain single line' do
575
- expect(@set.ai(plain: true, multiline: false)).to eq(@arr.ai(plain: true, multiline: false))
576
- end
577
-
578
- it 'colored multiline (default)' do
579
- expect(@set.ai).to eq(@arr.ai)
580
- end
581
- end
582
-
583
- #------------------------------------------------------------------------------
584
- describe 'Struct' do
585
- before do
586
- @struct = if defined?(Struct::SimpleStruct)
587
- Struct::SimpleStruct.new
588
- else
589
- Struct.new('SimpleStruct', :name, :address).new
590
- end
591
- @struct.name = 'Herman Munster'
592
- @struct.address = '1313 Mockingbird Lane'
593
- end
594
-
595
- it 'empty struct' do
596
- expect(Struct.new('EmptyStruct').ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
597
- end
598
-
599
- it 'plain multiline' do
600
- s1 = <<-EOS.strip
601
- address = "1313 Mockingbird Lane",
602
- name = "Herman Munster"
603
- EOS
604
- s2 = <<-EOS.strip
605
- name = "Herman Munster",
606
- address = "1313 Mockingbird Lane"
607
- EOS
608
- expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) }
609
- end
610
-
611
- it 'plain multiline indented' do
612
- s1 = <<-EOS.strip
613
- address = "1313 Mockingbird Lane",
614
- name = "Herman Munster"
615
- EOS
616
- s2 = <<-EOS.strip
617
- name = "Herman Munster",
618
- address = "1313 Mockingbird Lane"
619
- EOS
620
- expect(@struct.ai(plain: true, indent: 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
621
- end
622
-
623
- it 'plain single line' do
624
- s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"'
625
- s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"'
626
- expect(@struct.ai(plain: true, multiline: false)).to satisfy { |out| out.match(s1) || out.match(s2) }
627
- end
628
-
629
- it 'colored multiline (default)' do
630
- s1 = <<-EOS.strip
631
- address\e[0;37m = \e[0m\e[0;33m"1313 Mockingbird Lane"\e[0m,
632
- name\e[0;37m = \e[0m\e[0;33m"Herman Munster"\e[0m
633
- EOS
634
- s2 = <<-EOS.strip
635
- name\e[0;37m = \e[0m\e[0;33m"Herman Munster"\e[0m,
636
- address\e[0;37m = \e[0m\e[0;33m"1313 Mockingbird Lane"\e[0m
637
- EOS
638
- expect(@struct.ai).to satisfy { |out| out.include?(s1) || out.include?(s2) }
639
- end
640
- end
641
-
642
- #------------------------------------------------------------------------------
643
- describe 'Inherited from standard Ruby classes' do
644
- after do
645
- Object.instance_eval { remove_const :My } if defined?(My)
646
- end
647
-
648
- it 'inherited from Array should be displayed as Array' do
649
- class My < Array; end
650
-
651
- my = My.new([1, :two, 'three', [nil, [true, false]]])
652
- expect(my.ai(plain: true)).to eq <<~EOS.strip
653
- [
654
- [0] 1,
655
- [1] :two,
656
- [2] "three",
657
- [3] [
658
- [0] nil,
659
- [1] [
660
- [0] true,
661
- [1] false
662
- ]
663
- ]
664
- ]
665
- EOS
666
- end
667
-
668
- it 'inherited from Hash should be displayed as Hash' do
669
- class My < Hash; end
670
-
671
- my = My[{ 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }]
672
- expect(my.ai(plain: true)).to eq <<~EOS.strip
673
- {
674
- 1 => {
675
- :sym => {
676
- "str" => {
677
- [ 1, 2, 3 ] => {
678
- { :k => :v } => Hash < Object
679
- }
680
- }
681
- }
682
- }
683
- }
684
- EOS
685
- end
686
-
687
- it 'inherited from File should be displayed as File', unix: true do
688
- class My < File; end
689
-
690
- my = begin
691
- File.new('/dev/null')
692
- rescue StandardError
693
- File.new('nul')
694
- end
695
- expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + `ls -alF #{my.path}`.chop)
696
- end
697
-
698
- it 'inherited from File should be displayed as File', mswin: true do
699
- class My < File; end
700
- my = My.new('nul') # it's /dev/null in Windows
701
- expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(my.path).to_s)
702
- end
703
-
704
- it 'inherited from Dir should be displayed as Dir', unix: true do
705
- class My < Dir; end
706
-
707
- require 'tmpdir'
708
- my = My.new(Dir.tmpdir)
709
- expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + `ls -alF #{my.path}`.chop)
710
- end
711
-
712
- it 'inherited from Dir are displayed as Dir', mswin: true do
713
- class My < Dir; end
714
-
715
- require 'tmpdir'
716
- my = My.new(Dir.tmpdir)
717
- expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(my.path).to_s)
718
- end
719
-
720
- it 'handles a class that defines its own #send method' do
721
- class My
722
- def send(arg1, arg2, arg3); end
723
- end
724
-
725
- my = My.new
726
- expect { my.methods.ai(plain: true) }.not_to raise_error
727
- end
728
-
729
- it 'handles a class defines its own #method method (ex. request.method)' do
730
- class My
731
- def method
732
- 'POST'
733
- end
734
- end
735
-
736
- my = My.new
737
- expect { my.methods.ai(plain: true) }.not_to raise_error
738
- end
739
-
740
- describe 'should handle a class that defines its own #to_hash method' do
741
- it 'that takes arguments' do
742
- class My
743
- def to_hash(a, b); end
744
- end
745
-
746
- my = My.new
747
- expect { my.ai(plain: true) }.not_to raise_error
748
- end
749
-
750
- it 'that returns nil' do
751
- class My
752
- def to_hash
753
- nil
754
- end
755
- end
756
-
757
- my = My.new
758
- expect { my.ai(plain: true) }.not_to raise_error
759
- end
760
-
761
- it "that returns an object that doesn't support #keys" do
762
- class My
763
- def to_hash
764
- object = Object.new
765
- object.define_singleton_method('[]') { nil }
766
-
767
- object
768
- end
769
- end
770
-
771
- my = My.new
772
- expect { my.ai(plain: true) }.not_to raise_error
773
- end
774
-
775
- it "that returns an object that doesn't support subscripting" do
776
- class My
777
- def to_hash
778
- object = Object.new
779
- object.define_singleton_method(:keys) { [:foo] }
780
-
781
- object
782
- end
783
- end
784
-
785
- my = My.new
786
- expect { my.ai(plain: true) }.not_to raise_error
787
- end
788
- end
789
- end
790
- end
791
-
792
- # rubocop:enable Lint/ConstantDefinitionInBlock