awesome_print 0.4.0 → 1.0.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.
- data/.gitignore +22 -0
- data/CHANGELOG +18 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +26 -0
- data/README.md +64 -16
- data/Rakefile +2 -46
- data/lib/ap.rb +3 -17
- data/lib/{ap → awesome_print}/core_ext/class.rb +7 -2
- data/lib/{ap → awesome_print}/core_ext/kernel.rb +2 -2
- data/lib/awesome_print/core_ext/logger.rb +20 -0
- data/lib/{ap → awesome_print}/core_ext/object.rb +7 -2
- data/lib/{ap → awesome_print}/core_ext/string.rb +8 -5
- data/lib/awesome_print/ext/action_view.rb +18 -0
- data/lib/awesome_print/ext/active_record.rb +64 -0
- data/lib/awesome_print/ext/active_support.rb +47 -0
- data/lib/awesome_print/ext/mongo_mapper.rb +38 -0
- data/lib/awesome_print/ext/mongoid.rb +65 -0
- data/lib/awesome_print/ext/nokogiri.rb +45 -0
- data/lib/awesome_print/formatter.rb +384 -0
- data/lib/awesome_print/inspector.rb +140 -0
- data/{rails/init.rb → lib/awesome_print/version.rb} +5 -4
- data/lib/awesome_print.rb +16 -12
- data/spec/colors_spec.rb +106 -0
- data/spec/{awesome_print_spec.rb → formats_spec.rb} +187 -37
- data/spec/methods_spec.rb +30 -0
- data/spec/objects_spec.rb +79 -0
- data/spec/spec_helper.rb +1 -1
- metadata +49 -53
- data/VERSION +0 -1
- data/init.rb +0 -1
- data/lib/ap/awesome_print.rb +0 -352
- data/lib/ap/core_ext/logger.rb +0 -18
- data/lib/ap/mixin/action_view.rb +0 -17
- data/lib/ap/mixin/active_record.rb +0 -54
- data/lib/ap/mixin/active_support.rb +0 -46
- data/lib/ap/mixin/mongo_mapper.rb +0 -54
- data/spec/action_view_spec.rb +0 -25
- data/spec/active_record_spec.rb +0 -136
- data/spec/colorization_spec.rb +0 -84
- data/spec/logger_spec.rb +0 -43
- data/spec/mongo_mapper_spec.rb +0 -63
- data/spec/string_spec.rb +0 -20
- /data/lib/{ap → awesome_print}/core_ext/array.rb +0 -0
- /data/lib/{ap → awesome_print}/core_ext/method.rb +0 -0
data/spec/colors_spec.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "AwesomePrint" do
|
|
4
|
+
def stub_tty!(output = true, stream = STDOUT)
|
|
5
|
+
if output
|
|
6
|
+
stream.instance_eval { def tty?; true; end }
|
|
7
|
+
else
|
|
8
|
+
stream.instance_eval { def tty?; false; end }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
stub_dotfile!
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "colorization" do
|
|
17
|
+
PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
|
|
18
|
+
COLORIZED = "[ \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 ] ] ]"
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
ENV['TERM'] = "xterm-colors"
|
|
22
|
+
ENV.delete('ANSICON')
|
|
23
|
+
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "default settings (no forced colors)" do
|
|
27
|
+
before do
|
|
28
|
+
AwesomePrint.force_colors! false
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "colorizes tty processes by default" do
|
|
32
|
+
stub_tty!
|
|
33
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "colorizes processes with ENV['ANSICON'] by default" do
|
|
37
|
+
begin
|
|
38
|
+
stub_tty!
|
|
39
|
+
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
|
40
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
41
|
+
ensure
|
|
42
|
+
ENV['ANSICON'] = term
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "does not colorize tty processes running in dumb terminals by default" do
|
|
47
|
+
begin
|
|
48
|
+
stub_tty!
|
|
49
|
+
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
|
50
|
+
@arr.ai(:multiline => false).should == PLAIN
|
|
51
|
+
ensure
|
|
52
|
+
ENV['TERM'] = term
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "does not colorize subprocesses by default" do
|
|
57
|
+
begin
|
|
58
|
+
stub_tty! false
|
|
59
|
+
@arr.ai(:multiline => false).should == PLAIN
|
|
60
|
+
ensure
|
|
61
|
+
stub_tty!
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "forced colors override" do
|
|
67
|
+
before do
|
|
68
|
+
AwesomePrint.force_colors!
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "still colorizes tty processes" do
|
|
72
|
+
stub_tty!
|
|
73
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
|
77
|
+
begin
|
|
78
|
+
stub_tty!
|
|
79
|
+
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
|
80
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
81
|
+
ensure
|
|
82
|
+
ENV['ANSICON'] = term
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "colorizes dumb terminals" do
|
|
87
|
+
begin
|
|
88
|
+
stub_tty!
|
|
89
|
+
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
|
90
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
91
|
+
ensure
|
|
92
|
+
ENV['TERM'] = term
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "colorizes subprocess" do
|
|
97
|
+
begin
|
|
98
|
+
stub_tty! false
|
|
99
|
+
@arr.ai(:multiline => false).should == COLORIZED
|
|
100
|
+
ensure
|
|
101
|
+
stub_tty!
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -3,12 +3,12 @@ require "bigdecimal"
|
|
|
3
3
|
require "rational"
|
|
4
4
|
|
|
5
5
|
describe "AwesomePrint" do
|
|
6
|
-
before
|
|
6
|
+
before do
|
|
7
7
|
stub_dotfile!
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
describe "Array" do
|
|
11
|
-
before
|
|
11
|
+
before do
|
|
12
12
|
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -91,14 +91,14 @@ EOS
|
|
|
91
91
|
it "colored multiline (default)" do
|
|
92
92
|
@arr.ai.should == <<-EOS.strip
|
|
93
93
|
[
|
|
94
|
-
\e[1;37m
|
|
95
|
-
\e[1;37m
|
|
96
|
-
\e[1;37m
|
|
97
|
-
\e[1;37m
|
|
98
|
-
\e[1;37m
|
|
99
|
-
\e[1;37m
|
|
100
|
-
\e[1;37m
|
|
101
|
-
\e[1;37m
|
|
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
102
|
]
|
|
103
103
|
]
|
|
104
104
|
]
|
|
@@ -108,14 +108,14 @@ EOS
|
|
|
108
108
|
it "colored multiline indented" do
|
|
109
109
|
@arr.ai(:indent => 8).should == <<-EOS.strip
|
|
110
110
|
[
|
|
111
|
-
\e[1;37m
|
|
112
|
-
\e[1;37m
|
|
113
|
-
\e[1;37m
|
|
114
|
-
\e[1;37m
|
|
115
|
-
\e[1;37m
|
|
116
|
-
\e[1;37m
|
|
117
|
-
\e[1;37m
|
|
118
|
-
\e[1;37m
|
|
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
119
|
]
|
|
120
120
|
]
|
|
121
121
|
]
|
|
@@ -129,7 +129,7 @@ EOS
|
|
|
129
129
|
|
|
130
130
|
#------------------------------------------------------------------------------
|
|
131
131
|
describe "Nested Array" do
|
|
132
|
-
before
|
|
132
|
+
before do
|
|
133
133
|
@arr = [ 1, 2 ]
|
|
134
134
|
@arr << @arr
|
|
135
135
|
end
|
|
@@ -160,8 +160,97 @@ EOS
|
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
#------------------------------------------------------------------------------
|
|
163
|
-
describe "
|
|
163
|
+
describe "Limited Output Array" do
|
|
164
|
+
before(:each) do
|
|
165
|
+
@arr = (1..1000).to_a
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "plain limited output large" do
|
|
169
|
+
@arr.ai(:plain => true, :limit => true).should == <<-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
|
+
@arr.ai(:plain => true, :limit => true).should == <<-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
|
+
@arr.ai(:plain => true, :limit => 10).should == <<-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
|
+
@arr.ai(:plain => true, :limit => 11).should == <<-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
|
|
164
232
|
before(:each) do
|
|
233
|
+
@hash = ("a".."z").inject({}) { |h, v| h.merge({ v => v.to_sym }) }
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "plain limited output" do
|
|
237
|
+
@hash.ai(:sort_keys => true, :plain => true, :limit => true).should == <<-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
|
|
165
254
|
@hash = { 1 => { :sym => { "str" => { [1, 2, 3] => { { :k => :v } => Hash } } } } }
|
|
166
255
|
end
|
|
167
256
|
|
|
@@ -245,7 +334,7 @@ EOS
|
|
|
245
334
|
|
|
246
335
|
#------------------------------------------------------------------------------
|
|
247
336
|
describe "Nested Hash" do
|
|
248
|
-
before
|
|
337
|
+
before do
|
|
249
338
|
@hash = {}
|
|
250
339
|
@hash[:a] = @hash
|
|
251
340
|
end
|
|
@@ -265,7 +354,7 @@ EOS
|
|
|
265
354
|
|
|
266
355
|
#------------------------------------------------------------------------------
|
|
267
356
|
describe "Hash with several keys" do
|
|
268
|
-
before
|
|
357
|
+
before do
|
|
269
358
|
@hash = {"b" => "b", :a => "a", :z => "z", "alpha" => "alpha"}
|
|
270
359
|
end
|
|
271
360
|
|
|
@@ -290,7 +379,7 @@ EOS
|
|
|
290
379
|
end
|
|
291
380
|
|
|
292
381
|
it "plain multiline with sorted keys" do
|
|
293
|
-
@hash.ai(:plain => true, :
|
|
382
|
+
@hash.ai(:plain => true, :sort_keys => true).should == <<-EOS.strip
|
|
294
383
|
{
|
|
295
384
|
:a => "a",
|
|
296
385
|
"alpha" => "alpha",
|
|
@@ -304,17 +393,58 @@ EOS
|
|
|
304
393
|
|
|
305
394
|
#------------------------------------------------------------------------------
|
|
306
395
|
describe "Negative options[:indent]" do
|
|
307
|
-
|
|
308
|
-
|
|
396
|
+
#
|
|
397
|
+
# With Ruby < 1.9 the order of hash keys is not defined so we can't
|
|
398
|
+
# reliably compare the output string.
|
|
399
|
+
#
|
|
400
|
+
it "hash keys must be left aligned" do
|
|
401
|
+
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
|
|
402
|
+
out = hash.ai(:plain => true, :indent => -4, :sort_keys => true)
|
|
403
|
+
out.should == <<-EOS.strip
|
|
404
|
+
{
|
|
405
|
+
[ 0, 0, 255 ] => :yellow,
|
|
406
|
+
"magenta" => "rgb(255, 0, 255)",
|
|
407
|
+
:red => "rgb(255, 0, 0)"
|
|
408
|
+
}
|
|
409
|
+
EOS
|
|
309
410
|
end
|
|
310
411
|
|
|
311
|
-
it "hash keys
|
|
312
|
-
|
|
313
|
-
out.
|
|
314
|
-
out.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
412
|
+
it "nested hash keys should be indented (array of hashes)" do
|
|
413
|
+
arr = [ { :a => 1, :bb => 22, :ccc => 333}, { 1 => :a, 22 => :bb, 333 => :ccc} ]
|
|
414
|
+
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
|
415
|
+
out.should == <<-EOS.strip
|
|
416
|
+
[
|
|
417
|
+
[0] {
|
|
418
|
+
:a => 1,
|
|
419
|
+
:bb => 22,
|
|
420
|
+
:ccc => 333
|
|
421
|
+
},
|
|
422
|
+
[1] {
|
|
423
|
+
1 => :a,
|
|
424
|
+
22 => :bb,
|
|
425
|
+
333 => :ccc
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
EOS
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
it "nested hash keys should be indented (hash of hashes)" do
|
|
432
|
+
arr = { :first => { :a => 1, :bb => 22, :ccc => 333}, :second => { 1 => :a, 22 => :bb, 333 => :ccc} }
|
|
433
|
+
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
|
434
|
+
out.should == <<-EOS.strip
|
|
435
|
+
{
|
|
436
|
+
:first => {
|
|
437
|
+
:a => 1,
|
|
438
|
+
:bb => 22,
|
|
439
|
+
:ccc => 333
|
|
440
|
+
},
|
|
441
|
+
:second => {
|
|
442
|
+
1 => :a,
|
|
443
|
+
22 => :bb,
|
|
444
|
+
333 => :ccc
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
EOS
|
|
318
448
|
end
|
|
319
449
|
end
|
|
320
450
|
|
|
@@ -363,7 +493,7 @@ EOS
|
|
|
363
493
|
#------------------------------------------------------------------------------
|
|
364
494
|
describe "Utility methods" do
|
|
365
495
|
it "should merge options" do
|
|
366
|
-
ap = AwesomePrint.new
|
|
496
|
+
ap = AwesomePrint::Inspector.new
|
|
367
497
|
ap.send(:merge_options!, { :color => { :array => :black }, :indent => 0 })
|
|
368
498
|
options = ap.instance_variable_get("@options")
|
|
369
499
|
options[:color][:array].should == :black
|
|
@@ -374,7 +504,7 @@ EOS
|
|
|
374
504
|
|
|
375
505
|
#------------------------------------------------------------------------------
|
|
376
506
|
describe "Struct" do
|
|
377
|
-
before
|
|
507
|
+
before do
|
|
378
508
|
@struct = unless defined?(Struct::SimpleStruct)
|
|
379
509
|
Struct.new("SimpleStruct", :name, :address).new
|
|
380
510
|
else
|
|
@@ -455,6 +585,15 @@ EOS
|
|
|
455
585
|
weird.new.ai(:plain => true).should == ''
|
|
456
586
|
end
|
|
457
587
|
|
|
588
|
+
it "handle frozen object.inspect" do
|
|
589
|
+
weird = Class.new do
|
|
590
|
+
def inspect
|
|
591
|
+
"ice".freeze
|
|
592
|
+
end
|
|
593
|
+
end
|
|
594
|
+
weird.new.ai(:plain => false).should == "ice"
|
|
595
|
+
end
|
|
596
|
+
|
|
458
597
|
# See https://github.com/michaeldv/awesome_print/issues/35
|
|
459
598
|
it "handle array grep when pattern contains / chapacter" do
|
|
460
599
|
hash = { "1/x" => 1, "2//x" => :"2" }
|
|
@@ -481,9 +620,20 @@ EOS
|
|
|
481
620
|
markup.ai(:html => true, :plain => true).should == "<pre>#{markup}</pre>"
|
|
482
621
|
end
|
|
483
622
|
|
|
484
|
-
it "wraps ap output with
|
|
623
|
+
it "wraps ap output with <pre> tag with colorized <kbd>" do
|
|
485
624
|
markup = rand
|
|
486
|
-
markup.ai(:html => true).should == %Q|<pre style="color:blue">#{markup}</pre>|
|
|
625
|
+
markup.ai(:html => true).should == %Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
|
629
|
+
markup = [ 1, :two, "three" ]
|
|
630
|
+
markup.ai(:html => true).should == <<-EOS.strip
|
|
631
|
+
<pre>[
|
|
632
|
+
<kbd style="color:white">[0] </kbd><pre><kbd style="color:blue">1</kbd></pre>,
|
|
633
|
+
<kbd style="color:white">[1] </kbd><pre><kbd style="color:darkcyan">:two</kbd></pre>,
|
|
634
|
+
<kbd style="color:white">[2] </kbd><pre><kbd style="color:brown">"three"</kbd></pre>
|
|
635
|
+
]</pre>
|
|
636
|
+
EOS
|
|
487
637
|
end
|
|
488
638
|
|
|
489
639
|
it "encodes HTML entities (plain)" do
|
|
@@ -493,7 +643,7 @@ EOS
|
|
|
493
643
|
|
|
494
644
|
it "encodes HTML entities (color)" do
|
|
495
645
|
markup = ' &<hello>'
|
|
496
|
-
markup.ai(:html => true).should == '<pre style="color:brown">" &<hello>"</pre>'
|
|
646
|
+
markup.ai(:html => true).should == '<pre><kbd style="color:brown">" &<hello>"</kbd></pre>'
|
|
497
647
|
end
|
|
498
648
|
end
|
|
499
649
|
|
data/spec/methods_spec.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "Single method" do
|
|
4
|
+
before do
|
|
5
|
+
stub_dotfile!
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
after do
|
|
5
9
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
6
10
|
end
|
|
@@ -77,6 +81,10 @@ describe "Single method" do
|
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
describe "Object methods" do
|
|
84
|
+
before do
|
|
85
|
+
stub_dotfile!
|
|
86
|
+
end
|
|
87
|
+
|
|
80
88
|
after do
|
|
81
89
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
82
90
|
end
|
|
@@ -194,6 +202,10 @@ describe "Object methods" do
|
|
|
194
202
|
end
|
|
195
203
|
|
|
196
204
|
describe "Class methods" do
|
|
205
|
+
before do
|
|
206
|
+
stub_dotfile!
|
|
207
|
+
end
|
|
208
|
+
|
|
197
209
|
after do
|
|
198
210
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
199
211
|
end
|
|
@@ -301,6 +313,10 @@ end
|
|
|
301
313
|
|
|
302
314
|
if RUBY_VERSION >= '1.9.2'
|
|
303
315
|
describe "Ruby 1.9.2+ Method#parameters" do
|
|
316
|
+
before do
|
|
317
|
+
stub_dotfile!
|
|
318
|
+
end
|
|
319
|
+
|
|
304
320
|
after do
|
|
305
321
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
306
322
|
end
|
|
@@ -354,6 +370,7 @@ describe "Methods arrays" do
|
|
|
354
370
|
end
|
|
355
371
|
|
|
356
372
|
it "obj1.methods - obj2.methods should be awesome printed" do
|
|
373
|
+
stub_dotfile!
|
|
357
374
|
class Hello
|
|
358
375
|
def self.m1; end
|
|
359
376
|
end
|
|
@@ -362,6 +379,7 @@ describe "Methods arrays" do
|
|
|
362
379
|
end
|
|
363
380
|
|
|
364
381
|
it "obj1.methods & obj2.methods should be awesome printed" do
|
|
382
|
+
stub_dotfile!
|
|
365
383
|
class Hello
|
|
366
384
|
def self.m1; end
|
|
367
385
|
def self.m2; end
|
|
@@ -374,6 +392,7 @@ describe "Methods arrays" do
|
|
|
374
392
|
end
|
|
375
393
|
|
|
376
394
|
it "obj1.methods.grep(pattern) should be awesome printed" do
|
|
395
|
+
stub_dotfile!
|
|
377
396
|
class Hello
|
|
378
397
|
def self.m1; end
|
|
379
398
|
def self.m2; end
|
|
@@ -396,6 +415,7 @@ describe "Methods arrays" do
|
|
|
396
415
|
end
|
|
397
416
|
|
|
398
417
|
it "obj1.methods.grep(pattern, &block) should be awesome printed" do
|
|
418
|
+
stub_dotfile!
|
|
399
419
|
class Hello
|
|
400
420
|
def self.m0; end
|
|
401
421
|
def self.none; end
|
|
@@ -425,4 +445,14 @@ describe "Methods arrays" do
|
|
|
425
445
|
hello = Hello.new
|
|
426
446
|
(hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }.should == [ :him, :his ]
|
|
427
447
|
end
|
|
448
|
+
|
|
449
|
+
it "appending garbage to methods array should not raise error" do
|
|
450
|
+
arr = 42.methods << [ :wtf ]
|
|
451
|
+
arr.ai(:plain => true).should_not raise_error(TypeError)
|
|
452
|
+
if RUBY_VERSION < '1.9.2'
|
|
453
|
+
arr.ai(:plain => true).should =~ /\s+wtf\(\?\)\s+\?/ # [ :wtf ].to_s => "wtf"
|
|
454
|
+
else
|
|
455
|
+
arr.ai(:plain => true).should =~ /\s+\[:wtf\]\(\?\)\s+\?/ # [ :wtf ].to_s => [:wtf]
|
|
456
|
+
end
|
|
457
|
+
end
|
|
428
458
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "Single method" do
|
|
4
|
+
before do
|
|
5
|
+
stub_dotfile!
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
after do
|
|
9
|
+
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "object" do
|
|
13
|
+
it "attributes" do
|
|
14
|
+
class Hello
|
|
15
|
+
attr_reader :abra
|
|
16
|
+
attr_writer :ca
|
|
17
|
+
attr_accessor :dabra
|
|
18
|
+
|
|
19
|
+
def initialize
|
|
20
|
+
@abra, @ca, @dabra = 1, 2, 3
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
out = Hello.new.ai(:plain => true)
|
|
25
|
+
str = <<-EOS.strip
|
|
26
|
+
#<Hello:0x01234567
|
|
27
|
+
attr_accessor :dabra = 3,
|
|
28
|
+
attr_reader :abra = 1,
|
|
29
|
+
attr_writer :ca = 2
|
|
30
|
+
>
|
|
31
|
+
EOS
|
|
32
|
+
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "instance variables" do
|
|
36
|
+
class Hello
|
|
37
|
+
def initialize
|
|
38
|
+
@abra, @ca, @dabra = 1, 2, 3
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
out = Hello.new.ai(:plain => true)
|
|
43
|
+
str = <<-EOS.strip
|
|
44
|
+
#<Hello:0x01234567
|
|
45
|
+
@abra = 1,
|
|
46
|
+
@ca = 2,
|
|
47
|
+
@dabra = 3
|
|
48
|
+
>
|
|
49
|
+
EOS
|
|
50
|
+
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "attributes and instance variables" do
|
|
54
|
+
class Hello
|
|
55
|
+
attr_reader :abra
|
|
56
|
+
attr_writer :ca
|
|
57
|
+
attr_accessor :dabra
|
|
58
|
+
|
|
59
|
+
def initialize
|
|
60
|
+
@abra, @ca, @dabra = 1, 2, 3
|
|
61
|
+
@scooby, @dooby, @doo = 3, 2, 1
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
out = Hello.new.ai(:plain => true)
|
|
66
|
+
str = <<-EOS.strip
|
|
67
|
+
#<Hello:0x01234567
|
|
68
|
+
@doo = 1,
|
|
69
|
+
@dooby = 2,
|
|
70
|
+
@scooby = 3,
|
|
71
|
+
attr_accessor :dabra = 3,
|
|
72
|
+
attr_reader :abra = 1,
|
|
73
|
+
attr_writer :ca = 2
|
|
74
|
+
>
|
|
75
|
+
EOS
|
|
76
|
+
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -19,7 +19,7 @@ end
|
|
|
19
19
|
|
|
20
20
|
# The following is needed for the Infinity Test. It runs tests as subprocesses,
|
|
21
21
|
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
|
|
22
|
-
AwesomePrint.force_colors!
|
|
22
|
+
### AwesomePrint.force_colors!
|
|
23
23
|
|
|
24
24
|
# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass.
|
|
25
25
|
if RUBY_VERSION < '1.8.7'
|