amazing_print 1.0.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.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/Appraisals +60 -0
  4. data/CHANGELOG.md +2 -0
  5. data/CONTRIBUTING.md +81 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +21 -0
  8. data/README.md +356 -0
  9. data/Rakefile +23 -0
  10. data/lib/amazing_print.rb +46 -0
  11. data/lib/amazing_print/colorize.rb +25 -0
  12. data/lib/amazing_print/core_ext/awesome_method_array.rb +82 -0
  13. data/lib/amazing_print/core_ext/class.rb +23 -0
  14. data/lib/amazing_print/core_ext/kernel.rb +25 -0
  15. data/lib/amazing_print/core_ext/logger.rb +21 -0
  16. data/lib/amazing_print/core_ext/method.rb +21 -0
  17. data/lib/amazing_print/core_ext/object.rb +23 -0
  18. data/lib/amazing_print/core_ext/string.rb +42 -0
  19. data/lib/amazing_print/custom_defaults.rb +57 -0
  20. data/lib/amazing_print/ext/action_view.rb +22 -0
  21. data/lib/amazing_print/ext/active_record.rb +103 -0
  22. data/lib/amazing_print/ext/active_support.rb +45 -0
  23. data/lib/amazing_print/ext/mongo_mapper.rb +125 -0
  24. data/lib/amazing_print/ext/mongoid.rb +68 -0
  25. data/lib/amazing_print/ext/nobrainer.rb +53 -0
  26. data/lib/amazing_print/ext/nokogiri.rb +45 -0
  27. data/lib/amazing_print/ext/ostruct.rb +27 -0
  28. data/lib/amazing_print/ext/ripple.rb +71 -0
  29. data/lib/amazing_print/ext/sequel.rb +55 -0
  30. data/lib/amazing_print/formatter.rb +120 -0
  31. data/lib/amazing_print/formatters.rb +14 -0
  32. data/lib/amazing_print/formatters/array_formatter.rb +139 -0
  33. data/lib/amazing_print/formatters/base_formatter.rb +148 -0
  34. data/lib/amazing_print/formatters/class_formatter.rb +24 -0
  35. data/lib/amazing_print/formatters/dir_formatter.rb +21 -0
  36. data/lib/amazing_print/formatters/file_formatter.rb +21 -0
  37. data/lib/amazing_print/formatters/hash_formatter.rb +106 -0
  38. data/lib/amazing_print/formatters/method_formatter.rb +21 -0
  39. data/lib/amazing_print/formatters/object_formatter.rb +82 -0
  40. data/lib/amazing_print/formatters/simple_formatter.rb +20 -0
  41. data/lib/amazing_print/formatters/struct_formatter.rb +74 -0
  42. data/lib/amazing_print/indentator.rb +17 -0
  43. data/lib/amazing_print/inspector.rb +175 -0
  44. data/lib/amazing_print/version.rb +10 -0
  45. data/lib/ap.rb +10 -0
  46. data/spec/active_record_helper.rb +30 -0
  47. data/spec/colors_spec.rb +114 -0
  48. data/spec/core_ext/logger_spec.rb +44 -0
  49. data/spec/core_ext/string_spec.rb +20 -0
  50. data/spec/ext/action_view_spec.rb +17 -0
  51. data/spec/ext/active_record_spec.rb +297 -0
  52. data/spec/ext/active_support_spec.rb +26 -0
  53. data/spec/ext/mongo_mapper_spec.rb +259 -0
  54. data/spec/ext/mongoid_spec.rb +66 -0
  55. data/spec/ext/nobrainer_spec.rb +58 -0
  56. data/spec/ext/nokogiri_spec.rb +50 -0
  57. data/spec/ext/ostruct_spec.rb +22 -0
  58. data/spec/ext/ripple_spec.rb +47 -0
  59. data/spec/formats_spec.rb +779 -0
  60. data/spec/methods_spec.rb +478 -0
  61. data/spec/misc_spec.rb +245 -0
  62. data/spec/objects_spec.rb +219 -0
  63. data/spec/spec_helper.rb +106 -0
  64. data/spec/support/active_record_data.rb +20 -0
  65. data/spec/support/active_record_data/3_2_diana.txt +24 -0
  66. data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
  67. data/spec/support/active_record_data/3_2_multi.txt +50 -0
  68. data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
  69. data/spec/support/active_record_data/4_0_diana.txt +98 -0
  70. data/spec/support/active_record_data/4_0_multi.txt +198 -0
  71. data/spec/support/active_record_data/4_1_diana.txt +97 -0
  72. data/spec/support/active_record_data/4_1_multi.txt +196 -0
  73. data/spec/support/active_record_data/4_2_diana.txt +109 -0
  74. data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
  75. data/spec/support/active_record_data/4_2_multi.txt +220 -0
  76. data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
  77. data/spec/support/active_record_data/5_0_diana.txt +105 -0
  78. data/spec/support/active_record_data/5_0_multi.txt +212 -0
  79. data/spec/support/active_record_data/5_1_diana.txt +104 -0
  80. data/spec/support/active_record_data/5_1_multi.txt +210 -0
  81. data/spec/support/active_record_data/5_2_diana.txt +104 -0
  82. data/spec/support/active_record_data/5_2_multi.txt +210 -0
  83. data/spec/support/active_record_data/6_0_diana.txt +104 -0
  84. data/spec/support/active_record_data/6_0_multi.txt +210 -0
  85. data/spec/support/ext_verifier.rb +41 -0
  86. data/spec/support/mongoid_versions.rb +22 -0
  87. data/spec/support/rails_versions.rb +50 -0
  88. metadata +243 -0
@@ -0,0 +1,478 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Single method' do
4
+ after do
5
+ Object.instance_eval { remove_const :Hello } if defined?(Hello)
6
+ end
7
+
8
+ it 'plain: should handle a method with no arguments' do
9
+ method = ''.method(:upcase)
10
+ if RUBY_VERSION >= '2.4.0'
11
+ expect(method.ai(plain: true)).to eq('String#upcase(*arg1)')
12
+ else
13
+ expect(method.ai(plain: true)).to eq('String#upcase()')
14
+ end
15
+ end
16
+
17
+ it 'color: should handle a method with no arguments' do
18
+ method = ''.method(:upcase)
19
+ if RUBY_VERSION >= '2.4.0'
20
+ expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m(*arg1)\e[0m")
21
+ else
22
+ expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
23
+ end
24
+ end
25
+
26
+ it 'plain: should handle a method with one argument' do
27
+ method = ''.method(:include?)
28
+ expect(method.ai(plain: true)).to eq('String#include?(arg1)')
29
+ end
30
+
31
+ it 'color: should handle a method with one argument' do
32
+ method = ''.method(:include?)
33
+ expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
34
+ end
35
+
36
+ it 'plain: should handle a method with two arguments' do
37
+ method = ''.method(:tr)
38
+ expect(method.ai(plain: true)).to eq('String#tr(arg1, arg2)')
39
+ end
40
+
41
+ it 'color: should handle a method with two arguments' do
42
+ method = ''.method(:tr)
43
+ expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m")
44
+ end
45
+
46
+ it 'plain: should handle a method with multiple arguments' do
47
+ method = ''.method(:split)
48
+ expect(method.ai(plain: true)).to eq('String#split(*arg1)')
49
+ end
50
+
51
+ it 'color: should handle a method with multiple arguments' do
52
+ method = ''.method(:split)
53
+ expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m")
54
+ end
55
+
56
+ it 'plain: should handle a method defined in mixin' do
57
+ method = ''.method(:is_a?)
58
+ expect(method.ai(plain: true)).to eq('String (Kernel)#is_a?(arg1)')
59
+ end
60
+
61
+ it 'color: should handle a method defined in mixin' do
62
+ method = ''.method(:is_a?)
63
+ expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
64
+ end
65
+
66
+ it 'plain: should handle an unbound method' do
67
+ class Hello
68
+ def world; end
69
+ end
70
+ method = Hello.instance_method(:world)
71
+ expect(method.ai(plain: true)).to eq('Hello (unbound)#world()')
72
+ end
73
+
74
+ it 'color: should handle an unbound method' do
75
+ class Hello
76
+ def world(a, b); end
77
+ end
78
+ method = Hello.instance_method(:world)
79
+ if RUBY_VERSION < '1.9.2'
80
+ expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m")
81
+ else
82
+ expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
83
+ end
84
+ end
85
+ end
86
+
87
+ RSpec.describe 'Object methods' do
88
+ after do
89
+ Object.instance_eval { remove_const :Hello } if defined?(Hello)
90
+ end
91
+
92
+ describe 'object.methods' do
93
+ it 'index: should handle object.methods' do
94
+ out = nil.methods.ai(plain: true).split("\n").grep(/is_a\?/).first
95
+ expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
96
+ end
97
+
98
+ it 'no index: should handle object.methods' do
99
+ out = nil.methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first
100
+ expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
101
+ end
102
+ end
103
+
104
+ describe 'object.public_methods' do
105
+ it 'index: should handle object.public_methods' do
106
+ out = nil.public_methods.ai(plain: true).split("\n").grep(/is_a\?/).first
107
+ expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
108
+ end
109
+
110
+ it 'no index: should handle object.public_methods' do
111
+ out = nil.public_methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first
112
+ expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
113
+ end
114
+ end
115
+
116
+ describe 'object.private_methods' do
117
+ it 'index: should handle object.private_methods' do
118
+ out = nil.private_methods.ai(plain: true).split("\n").grep(/sleep/).first
119
+ expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
120
+ end
121
+
122
+ it 'no index: should handle object.private_methods' do
123
+ out = nil.private_methods.ai(plain: true, index: false).split("\n").grep(/sleep/).first
124
+ expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
125
+ end
126
+ end
127
+
128
+ describe 'object.protected_methods' do
129
+ it 'index: should handle object.protected_methods' do
130
+ class Hello
131
+ protected
132
+
133
+ def m1; end
134
+
135
+ def m2; end
136
+ end
137
+ expect(Hello.new.protected_methods.ai(plain: true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
138
+ end
139
+
140
+ it 'no index: should handle object.protected_methods' do
141
+ class Hello
142
+ protected
143
+
144
+ def m3(a, b); end
145
+ end
146
+ if RUBY_VERSION < '1.9.2'
147
+ expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(arg1, arg2) Hello\n]")
148
+ else
149
+ expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(a, b) Hello\n]")
150
+ end
151
+ end
152
+ end
153
+
154
+ describe 'object.private_methods' do
155
+ it 'index: should handle object.private_methods' do
156
+ class Hello
157
+ private
158
+
159
+ def m1; end
160
+
161
+ def m2; end
162
+ end
163
+
164
+ out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/)
165
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
166
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
167
+ end
168
+
169
+ it 'no index: should handle object.private_methods' do
170
+ class Hello
171
+ private
172
+
173
+ def m3(a, b); end
174
+ end
175
+ out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/)
176
+ if RUBY_VERSION < '1.9.2'
177
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(arg1, arg2\)\s+Hello$/)
178
+ else
179
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/)
180
+ end
181
+ end
182
+ end
183
+
184
+ describe 'object.singleton_methods' do
185
+ it 'index: should handle object.singleton_methods' do
186
+ class Hello
187
+ class << self
188
+ def m1; end
189
+
190
+ def m2; end
191
+ end
192
+ end
193
+ out = Hello.singleton_methods.ai(plain: true).split("\n").grep(/m\d/)
194
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
195
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
196
+ end
197
+
198
+ it 'no index: should handle object.singleton_methods' do
199
+ class Hello
200
+ def self.m3(a, b); end
201
+ end
202
+ out = Hello.singleton_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
203
+ if RUBY_VERSION < '1.9.2'
204
+ expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello$/)
205
+ else
206
+ expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/)
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ RSpec.describe 'Class methods' do
213
+ after do
214
+ Object.instance_eval { remove_const :Hello } if defined?(Hello)
215
+ end
216
+
217
+ describe 'class.instance_methods' do
218
+ it 'index: should handle unbound class.instance_methods' do
219
+ class Hello
220
+ def m1; end
221
+
222
+ def m2; end
223
+ end
224
+ out = Hello.instance_methods.ai(plain: true).split("\n").grep(/m\d/)
225
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
226
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
227
+ end
228
+
229
+ it 'no index: should handle unbound class.instance_methods' do
230
+ class Hello
231
+ def m3(a, b); end
232
+ end
233
+ out = Hello.instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
234
+ if RUBY_VERSION < '1.9.2'
235
+ expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
236
+ else
237
+ expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
238
+ end
239
+ end
240
+ end
241
+
242
+ describe 'class.public_instance_methods' do
243
+ it 'index: should handle class.public_instance_methods' do
244
+ class Hello
245
+ def m1; end
246
+
247
+ def m2; end
248
+ end
249
+ out = Hello.public_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
250
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
251
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
252
+ end
253
+
254
+ it 'no index: should handle class.public_instance_methods' do
255
+ class Hello
256
+ def m3(a, b); end
257
+ end
258
+ out = Hello.public_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
259
+ if RUBY_VERSION < '1.9.2'
260
+ expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
261
+ else
262
+ expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
263
+ end
264
+ end
265
+ end
266
+
267
+ describe 'class.protected_instance_methods' do
268
+ it 'index: should handle class.protected_instance_methods' do
269
+ class Hello
270
+ protected
271
+
272
+ def m1; end
273
+
274
+ def m2; end
275
+ end
276
+ out = Hello.protected_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
277
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
278
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
279
+ end
280
+
281
+ it 'no index: should handle class.protected_instance_methods' do
282
+ class Hello
283
+ protected
284
+
285
+ def m3(a, b); end
286
+ end
287
+ out = Hello.protected_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
288
+ if RUBY_VERSION < '1.9.2'
289
+ expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
290
+ else
291
+ expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
292
+ end
293
+ end
294
+ end
295
+
296
+ describe 'class.private_instance_methods' do
297
+ it 'index: should handle class.private_instance_methods' do
298
+ class Hello
299
+ private
300
+
301
+ def m1; end
302
+
303
+ def m2; end
304
+ end
305
+ out = Hello.private_instance_methods.ai(plain: true).split("\n").grep(/m\d/)
306
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
307
+ expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
308
+ end
309
+
310
+ it 'no index: should handle class.private_instance_methods' do
311
+ class Hello
312
+ private
313
+
314
+ def m3(a, b); end
315
+ end
316
+ out = Hello.private_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
317
+ if RUBY_VERSION < '1.9.2'
318
+ expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
319
+ else
320
+ expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
321
+ end
322
+ end
323
+ end
324
+ end
325
+
326
+ if RUBY_VERSION >= '1.9.2'
327
+ RSpec.describe 'Ruby 1.9.2+ Method#parameters' do
328
+ before do
329
+ stub_dotfile!
330
+ end
331
+
332
+ after do
333
+ Object.instance_eval { remove_const :Hello } if defined?(Hello)
334
+ end
335
+
336
+ it '()' do
337
+ class Hello
338
+ def m1; end
339
+ end
340
+ out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
341
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
342
+ end
343
+
344
+ it ':req' do
345
+ class Hello
346
+ def m1(a, b, c); end
347
+ end
348
+ out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
349
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/)
350
+ end
351
+
352
+ it ':opt' do
353
+ class Hello
354
+ def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
355
+ end
356
+ out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
357
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
358
+ end
359
+
360
+ it ':rest' do
361
+ class Hello
362
+ def m1(*a); end # m1(*a)
363
+ end
364
+ out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
365
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
366
+ end
367
+
368
+ it ':block' do
369
+ class Hello
370
+ def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
371
+ end
372
+ out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/)
373
+ expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/)
374
+ end
375
+ end
376
+ end
377
+
378
+ RSpec.describe 'Methods arrays' do
379
+ after do
380
+ Object.instance_eval { remove_const :Hello } if defined?(Hello)
381
+ Object.instance_eval { remove_const :World } if defined?(World)
382
+ end
383
+
384
+ it 'obj1.methods - obj2.methods should be awesome printed' do
385
+ stub_dotfile!
386
+ class Hello
387
+ def self.m1; end
388
+ end
389
+ out = (Hello.methods - Class.methods).ai(plain: true)
390
+ expect(out).to eq("[\n [0] m1() Hello\n]")
391
+ end
392
+
393
+ it 'obj1.methods & obj2.methods should be awesome printed' do
394
+ stub_dotfile!
395
+ class Hello
396
+ def self.m1; end
397
+
398
+ def self.m2; end
399
+ end
400
+ class World
401
+ def self.m1; end
402
+ end
403
+ out = (Hello.methods & World.methods - Class.methods).ai(plain: true)
404
+ expect(out).to eq("[\n [0] m1() Hello\n]")
405
+ end
406
+
407
+ it 'obj1.methods.grep(pattern) should be awesome printed' do
408
+ stub_dotfile!
409
+ class Hello
410
+ def self.m1; end
411
+
412
+ def self.m2; end
413
+
414
+ def self.m3; end
415
+ end
416
+ out = Hello.methods.grep(/^m1$/).ai(plain: true)
417
+ expect(out).to eq("[\n [0] m1() Hello\n]")
418
+ out = Hello.methods.grep(/^m\d$/).ai(plain: true)
419
+ expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
420
+ end
421
+
422
+ it 'obj1.methods.grep(pattern, &block) should pass the matching string within the block' do
423
+ class Hello
424
+ def self.m_one; end
425
+
426
+ def self.m_two; end
427
+ end
428
+
429
+ out = Hello.methods.sort.grep(/^m_(.+)$/) { Regexp.last_match(1).to_sym }
430
+ expect(out).to eq(%i[one two])
431
+ end
432
+
433
+ it 'obj1.methods.grep(pattern, &block) should be awesome printed' do
434
+ stub_dotfile!
435
+ class Hello
436
+ def self.m0; end
437
+
438
+ def self.none; end
439
+
440
+ def self.m1; end
441
+
442
+ def self.one; end
443
+ end
444
+
445
+ out = Hello.methods.grep(/^m(\d)$/) { %w[none one][Regexp.last_match(1).to_i] }.ai(plain: true)
446
+ expect(out).to eq("[\n [0] none() Hello\n [1] one() Hello\n]")
447
+ end
448
+
449
+ # See https://github.com/awesome-print/awesome_print/issues/30 for details.
450
+ it 'grepping methods and converting them to_sym should work as expected' do
451
+ class Hello
452
+ private
453
+
454
+ def him; end
455
+
456
+ def his
457
+ private_methods.grep(/^h..$/) { |n| n.to_sym }
458
+ end
459
+
460
+ def her
461
+ private_methods.grep(/^.e.$/) { |n| n.to_sym }
462
+ end
463
+ end
464
+
465
+ hello = Hello.new
466
+ expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq(%i[him his])
467
+ end
468
+
469
+ it 'appending garbage to methods array should not raise error' do
470
+ arr = 42.methods << [:wtf]
471
+ expect { arr.ai(plain: true) }.not_to raise_error
472
+ if RUBY_VERSION < '1.9.2'
473
+ expect(arr.ai(plain: true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf"
474
+ else
475
+ expect(arr.ai(plain: true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf]
476
+ end
477
+ end
478
+ end