awesome_print 1.2.0 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -2
- data/Appraisals +62 -0
- data/CHANGELOG.md +180 -0
- data/CONTRIBUTING.md +82 -0
- data/Gemfile +3 -2
- data/LICENSE +16 -19
- data/README.md +112 -87
- data/Rakefile +17 -4
- data/awesome_print.gemspec +33 -0
- data/init.rb +1 -0
- data/lib/ap.rb +2 -2
- data/lib/awesome_print.rb +22 -16
- data/lib/awesome_print/colorize.rb +24 -0
- 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 +47 -13
- 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 +9 -7
- data/lib/awesome_print/ext/nobrainer.rb +52 -0
- data/lib/awesome_print/ext/nokogiri.rb +4 -4
- data/lib/awesome_print/ext/ostruct.rb +27 -0
- data/lib/awesome_print/ext/ripple.rb +6 -7
- data/lib/awesome_print/ext/sequel.rb +7 -6
- data/lib/awesome_print/formatter.rb +54 -327
- data/lib/awesome_print/formatters.rb +15 -0
- data/lib/awesome_print/formatters/array_formatter.rb +139 -0
- data/lib/awesome_print/formatters/base_formatter.rb +140 -0
- data/lib/awesome_print/formatters/class_formatter.rb +25 -0
- data/lib/awesome_print/formatters/dir_formatter.rb +22 -0
- data/lib/awesome_print/formatters/file_formatter.rb +22 -0
- data/lib/awesome_print/formatters/hash_formatter.rb +106 -0
- data/lib/awesome_print/formatters/method_formatter.rb +22 -0
- data/lib/awesome_print/formatters/object_formatter.rb +78 -0
- data/lib/awesome_print/formatters/simple_formatter.rb +21 -0
- data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
- data/lib/awesome_print/indentator.rb +18 -0
- data/lib/awesome_print/inspector.rb +92 -94
- data/lib/awesome_print/version.rb +2 -2
- data/spec/active_record_helper.rb +30 -0
- data/spec/colors_spec.rb +31 -31
- 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 +21 -0
- data/spec/ext/active_record_spec.rb +260 -0
- data/spec/ext/active_support_spec.rb +30 -0
- data/spec/ext/mongo_mapper_spec.rb +261 -0
- data/spec/ext/mongoid_spec.rb +67 -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 +272 -205
- data/spec/methods_spec.rb +173 -177
- data/spec/misc_spec.rb +129 -105
- data/spec/objects_spec.rb +162 -27
- data/spec/spec_helper.rb +75 -37
- 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/active_record_data/5_1_diana.txt +104 -0
- data/spec/support/active_record_data/5_1_multi.txt +210 -0
- data/spec/support/active_record_data/5_2_diana.txt +104 -0
- data/spec/support/active_record_data/5_2_multi.txt +210 -0
- data/spec/support/active_record_data/6_0_diana.txt +104 -0
- data/spec/support/active_record_data/6_0_multi.txt +210 -0
- data/spec/support/active_record_data/6_1_diana.txt +109 -0
- data/spec/support/active_record_data/6_1_multi.txt +220 -0
- data/spec/support/ext_verifier.rb +42 -0
- data/spec/support/mongoid_versions.rb +26 -0
- data/spec/support/rails_versions.rb +55 -0
- metadata +163 -32
- data/CHANGELOG +0 -96
- data/lib/awesome_print/ext/no_brainer.rb +0 -58
data/spec/misc_spec.rb
CHANGED
@@ -1,146 +1,156 @@
|
|
1
|
-
require
|
1
|
+
require 'net/http'
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
|
-
describe
|
4
|
+
RSpec.describe 'AwesomePrint' do
|
4
5
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
stub_dotfile!
|
8
|
-
end
|
9
|
-
|
10
|
-
it "handle weird objects that return nil on inspect" do
|
6
|
+
describe 'Misc' do
|
7
|
+
it 'handle weird objects that return nil on inspect' do
|
11
8
|
weird = Class.new do
|
12
9
|
def inspect
|
13
10
|
nil
|
14
11
|
end
|
15
12
|
end
|
16
|
-
weird.new.ai(:
|
13
|
+
expect(weird.new.ai(plain: true)).to eq('')
|
17
14
|
end
|
18
15
|
|
19
|
-
it
|
16
|
+
it 'handle frozen object.inspect' do
|
20
17
|
weird = Class.new do
|
21
18
|
def inspect
|
22
|
-
|
19
|
+
'ice'.freeze
|
23
20
|
end
|
24
21
|
end
|
25
|
-
weird.new.ai(:
|
22
|
+
expect(weird.new.ai(plain: false)).to eq('ice')
|
26
23
|
end
|
27
24
|
|
28
|
-
# See https://github.com/
|
29
|
-
it
|
30
|
-
hash = {
|
25
|
+
# See https://github.com/awesome-print/awesome_print/issues/35
|
26
|
+
it 'handle array grep when pattern contains / chapacter' do
|
27
|
+
hash = { '1/x' => 1, '2//x' => :"2" }
|
31
28
|
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
32
|
-
grepped.ai(:
|
29
|
+
expect(grepped.ai(plain: true, multiline: false)).to eq('[ "1", "2" ]')
|
33
30
|
end
|
34
31
|
|
35
|
-
# See https://github.com/
|
36
|
-
if RUBY_VERSION >=
|
32
|
+
# See https://github.com/awesome-print/awesome_print/issues/85
|
33
|
+
if RUBY_VERSION >= '1.8.7'
|
37
34
|
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
38
35
|
arr = (0..6).to_a
|
39
36
|
grepped = arr.grep(1..4, &:succ)
|
40
|
-
grepped.ai(:
|
37
|
+
expect(grepped.ai(plain: true, multiline: false)).to eq('[ 2, 3, 4, 5 ]')
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
|
-
it
|
41
|
+
it 'returns value passed as a parameter' do
|
45
42
|
object = rand
|
46
|
-
self.
|
47
|
-
(ap object).
|
43
|
+
allow(self).to receive(:puts)
|
44
|
+
expect(ap object).to eq(object)
|
48
45
|
end
|
49
46
|
|
50
47
|
# Require different file name this time (lib/ap.rb vs. lib/awesome_print).
|
51
48
|
it "several require 'awesome_print' should do no harm" do
|
52
49
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/ap')
|
53
|
-
|
50
|
+
expect { rand.ai }.not_to raise_error
|
54
51
|
end
|
55
52
|
|
56
|
-
it
|
57
|
-
ENV.ai(:
|
58
|
-
ENV.ai.
|
53
|
+
it 'format ENV as hash' do
|
54
|
+
expect(ENV.ai(plain: true)).to eq(ENV.to_hash.ai(plain: true))
|
55
|
+
expect(ENV.ai).to eq(ENV.to_hash.ai)
|
59
56
|
end
|
60
|
-
end
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
# See https://github.com/awesome-print/awesome_print/issues/134
|
59
|
+
it 'IPAddr workaround' do
|
60
|
+
require 'ipaddr'
|
61
|
+
ipaddr = IPAddr.new('3ffe:505:2::1')
|
62
|
+
expect(ipaddr.ai).to eq('#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>')
|
63
|
+
end
|
64
|
+
|
65
|
+
# See https://github.com/awesome-print/awesome_print/issues/139
|
66
|
+
it 'Object that overrides == and expects the :id method' do
|
67
|
+
weird = Class.new do
|
68
|
+
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
69
|
+
def ==(other)
|
70
|
+
self.id == other.id
|
71
|
+
end
|
72
|
+
alias :eql? :==
|
73
|
+
end
|
74
|
+
expect { weird.new.ai }.not_to raise_error
|
66
75
|
end
|
67
76
|
|
68
|
-
it
|
77
|
+
it 'handles attr_reader :method' do
|
78
|
+
uri = URI.parse('https://hello.nx/world')
|
79
|
+
req = Net::HTTP::Get.new(uri)
|
80
|
+
expect(req.ai(plain: true)).to eq('#<Net::HTTP::Get GET>')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
#------------------------------------------------------------------------------
|
85
|
+
describe 'HTML output' do
|
86
|
+
it 'wraps ap output with plain <pre> tag' do
|
69
87
|
markup = rand
|
70
|
-
markup.ai(:
|
88
|
+
expect(markup.ai(html: true, plain: true)).to eq("<pre>#{markup}</pre>")
|
71
89
|
end
|
72
90
|
|
73
|
-
it
|
91
|
+
it 'wraps ap output with <pre> tag with colorized <kbd>' do
|
74
92
|
markup = rand
|
75
|
-
markup.ai(:
|
93
|
+
expect(markup.ai(html: true)).to eq(%Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|)
|
76
94
|
end
|
77
95
|
|
78
|
-
it
|
79
|
-
markup = [
|
80
|
-
markup.ai(:
|
96
|
+
it 'wraps multiline ap output with <pre> tag with colorized <kbd>' do
|
97
|
+
markup = [1, :two, 'three']
|
98
|
+
expect(markup.ai(html: true)).to eq <<-EOS.strip
|
81
99
|
<pre>[
|
82
100
|
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
83
101
|
<kbd style="color:white">[1] </kbd><kbd style="color:darkcyan">:two</kbd>,
|
84
102
|
<kbd style="color:white">[2] </kbd><kbd style="color:brown">"three"</kbd>
|
85
103
|
]</pre>
|
86
|
-
EOS
|
104
|
+
EOS
|
87
105
|
end
|
88
106
|
|
89
|
-
it
|
90
|
-
markup = [
|
91
|
-
markup.ai(:
|
107
|
+
it 'wraps hash ap output with only an outer <pre> tag' do
|
108
|
+
markup = [{ 'hello' => 'world' }]
|
109
|
+
expect(markup.ai(html: true)).to eq <<-EOS.strip
|
92
110
|
<pre>[
|
93
111
|
<kbd style="color:white">[0] </kbd>{
|
94
112
|
"hello"<kbd style="color:slategray"> => </kbd><kbd style="color:brown">"world"</kbd>
|
95
113
|
}
|
96
114
|
]</pre>
|
97
|
-
|
115
|
+
EOS
|
98
116
|
end
|
99
117
|
|
100
|
-
it
|
118
|
+
it 'encodes HTML entities (plain)' do
|
101
119
|
markup = ' &<hello>'
|
102
|
-
markup.ai(:
|
120
|
+
expect(markup.ai(html: true, plain: true)).to eq('<pre>" &<hello>"</pre>')
|
103
121
|
end
|
104
122
|
|
105
|
-
it
|
123
|
+
it 'encodes HTML entities (color)' do
|
106
124
|
markup = ' &<hello>'
|
107
|
-
markup.ai(:
|
125
|
+
expect(markup.ai(html: true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
108
126
|
end
|
109
127
|
end
|
110
128
|
|
111
129
|
#------------------------------------------------------------------------------
|
112
|
-
describe
|
113
|
-
before do
|
114
|
-
stub_dotfile!
|
115
|
-
end
|
116
|
-
|
130
|
+
describe 'AwesomePrint.defaults' do
|
117
131
|
after do
|
118
132
|
AwesomePrint.defaults = nil
|
119
133
|
end
|
120
134
|
|
121
|
-
# See https://github.com/
|
122
|
-
it
|
123
|
-
AwesomePrint.defaults = { :
|
124
|
-
hash = { [0, 0, 255] => :yellow, :red =>
|
125
|
-
out = hash.ai(:
|
126
|
-
out.
|
135
|
+
# See https://github.com/awesome-print/awesome_print/issues/98
|
136
|
+
it 'should properly merge the defaults' do
|
137
|
+
AwesomePrint.defaults = { indent: -2, sort_keys: true }
|
138
|
+
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
139
|
+
out = hash.ai(plain: true)
|
140
|
+
expect(out).to eq <<-EOS.strip
|
127
141
|
{
|
128
142
|
[ 0, 0, 255 ] => :yellow,
|
129
143
|
"magenta" => "rgb(255, 0, 255)",
|
130
144
|
:red => "rgb(255, 0, 0)"
|
131
145
|
}
|
132
|
-
EOS
|
146
|
+
EOS
|
133
147
|
end
|
134
148
|
end
|
135
149
|
|
136
150
|
#------------------------------------------------------------------------------
|
137
|
-
describe
|
138
|
-
before do
|
139
|
-
stub_dotfile!
|
140
|
-
end
|
141
|
-
|
151
|
+
describe 'Coexistence with the colorize gem' do
|
142
152
|
before do # Redefine String#red just like colorize gem does it.
|
143
|
-
@awesome_method =
|
153
|
+
@awesome_method = ''.method(:red)
|
144
154
|
|
145
155
|
String.instance_eval do
|
146
156
|
define_method :red do # Method arity is now 0 in Ruby 1.9+.
|
@@ -156,74 +166,88 @@ EOS
|
|
156
166
|
end
|
157
167
|
end
|
158
168
|
|
159
|
-
it
|
160
|
-
out =
|
161
|
-
if RUBY_VERSION >=
|
162
|
-
out.
|
169
|
+
it 'shoud not raise ArgumentError when formatting HTML' do
|
170
|
+
out = 'hello'.ai(color: { string: :red }, html: true)
|
171
|
+
if RUBY_VERSION >= '1.9'
|
172
|
+
expect(out).to eq(%Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
163
173
|
else
|
164
|
-
out.
|
174
|
+
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
165
175
|
end
|
166
176
|
end
|
167
177
|
|
168
|
-
it
|
169
|
-
out =
|
170
|
-
out.
|
178
|
+
it 'shoud not raise ArgumentError when formatting HTML (shade color)' do
|
179
|
+
out = 'hello'.ai(color: { string: :redish }, html: true)
|
180
|
+
expect(out).to eq(%Q|<pre><kbd style="color:darkred">"hello"</kbd></pre>|)
|
171
181
|
end
|
172
182
|
|
173
|
-
it
|
174
|
-
out =
|
175
|
-
out.
|
183
|
+
it 'shoud not raise ArgumentError when formatting non-HTML' do
|
184
|
+
out = 'hello'.ai(color: { string: :red }, html: false)
|
185
|
+
expect(out).to eq(%Q|[red]"hello"[/red]|)
|
176
186
|
end
|
177
187
|
|
178
|
-
it
|
179
|
-
out =
|
180
|
-
out.
|
188
|
+
it 'shoud not raise ArgumentError when formatting non-HTML (shade color)' do
|
189
|
+
out = 'hello'.ai(color: { string: :redish }, html: false)
|
190
|
+
expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|)
|
181
191
|
end
|
182
192
|
end
|
183
193
|
|
184
194
|
#------------------------------------------------------------------------------
|
185
|
-
describe
|
186
|
-
it
|
195
|
+
describe 'Console' do
|
196
|
+
it 'should detect IRB' do
|
187
197
|
class IRB; end
|
188
|
-
|
189
|
-
AwesomePrint.
|
190
|
-
|
198
|
+
ENV.delete('RAILS_ENV')
|
199
|
+
expect(AwesomePrint.console?).to eq(true)
|
200
|
+
expect(AwesomePrint.rails_console?).to eq(false)
|
201
|
+
Object.instance_eval { remove_const :IRB }
|
191
202
|
end
|
192
203
|
|
193
|
-
it
|
204
|
+
it 'should detect Pry' do
|
194
205
|
class Pry; end
|
195
|
-
|
196
|
-
AwesomePrint.
|
197
|
-
|
206
|
+
ENV.delete('RAILS_ENV')
|
207
|
+
expect(AwesomePrint.console?).to eq(true)
|
208
|
+
expect(AwesomePrint.rails_console?).to eq(false)
|
209
|
+
Object.instance_eval { remove_const :Pry }
|
198
210
|
end
|
199
211
|
|
200
|
-
it
|
212
|
+
it 'should detect Rails::Console' do
|
201
213
|
class IRB; end
|
202
|
-
|
203
|
-
AwesomePrint.console
|
204
|
-
AwesomePrint.rails_console
|
205
|
-
Object.instance_eval{ remove_const :IRB }
|
206
|
-
Object.instance_eval{ remove_const :Rails }
|
214
|
+
module Rails; class Console; end; end
|
215
|
+
expect(AwesomePrint.console?).to eq(true)
|
216
|
+
expect(AwesomePrint.rails_console?).to eq(true)
|
217
|
+
Object.instance_eval { remove_const :IRB }
|
218
|
+
Object.instance_eval { remove_const :Rails }
|
207
219
|
end
|
208
220
|
|
209
221
|
it "should detect ENV['RAILS_ENV']" do
|
210
222
|
class Pry; end
|
211
|
-
ENV[
|
212
|
-
AwesomePrint.console
|
213
|
-
AwesomePrint.rails_console
|
214
|
-
Object.instance_eval{ remove_const :Pry }
|
223
|
+
ENV['RAILS_ENV'] = 'development'
|
224
|
+
expect(AwesomePrint.console?).to eq(true)
|
225
|
+
expect(AwesomePrint.rails_console?).to eq(true)
|
226
|
+
Object.instance_eval { remove_const :Pry }
|
215
227
|
end
|
216
228
|
|
217
|
-
it
|
218
|
-
capture! { ap([
|
219
|
-
capture! { ap({ :
|
229
|
+
it 'should return the actual object when *not* running under console' do
|
230
|
+
expect(capture! { ap([1, 2, 3]) }).to eq([1, 2, 3])
|
231
|
+
expect(capture! { ap({ a: 1 }) }).to eq({ a: 1 })
|
220
232
|
end
|
221
233
|
|
222
|
-
it
|
234
|
+
it 'should return nil when running under console' do
|
223
235
|
class IRB; end
|
224
|
-
capture! { ap([
|
225
|
-
capture! { ap({ :
|
226
|
-
Object.instance_eval{ remove_const :IRB }
|
236
|
+
expect(capture! { ap([1, 2, 3]) }).to eq(nil)
|
237
|
+
expect(capture! { ap({ a: 1 }) }).to eq(nil)
|
238
|
+
Object.instance_eval { remove_const :IRB }
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'handles NoMethodError on IRB implicit #ai' do
|
242
|
+
module IRB; class Irb; end; end
|
243
|
+
irb_context = double('irb_context', last_value: BasicObject.new)
|
244
|
+
IRB.define_singleton_method :version, -> { 'test_version' }
|
245
|
+
irb = IRB::Irb.new
|
246
|
+
irb.instance_eval { @context = irb_context }
|
247
|
+
AwesomePrint.irb!
|
248
|
+
expect(irb).to receive(:puts).with("(Object doesn't support #ai)")
|
249
|
+
expect { irb.output_value }.to_not raise_error
|
250
|
+
Object.instance_eval { remove_const :IRB }
|
227
251
|
end
|
228
252
|
end
|
229
253
|
end
|
data/spec/objects_spec.rb
CHANGED
@@ -1,75 +1,79 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe "Objects" do
|
4
|
-
before do
|
5
|
-
stub_dotfile!
|
6
|
-
end
|
1
|
+
require 'spec_helper'
|
7
2
|
|
3
|
+
RSpec.describe 'Objects' 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
|
-
describe
|
13
|
-
it
|
8
|
+
describe 'Formatting an object' do
|
9
|
+
it 'attributes' do
|
14
10
|
class Hello
|
15
11
|
attr_reader :abra
|
16
12
|
attr_writer :ca
|
17
13
|
attr_accessor :dabra
|
18
14
|
|
19
15
|
def initialize
|
20
|
-
@abra
|
16
|
+
@abra = 1
|
17
|
+
@ca = 2
|
18
|
+
@dabra = 3
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
hello = Hello.new
|
25
|
-
out = hello.ai(:
|
23
|
+
out = hello.ai(plain: true, raw: true)
|
26
24
|
str = <<-EOS.strip
|
27
|
-
#<Hello:
|
25
|
+
#<Hello:placeholder_id
|
28
26
|
attr_accessor :dabra = 3,
|
29
27
|
attr_reader :abra = 1,
|
30
28
|
attr_writer :ca = 2
|
31
29
|
>
|
32
30
|
EOS
|
33
|
-
out
|
34
|
-
hello.ai(:
|
31
|
+
expect(out).to be_similar_to(str)
|
32
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
35
33
|
end
|
36
34
|
|
37
|
-
it
|
35
|
+
it 'instance variables' do
|
38
36
|
class Hello
|
39
37
|
def initialize
|
40
|
-
@abra
|
38
|
+
@abra = 1
|
39
|
+
@ca = 2
|
40
|
+
@dabra = 3
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
hello = Hello.new
|
45
|
-
out = hello.ai(:
|
45
|
+
out = hello.ai(plain: true, raw: true)
|
46
46
|
str = <<-EOS.strip
|
47
|
-
#<Hello:
|
47
|
+
#<Hello:placeholder_id
|
48
48
|
@abra = 1,
|
49
49
|
@ca = 2,
|
50
50
|
@dabra = 3
|
51
51
|
>
|
52
52
|
EOS
|
53
|
-
out
|
54
|
-
hello.ai(:
|
53
|
+
expect(out).to be_similar_to(str)
|
54
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'attributes and instance variables' do
|
58
58
|
class Hello
|
59
59
|
attr_reader :abra
|
60
60
|
attr_writer :ca
|
61
61
|
attr_accessor :dabra
|
62
62
|
|
63
63
|
def initialize
|
64
|
-
@abra
|
65
|
-
@
|
64
|
+
@abra = 1
|
65
|
+
@ca = 2
|
66
|
+
@dabra = 3
|
67
|
+
@scooby = 3
|
68
|
+
@dooby = 2
|
69
|
+
@doo = 1
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
73
|
hello = Hello.new
|
70
|
-
out = hello.ai(:
|
74
|
+
out = hello.ai(plain: true, raw: true)
|
71
75
|
str = <<-EOS.strip
|
72
|
-
#<Hello:
|
76
|
+
#<Hello:placeholder_id
|
73
77
|
@doo = 1,
|
74
78
|
@dooby = 2,
|
75
79
|
@scooby = 3,
|
@@ -78,8 +82,139 @@ EOS
|
|
78
82
|
attr_writer :ca = 2
|
79
83
|
>
|
80
84
|
EOS
|
81
|
-
out
|
82
|
-
hello.ai(:
|
85
|
+
expect(out).to be_similar_to(str)
|
86
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
83
87
|
end
|
88
|
+
|
89
|
+
it 'without the plain options print the colorized values' do
|
90
|
+
class Hello
|
91
|
+
attr_reader :abra
|
92
|
+
attr_writer :ca
|
93
|
+
|
94
|
+
def initialize
|
95
|
+
@abra = 1
|
96
|
+
@ca = 2
|
97
|
+
@dabra = 3
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
hello = Hello.new
|
102
|
+
out = hello.ai(raw: true)
|
103
|
+
str = <<-EOS.strip
|
104
|
+
#<Hello:placeholder_id
|
105
|
+
\e[0;36m@dabra\e[0m\e[0;37m = \e[0m\e[1;34m3\e[0m,
|
106
|
+
\e[1;36mattr_reader\e[0m \e[0;35m:abra\e[0m\e[0;37m = \e[0m\e[1;34m1\e[0m,
|
107
|
+
\e[1;36mattr_writer\e[0m \e[0;35m:ca\e[0m\e[0;37m = \e[0m\e[1;34m2\e[0m
|
108
|
+
>
|
109
|
+
EOS
|
110
|
+
expect(out).to be_similar_to(str)
|
111
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'with multine as false show inline values' do
|
115
|
+
class Hello
|
116
|
+
attr_reader :abra
|
117
|
+
attr_writer :ca
|
118
|
+
|
119
|
+
def initialize
|
120
|
+
@abra = 1
|
121
|
+
@ca = 2
|
122
|
+
@dabra = 3
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
hello = Hello.new
|
127
|
+
out = hello.ai(multiline: false, plain: true, raw: true)
|
128
|
+
str = <<-EOS.strip
|
129
|
+
#<Hello:placeholder_id @dabra = 3, attr_reader :abra = 1, attr_writer :ca = 2>
|
130
|
+
EOS
|
131
|
+
expect(out).to be_similar_to(str)
|
132
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'without the sort_vars option does not sort instance variables' do
|
136
|
+
class Hello
|
137
|
+
attr_reader :abra
|
138
|
+
attr_writer :ca
|
139
|
+
attr_accessor :dabra
|
140
|
+
|
141
|
+
def initialize
|
142
|
+
@abra = 1
|
143
|
+
@ca = 2
|
144
|
+
@dabra = 3
|
145
|
+
@scooby = 3
|
146
|
+
@dooby = 2
|
147
|
+
@doo = 1
|
148
|
+
end
|
149
|
+
|
150
|
+
def instance_variables
|
151
|
+
[:@scooby, :@dooby, :@doo, :@abra, :@ca, :@dabra]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
hello = Hello.new
|
156
|
+
out = hello.ai(plain: true, raw: true, sort_vars: false)
|
157
|
+
str = <<-EOS.strip
|
158
|
+
#<Hello:placeholder_id
|
159
|
+
@scooby = 3,
|
160
|
+
@dooby = 2,
|
161
|
+
@doo = 1,
|
162
|
+
attr_reader :abra = 1,
|
163
|
+
attr_writer :ca = 2,
|
164
|
+
attr_accessor :dabra = 3
|
165
|
+
>
|
166
|
+
EOS
|
167
|
+
expect(out).to be_similar_to(str)
|
168
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'object_id' do
|
172
|
+
class Hello
|
173
|
+
def initialize
|
174
|
+
@abra = 1
|
175
|
+
@ca = 2
|
176
|
+
@dabra = 3
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
hello = Hello.new
|
181
|
+
out = hello.ai(plain: true, raw: true, object_id: false)
|
182
|
+
str = <<-EOS.strip
|
183
|
+
#<Hello
|
184
|
+
@abra = 1,
|
185
|
+
@ca = 2,
|
186
|
+
@dabra = 3
|
187
|
+
>
|
188
|
+
EOS
|
189
|
+
expect(out).to be_similar_to(str)
|
190
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'class_name' do
|
194
|
+
class Hello
|
195
|
+
def initialize
|
196
|
+
@abra = 1
|
197
|
+
@ca = 2
|
198
|
+
@dabra = 3
|
199
|
+
end
|
200
|
+
|
201
|
+
def to_s
|
202
|
+
"CustomizedHello"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
hello = Hello.new
|
207
|
+
out = hello.ai(plain: true, raw: true, class_name: :to_s)
|
208
|
+
str = <<-EOS.strip
|
209
|
+
#<CustomizedHello:placeholder_id
|
210
|
+
@abra = 1,
|
211
|
+
@ca = 2,
|
212
|
+
@dabra = 3
|
213
|
+
>
|
214
|
+
EOS
|
215
|
+
expect(out).to be_similar_to(str)
|
216
|
+
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
217
|
+
end
|
218
|
+
|
84
219
|
end
|
85
220
|
end
|