awesome_print 1.2.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -3
- data/CHANGELOG +13 -1
- data/Gemfile +39 -1
- data/Gemfile.lock +91 -0
- data/LICENSE +1 -1
- data/README.md +3 -0
- data/lib/ap.rb +0 -0
- data/lib/awesome_print.rb +6 -1
- data/lib/awesome_print/ext/active_record.rb +2 -1
- data/lib/awesome_print/ext/mongoid.rb +1 -1
- data/lib/awesome_print/ext/ostruct.rb +27 -0
- data/lib/awesome_print/formatter.rb +1 -1
- data/lib/awesome_print/inspector.rb +0 -0
- data/lib/awesome_print/version.rb +1 -1
- data/spec/active_record_helper.rb +42 -0
- data/spec/colors_spec.rb +8 -8
- data/spec/formats_spec.rb +70 -70
- data/spec/methods_spec.rb +61 -61
- data/spec/misc_spec.rb +53 -34
- data/spec/objects_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -1
- metadata +22 -24
data/spec/methods_spec.rb
CHANGED
@@ -11,52 +11,52 @@ describe "Single method" do
|
|
11
11
|
|
12
12
|
it "plain: should handle a method with no arguments" do
|
13
13
|
method = ''.method(:upcase)
|
14
|
-
method.ai(:plain => true).
|
14
|
+
expect(method.ai(:plain => true)).to eq('String#upcase()')
|
15
15
|
end
|
16
16
|
|
17
17
|
it "color: should handle a method with no arguments" do
|
18
18
|
method = ''.method(:upcase)
|
19
|
-
method.ai.
|
19
|
+
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "plain: should handle a method with one argument" do
|
23
23
|
method = ''.method(:include?)
|
24
|
-
method.ai(:plain => true).
|
24
|
+
expect(method.ai(:plain => true)).to eq('String#include?(arg1)')
|
25
25
|
end
|
26
26
|
|
27
27
|
it "color: should handle a method with one argument" do
|
28
28
|
method = ''.method(:include?)
|
29
|
-
method.ai.
|
29
|
+
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "plain: should handle a method with two arguments" do
|
33
33
|
method = ''.method(:tr)
|
34
|
-
method.ai(:plain => true).
|
34
|
+
expect(method.ai(:plain => true)).to eq('String#tr(arg1, arg2)')
|
35
35
|
end
|
36
36
|
|
37
37
|
it "color: should handle a method with two arguments" do
|
38
38
|
method = ''.method(:tr)
|
39
|
-
method.ai.
|
39
|
+
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "plain: should handle a method with multiple arguments" do
|
43
43
|
method = ''.method(:split)
|
44
|
-
method.ai(:plain => true).
|
44
|
+
expect(method.ai(:plain => true)).to eq('String#split(*arg1)')
|
45
45
|
end
|
46
46
|
|
47
47
|
it "color: should handle a method with multiple arguments" do
|
48
48
|
method = ''.method(:split)
|
49
|
-
method.ai.
|
49
|
+
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "plain: should handle a method defined in mixin" do
|
53
53
|
method = ''.method(:is_a?)
|
54
|
-
method.ai(:plain => true).
|
54
|
+
expect(method.ai(:plain => true)).to eq('String (Kernel)#is_a?(arg1)')
|
55
55
|
end
|
56
56
|
|
57
57
|
it "color: should handle a method defined in mixin" do
|
58
58
|
method = ''.method(:is_a?)
|
59
|
-
method.ai.
|
59
|
+
expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
|
60
60
|
end
|
61
61
|
|
62
62
|
it "plain: should handle an unbound method" do
|
@@ -64,7 +64,7 @@ describe "Single method" do
|
|
64
64
|
def world; end
|
65
65
|
end
|
66
66
|
method = Hello.instance_method(:world)
|
67
|
-
method.ai(:plain => true).
|
67
|
+
expect(method.ai(:plain => true)).to eq('Hello (unbound)#world()')
|
68
68
|
end
|
69
69
|
|
70
70
|
it "color: should handle an unbound method" do
|
@@ -73,9 +73,9 @@ describe "Single method" do
|
|
73
73
|
end
|
74
74
|
method = Hello.instance_method(:world)
|
75
75
|
if RUBY_VERSION < '1.9.2'
|
76
|
-
method.ai.
|
76
|
+
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m")
|
77
77
|
else
|
78
|
-
method.ai.
|
78
|
+
expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -92,36 +92,36 @@ describe "Object methods" do
|
|
92
92
|
describe "object.methods" do
|
93
93
|
it "index: should handle object.methods" do
|
94
94
|
out = nil.methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
95
|
-
out.
|
95
|
+
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "no index: should handle object.methods" do
|
99
99
|
out = nil.methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
100
|
-
out.
|
100
|
+
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
describe "object.public_methods" do
|
105
105
|
it "index: should handle object.public_methods" do
|
106
106
|
out = nil.public_methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
107
|
-
out.
|
107
|
+
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
108
108
|
end
|
109
109
|
|
110
110
|
it "no index: should handle object.public_methods" do
|
111
111
|
out = nil.public_methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
112
|
-
out.
|
112
|
+
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe "object.private_methods" do
|
117
117
|
it "index: should handle object.private_methods" do
|
118
118
|
out = nil.private_methods.ai(:plain => true).split("\n").grep(/sleep/).first
|
119
|
-
out.
|
119
|
+
expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
120
120
|
end
|
121
121
|
|
122
122
|
it "no index: should handle object.private_methods" do
|
123
123
|
out = nil.private_methods.ai(:plain => true, :index => false).split("\n").grep(/sleep/).first
|
124
|
-
out.
|
124
|
+
expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -132,7 +132,7 @@ describe "Object methods" do
|
|
132
132
|
def m1; end
|
133
133
|
def m2; end
|
134
134
|
end
|
135
|
-
Hello.new.protected_methods.ai(:plain => true).
|
135
|
+
expect(Hello.new.protected_methods.ai(:plain => true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
|
136
136
|
end
|
137
137
|
|
138
138
|
it "no index: should handle object.protected_methods" do
|
@@ -141,9 +141,9 @@ describe "Object methods" do
|
|
141
141
|
def m3(a,b); end
|
142
142
|
end
|
143
143
|
if RUBY_VERSION < '1.9.2'
|
144
|
-
Hello.new.protected_methods.ai(:plain => true, :index => false).
|
144
|
+
expect(Hello.new.protected_methods.ai(:plain => true, :index => false)).to eq("[\n m3(arg1, arg2) Hello\n]")
|
145
145
|
else
|
146
|
-
Hello.new.protected_methods.ai(:plain => true, :index => false).
|
146
|
+
expect(Hello.new.protected_methods.ai(:plain => true, :index => false)).to eq("[\n m3(a, b) Hello\n]")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -157,8 +157,8 @@ describe "Object methods" do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
out = Hello.new.private_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
160
|
-
out.first.
|
161
|
-
out.last.
|
160
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
161
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
162
162
|
end
|
163
163
|
|
164
164
|
it "no index: should handle object.private_methods" do
|
@@ -168,9 +168,9 @@ describe "Object methods" do
|
|
168
168
|
end
|
169
169
|
out = Hello.new.private_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
170
170
|
if RUBY_VERSION < '1.9.2'
|
171
|
-
out.first.
|
171
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(arg1, arg2\)\s+Hello$/)
|
172
172
|
else
|
173
|
-
out.first.
|
173
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
@@ -184,8 +184,8 @@ describe "Object methods" do
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
out = Hello.singleton_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
187
|
-
out.first.
|
188
|
-
out.last.
|
187
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
188
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
189
189
|
end
|
190
190
|
|
191
191
|
it "no index: should handle object.singleton_methods" do
|
@@ -194,9 +194,9 @@ describe "Object methods" do
|
|
194
194
|
end
|
195
195
|
out = Hello.singleton_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
196
196
|
if RUBY_VERSION < '1.9.2'
|
197
|
-
out.first.
|
197
|
+
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello$/)
|
198
198
|
else
|
199
|
-
out.first.
|
199
|
+
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -218,8 +218,8 @@ describe "Class methods" do
|
|
218
218
|
def m2; end
|
219
219
|
end
|
220
220
|
out = Hello.instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
221
|
-
out.first.
|
222
|
-
out.last.
|
221
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
222
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "no index: should handle unbound class.instance_methods" do
|
@@ -228,9 +228,9 @@ describe "Class methods" do
|
|
228
228
|
end
|
229
229
|
out = Hello.instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
230
230
|
if RUBY_VERSION < '1.9.2'
|
231
|
-
out.first.
|
231
|
+
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
232
232
|
else
|
233
|
-
out.first.
|
233
|
+
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
234
234
|
end
|
235
235
|
end
|
236
236
|
end
|
@@ -242,8 +242,8 @@ describe "Class methods" do
|
|
242
242
|
def m2; end
|
243
243
|
end
|
244
244
|
out = Hello.public_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
245
|
-
out.first.
|
246
|
-
out.last.
|
245
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
246
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
247
247
|
end
|
248
248
|
|
249
249
|
it "no index: should handle class.public_instance_methods" do
|
@@ -252,9 +252,9 @@ describe "Class methods" do
|
|
252
252
|
end
|
253
253
|
out = Hello.public_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
254
254
|
if RUBY_VERSION < '1.9.2'
|
255
|
-
out.first.
|
255
|
+
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
256
256
|
else
|
257
|
-
out.first.
|
257
|
+
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
@@ -267,8 +267,8 @@ describe "Class methods" do
|
|
267
267
|
def m2; end
|
268
268
|
end
|
269
269
|
out = Hello.protected_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
270
|
-
out.first.
|
271
|
-
out.last.
|
270
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
271
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
272
272
|
end
|
273
273
|
|
274
274
|
it "no index: should handle class.protected_instance_methods" do
|
@@ -278,9 +278,9 @@ describe "Class methods" do
|
|
278
278
|
end
|
279
279
|
out = Hello.protected_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
280
280
|
if RUBY_VERSION < '1.9.2'
|
281
|
-
out.first.
|
281
|
+
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
282
282
|
else
|
283
|
-
out.first.
|
283
|
+
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end
|
@@ -293,8 +293,8 @@ describe "Class methods" do
|
|
293
293
|
def m2; end
|
294
294
|
end
|
295
295
|
out = Hello.private_instance_methods.ai(:plain => true).split("\n").grep(/m\d/)
|
296
|
-
out.first.
|
297
|
-
out.last.
|
296
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/)
|
297
|
+
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
298
298
|
end
|
299
299
|
|
300
300
|
it "no index: should handle class.private_instance_methods" do
|
@@ -304,9 +304,9 @@ describe "Class methods" do
|
|
304
304
|
end
|
305
305
|
out = Hello.private_instance_methods.ai(:plain => true, :index => false).split("\n").grep(/m\d/)
|
306
306
|
if RUBY_VERSION < '1.9.2'
|
307
|
-
out.first.
|
307
|
+
expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/)
|
308
308
|
else
|
309
|
-
out.first.
|
309
|
+
expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/)
|
310
310
|
end
|
311
311
|
end
|
312
312
|
end
|
@@ -327,7 +327,7 @@ if RUBY_VERSION >= '1.9.2'
|
|
327
327
|
def m1; end
|
328
328
|
end
|
329
329
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
330
|
-
out.first.
|
330
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
331
331
|
end
|
332
332
|
|
333
333
|
it ":req" do
|
@@ -335,7 +335,7 @@ if RUBY_VERSION >= '1.9.2'
|
|
335
335
|
def m1(a, b, c); end
|
336
336
|
end
|
337
337
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
338
|
-
out.first.
|
338
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/)
|
339
339
|
end
|
340
340
|
|
341
341
|
it ":opt" do
|
@@ -343,7 +343,7 @@ if RUBY_VERSION >= '1.9.2'
|
|
343
343
|
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
344
344
|
end
|
345
345
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
346
|
-
out.first.
|
346
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
|
347
347
|
end
|
348
348
|
|
349
349
|
it ":rest" do
|
@@ -351,7 +351,7 @@ if RUBY_VERSION >= '1.9.2'
|
|
351
351
|
def m1(*a); end # m1(*a)
|
352
352
|
end
|
353
353
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
354
|
-
out.first.
|
354
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
355
355
|
end
|
356
356
|
|
357
357
|
it ":block" do
|
@@ -359,7 +359,7 @@ if RUBY_VERSION >= '1.9.2'
|
|
359
359
|
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
360
360
|
end
|
361
361
|
out = Hello.new.methods.ai(:plain => true).split("\n").grep(/m1/)
|
362
|
-
out.first.
|
362
|
+
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/)
|
363
363
|
end
|
364
364
|
end
|
365
365
|
end
|
@@ -376,7 +376,7 @@ describe "Methods arrays" do
|
|
376
376
|
def self.m1; end
|
377
377
|
end
|
378
378
|
out = (Hello.methods - Class.methods).ai(:plain => true)
|
379
|
-
out.
|
379
|
+
expect(out).to eq("[\n [0] m1() Hello\n]")
|
380
380
|
end
|
381
381
|
|
382
382
|
it "obj1.methods & obj2.methods should be awesome printed" do
|
@@ -389,7 +389,7 @@ describe "Methods arrays" do
|
|
389
389
|
def self.m1; end
|
390
390
|
end
|
391
391
|
out = (Hello.methods & World.methods - Class.methods).ai(:plain => true)
|
392
|
-
out.
|
392
|
+
expect(out).to eq("[\n [0] m1() Hello\n]")
|
393
393
|
end
|
394
394
|
|
395
395
|
it "obj1.methods.grep(pattern) should be awesome printed" do
|
@@ -400,9 +400,9 @@ describe "Methods arrays" do
|
|
400
400
|
def self.m3; end
|
401
401
|
end
|
402
402
|
out = Hello.methods.grep(/^m1$/).ai(:plain => true)
|
403
|
-
out.
|
403
|
+
expect(out).to eq("[\n [0] m1() Hello\n]")
|
404
404
|
out = Hello.methods.grep(/^m\d$/).ai(:plain => true)
|
405
|
-
out.
|
405
|
+
expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
|
406
406
|
end
|
407
407
|
|
408
408
|
it "obj1.methods.grep(pattern, &block) should pass the matching string within the block" do
|
@@ -412,7 +412,7 @@ describe "Methods arrays" do
|
|
412
412
|
end
|
413
413
|
|
414
414
|
out = Hello.methods.sort.grep(/^m_(.+)$/) { $1.to_sym }
|
415
|
-
out.
|
415
|
+
expect(out).to eq([:one, :two])
|
416
416
|
end
|
417
417
|
|
418
418
|
it "obj1.methods.grep(pattern, &block) should be awesome printed" do
|
@@ -425,7 +425,7 @@ describe "Methods arrays" do
|
|
425
425
|
end
|
426
426
|
|
427
427
|
out = Hello.methods.grep(/^m(\d)$/) { %w(none one)[$1.to_i] }.ai(:plain => true)
|
428
|
-
out.
|
428
|
+
expect(out).to eq("[\n [0] none() Hello\n [1] one() Hello\n]")
|
429
429
|
end
|
430
430
|
|
431
431
|
# See https://github.com/michaeldv/awesome_print/issues/30 for details.
|
@@ -444,16 +444,16 @@ describe "Methods arrays" do
|
|
444
444
|
end
|
445
445
|
|
446
446
|
hello = Hello.new
|
447
|
-
(hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }.
|
447
|
+
expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq([ :him, :his ])
|
448
448
|
end
|
449
449
|
|
450
450
|
it "appending garbage to methods array should not raise error" do
|
451
451
|
arr = 42.methods << [ :wtf ]
|
452
|
-
arr.ai(:plain => true).
|
452
|
+
expect { arr.ai(:plain => true) }.not_to raise_error
|
453
453
|
if RUBY_VERSION < '1.9.2'
|
454
|
-
arr.ai(:plain => true).
|
454
|
+
expect(arr.ai(:plain => true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf"
|
455
455
|
else
|
456
|
-
arr.ai(:plain => true).
|
456
|
+
expect(arr.ai(:plain => true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf]
|
457
457
|
end
|
458
458
|
end
|
459
459
|
end
|
data/spec/misc_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe "AwesomePrint" do
|
|
13
13
|
nil
|
14
14
|
end
|
15
15
|
end
|
16
|
-
weird.new.ai(:plain => true).
|
16
|
+
expect(weird.new.ai(:plain => true)).to eq('')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "handle frozen object.inspect" do
|
@@ -22,14 +22,14 @@ describe "AwesomePrint" do
|
|
22
22
|
"ice".freeze
|
23
23
|
end
|
24
24
|
end
|
25
|
-
weird.new.ai(:plain => false).
|
25
|
+
expect(weird.new.ai(:plain => false)).to eq("ice")
|
26
26
|
end
|
27
27
|
|
28
28
|
# See https://github.com/michaeldv/awesome_print/issues/35
|
29
29
|
it "handle array grep when pattern contains / chapacter" do
|
30
30
|
hash = { "1/x" => 1, "2//x" => :"2" }
|
31
31
|
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
32
|
-
grepped.ai(:plain => true, :multiline => false).
|
32
|
+
expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ "1", "2" ]')
|
33
33
|
end
|
34
34
|
|
35
35
|
# See https://github.com/michaeldv/awesome_print/issues/85
|
@@ -37,25 +37,44 @@ describe "AwesomePrint" do
|
|
37
37
|
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
38
38
|
arr = (0..6).to_a
|
39
39
|
grepped = arr.grep(1..4, &:succ)
|
40
|
-
grepped.ai(:plain => true, :multiline => false).
|
40
|
+
expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ 2, 3, 4, 5 ]')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns value passed as a parameter" do
|
45
45
|
object = rand
|
46
|
-
self.
|
47
|
-
(ap object).
|
46
|
+
allow(self).to receive(:puts)
|
47
|
+
expect(ap object).to eq(object)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Require different file name this time (lib/ap.rb vs. lib/awesome_print).
|
51
51
|
it "several require 'awesome_print' should do no harm" do
|
52
52
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/ap')
|
53
|
-
|
53
|
+
expect { rand.ai }.not_to raise_error
|
54
54
|
end
|
55
55
|
|
56
56
|
it "format ENV as hash" do
|
57
|
-
ENV.ai(:plain => true).
|
58
|
-
ENV.ai.
|
57
|
+
expect(ENV.ai(:plain => true)).to eq(ENV.to_hash.ai(:plain => true))
|
58
|
+
expect(ENV.ai).to eq(ENV.to_hash.ai)
|
59
|
+
end
|
60
|
+
|
61
|
+
# See https://github.com/michaeldv/awesome_print/issues/134
|
62
|
+
it "IPAddr workaround" do
|
63
|
+
require "ipaddr"
|
64
|
+
ipaddr = IPAddr.new("3ffe:505:2::1")
|
65
|
+
expect(ipaddr.ai).to eq("#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>")
|
66
|
+
end
|
67
|
+
|
68
|
+
# See https://github.com/michaeldv/awesome_print/issues/139
|
69
|
+
it "Object that overrides == and expects the :id method" do
|
70
|
+
weird = Class.new do
|
71
|
+
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
72
|
+
def ==(other)
|
73
|
+
self.id == other.id
|
74
|
+
end
|
75
|
+
alias :eql? :==
|
76
|
+
end
|
77
|
+
expect { weird.new.ai }.not_to raise_error
|
59
78
|
end
|
60
79
|
end
|
61
80
|
|
@@ -67,17 +86,17 @@ describe "AwesomePrint" do
|
|
67
86
|
|
68
87
|
it "wraps ap output with plain <pre> tag" do
|
69
88
|
markup = rand
|
70
|
-
markup.ai(:html => true, :plain => true).
|
89
|
+
expect(markup.ai(:html => true, :plain => true)).to eq("<pre>#{markup}</pre>")
|
71
90
|
end
|
72
91
|
|
73
92
|
it "wraps ap output with <pre> tag with colorized <kbd>" do
|
74
93
|
markup = rand
|
75
|
-
markup.ai(:html => true).
|
94
|
+
expect(markup.ai(:html => true)).to eq(%Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|)
|
76
95
|
end
|
77
96
|
|
78
97
|
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
79
98
|
markup = [ 1, :two, "three" ]
|
80
|
-
markup.ai(:html => true).
|
99
|
+
expect(markup.ai(:html => true)).to eq <<-EOS.strip
|
81
100
|
<pre>[
|
82
101
|
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
83
102
|
<kbd style="color:white">[1] </kbd><kbd style="color:darkcyan">:two</kbd>,
|
@@ -88,7 +107,7 @@ EOS
|
|
88
107
|
|
89
108
|
it "wraps hash ap output with only an outer <pre> tag" do
|
90
109
|
markup = [ { "hello" => "world" } ]
|
91
|
-
markup.ai(:html => true).
|
110
|
+
expect(markup.ai(:html => true)).to eq <<-EOS.strip
|
92
111
|
<pre>[
|
93
112
|
<kbd style="color:white">[0] </kbd>{
|
94
113
|
"hello"<kbd style="color:slategray"> => </kbd><kbd style="color:brown">"world"</kbd>
|
@@ -99,12 +118,12 @@ EOS
|
|
99
118
|
|
100
119
|
it "encodes HTML entities (plain)" do
|
101
120
|
markup = ' &<hello>'
|
102
|
-
markup.ai(:html => true, :plain => true).
|
121
|
+
expect(markup.ai(:html => true, :plain => true)).to eq('<pre>" &<hello>"</pre>')
|
103
122
|
end
|
104
123
|
|
105
124
|
it "encodes HTML entities (color)" do
|
106
125
|
markup = ' &<hello>'
|
107
|
-
markup.ai(:html => true).
|
126
|
+
expect(markup.ai(:html => true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
108
127
|
end
|
109
128
|
end
|
110
129
|
|
@@ -123,7 +142,7 @@ EOS
|
|
123
142
|
AwesomePrint.defaults = { :indent => -2, :sort_keys => true }
|
124
143
|
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
|
125
144
|
out = hash.ai(:plain => true)
|
126
|
-
out.
|
145
|
+
expect(out).to eq <<-EOS.strip
|
127
146
|
{
|
128
147
|
[ 0, 0, 255 ] => :yellow,
|
129
148
|
"magenta" => "rgb(255, 0, 255)",
|
@@ -159,25 +178,25 @@ EOS
|
|
159
178
|
it "shoud not raise ArgumentError when formatting HTML" do
|
160
179
|
out = "hello".ai(:color => { :string => :red }, :html => true)
|
161
180
|
if RUBY_VERSION >= "1.9"
|
162
|
-
out.
|
181
|
+
expect(out).to eq(%Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
163
182
|
else
|
164
|
-
out.
|
183
|
+
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
165
184
|
end
|
166
185
|
end
|
167
186
|
|
168
187
|
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
169
188
|
out = "hello".ai(:color => { :string => :redish }, :html => true)
|
170
|
-
out.
|
189
|
+
expect(out).to eq(%Q|<pre><kbd style="color:darkred">"hello"</kbd></pre>|)
|
171
190
|
end
|
172
191
|
|
173
192
|
it "shoud not raise ArgumentError when formatting non-HTML" do
|
174
193
|
out = "hello".ai(:color => { :string => :red }, :html => false)
|
175
|
-
out.
|
194
|
+
expect(out).to eq(%Q|[red]"hello"[/red]|)
|
176
195
|
end
|
177
196
|
|
178
197
|
it "shoud not raise ArgumentError when formatting non-HTML (shade color)" do
|
179
198
|
out = "hello".ai(:color => { :string => :redish }, :html => false)
|
180
|
-
out.
|
199
|
+
expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|)
|
181
200
|
end
|
182
201
|
end
|
183
202
|
|
@@ -185,23 +204,23 @@ EOS
|
|
185
204
|
describe "Console" do
|
186
205
|
it "should detect IRB" do
|
187
206
|
class IRB; end
|
188
|
-
AwesomePrint.console
|
189
|
-
AwesomePrint.rails_console
|
207
|
+
expect(AwesomePrint.console?).to eq(true)
|
208
|
+
expect(AwesomePrint.rails_console?).to eq(false)
|
190
209
|
Object.instance_eval{ remove_const :IRB }
|
191
210
|
end
|
192
211
|
|
193
212
|
it "should detect Pry" do
|
194
213
|
class Pry; end
|
195
|
-
AwesomePrint.console
|
196
|
-
AwesomePrint.rails_console
|
214
|
+
expect(AwesomePrint.console?).to eq(true)
|
215
|
+
expect(AwesomePrint.rails_console?).to eq(false)
|
197
216
|
Object.instance_eval{ remove_const :Pry }
|
198
217
|
end
|
199
218
|
|
200
219
|
it "should detect Rails::Console" do
|
201
220
|
class IRB; end
|
202
|
-
|
203
|
-
AwesomePrint.console
|
204
|
-
AwesomePrint.rails_console
|
221
|
+
module Rails; class Console; end; end
|
222
|
+
expect(AwesomePrint.console?).to eq(true)
|
223
|
+
expect(AwesomePrint.rails_console?).to eq(true)
|
205
224
|
Object.instance_eval{ remove_const :IRB }
|
206
225
|
Object.instance_eval{ remove_const :Rails }
|
207
226
|
end
|
@@ -209,20 +228,20 @@ EOS
|
|
209
228
|
it "should detect ENV['RAILS_ENV']" do
|
210
229
|
class Pry; end
|
211
230
|
ENV["RAILS_ENV"] = "development"
|
212
|
-
AwesomePrint.console
|
213
|
-
AwesomePrint.rails_console
|
231
|
+
expect(AwesomePrint.console?).to eq(true)
|
232
|
+
expect(AwesomePrint.rails_console?).to eq(true)
|
214
233
|
Object.instance_eval{ remove_const :Pry }
|
215
234
|
end
|
216
235
|
|
217
236
|
it "should return the actual object when *not* running under console" do
|
218
|
-
capture! { ap([ 1, 2, 3 ]) }.
|
219
|
-
capture! { ap({ :a => 1 }) }.
|
237
|
+
expect(capture! { ap([ 1, 2, 3 ]) }).to eq([ 1, 2, 3 ])
|
238
|
+
expect(capture! { ap({ :a => 1 }) }).to eq({ :a => 1 })
|
220
239
|
end
|
221
240
|
|
222
241
|
it "should return nil when running under console" do
|
223
242
|
class IRB; end
|
224
|
-
capture! { ap([ 1, 2, 3 ]) }.
|
225
|
-
capture! { ap({ :a => 1 }) }.
|
243
|
+
expect(capture! { ap([ 1, 2, 3 ]) }).to eq(nil)
|
244
|
+
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
|
226
245
|
Object.instance_eval{ remove_const :IRB }
|
227
246
|
end
|
228
247
|
end
|