awesome_print 1.6.1 → 1.9.2

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