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