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.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -2
  3. data/Appraisals +62 -0
  4. data/CHANGELOG.md +180 -0
  5. data/CONTRIBUTING.md +82 -0
  6. data/Gemfile +3 -2
  7. data/LICENSE +16 -19
  8. data/README.md +112 -87
  9. data/Rakefile +17 -4
  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.rb +22 -16
  14. data/lib/awesome_print/colorize.rb +24 -0
  15. data/lib/awesome_print/core_ext/{array.rb → awesome_method_array.rb} +16 -18
  16. data/lib/awesome_print/core_ext/class.rb +3 -2
  17. data/lib/awesome_print/core_ext/kernel.rb +1 -1
  18. data/lib/awesome_print/core_ext/logger.rb +1 -1
  19. data/lib/awesome_print/core_ext/method.rb +2 -2
  20. data/lib/awesome_print/core_ext/object.rb +3 -2
  21. data/lib/awesome_print/core_ext/string.rb +3 -3
  22. data/lib/awesome_print/custom_defaults.rb +57 -0
  23. data/lib/awesome_print/ext/action_view.rb +8 -4
  24. data/lib/awesome_print/ext/active_record.rb +47 -13
  25. data/lib/awesome_print/ext/active_support.rb +1 -1
  26. data/lib/awesome_print/ext/mongo_mapper.rb +16 -13
  27. data/lib/awesome_print/ext/mongoid.rb +9 -7
  28. data/lib/awesome_print/ext/nobrainer.rb +52 -0
  29. data/lib/awesome_print/ext/nokogiri.rb +4 -4
  30. data/lib/awesome_print/ext/ostruct.rb +27 -0
  31. data/lib/awesome_print/ext/ripple.rb +6 -7
  32. data/lib/awesome_print/ext/sequel.rb +7 -6
  33. data/lib/awesome_print/formatter.rb +54 -327
  34. data/lib/awesome_print/formatters.rb +15 -0
  35. data/lib/awesome_print/formatters/array_formatter.rb +139 -0
  36. data/lib/awesome_print/formatters/base_formatter.rb +140 -0
  37. data/lib/awesome_print/formatters/class_formatter.rb +25 -0
  38. data/lib/awesome_print/formatters/dir_formatter.rb +22 -0
  39. data/lib/awesome_print/formatters/file_formatter.rb +22 -0
  40. data/lib/awesome_print/formatters/hash_formatter.rb +106 -0
  41. data/lib/awesome_print/formatters/method_formatter.rb +22 -0
  42. data/lib/awesome_print/formatters/object_formatter.rb +78 -0
  43. data/lib/awesome_print/formatters/simple_formatter.rb +21 -0
  44. data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
  45. data/lib/awesome_print/indentator.rb +18 -0
  46. data/lib/awesome_print/inspector.rb +92 -94
  47. data/lib/awesome_print/version.rb +2 -2
  48. data/spec/active_record_helper.rb +30 -0
  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 +272 -205
  62. data/spec/methods_spec.rb +173 -177
  63. data/spec/misc_spec.rb +129 -105
  64. data/spec/objects_spec.rb +162 -27
  65. data/spec/spec_helper.rb +75 -37
  66. data/spec/support/active_record_data.rb +20 -0
  67. data/spec/support/active_record_data/3_2_diana.txt +24 -0
  68. data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
  69. data/spec/support/active_record_data/3_2_multi.txt +50 -0
  70. data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
  71. data/spec/support/active_record_data/4_0_diana.txt +98 -0
  72. data/spec/support/active_record_data/4_0_multi.txt +198 -0
  73. data/spec/support/active_record_data/4_1_diana.txt +97 -0
  74. data/spec/support/active_record_data/4_1_multi.txt +196 -0
  75. data/spec/support/active_record_data/4_2_diana.txt +109 -0
  76. data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
  77. data/spec/support/active_record_data/4_2_multi.txt +220 -0
  78. data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
  79. data/spec/support/active_record_data/5_0_diana.txt +105 -0
  80. data/spec/support/active_record_data/5_0_multi.txt +212 -0
  81. data/spec/support/active_record_data/5_1_diana.txt +104 -0
  82. data/spec/support/active_record_data/5_1_multi.txt +210 -0
  83. data/spec/support/active_record_data/5_2_diana.txt +104 -0
  84. data/spec/support/active_record_data/5_2_multi.txt +210 -0
  85. data/spec/support/active_record_data/6_0_diana.txt +104 -0
  86. data/spec/support/active_record_data/6_0_multi.txt +210 -0
  87. data/spec/support/active_record_data/6_1_diana.txt +109 -0
  88. data/spec/support/active_record_data/6_1_multi.txt +220 -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 +163 -32
  93. data/CHANGELOG +0 -96
  94. data/lib/awesome_print/ext/no_brainer.rb +0 -58
data/spec/misc_spec.rb CHANGED
@@ -1,146 +1,156 @@
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
- weird.new.ai(:plain => true).should == ''
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
- weird.new.ai(:plain => false).should == "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
- grepped.ai(:plain => true, :multiline => false).should == '[ "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
- grepped.ai(:plain => true, :multiline => false).should == '[ 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
- self.stub!(:puts)
47
- (ap object).should == 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
- lambda { rand.ai }.should_not raise_error
50
+ expect { rand.ai }.not_to raise_error
54
51
  end
55
52
 
56
- it "format ENV as hash" do
57
- ENV.ai(:plain => true).should == ENV.to_hash.ai(:plain => true)
58
- ENV.ai.should == ENV.to_hash.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
- describe "HTML output" do
64
- before do
65
- stub_dotfile!
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 "wraps ap output with plain <pre> tag" do
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(:html => true, :plain => true).should == "<pre>#{markup}</pre>"
88
+ expect(markup.ai(html: true, plain: true)).to eq("<pre>#{markup}</pre>")
71
89
  end
72
90
 
73
- it "wraps ap output with <pre> tag with colorized <kbd>" do
91
+ it 'wraps ap output with <pre> tag with colorized <kbd>' do
74
92
  markup = rand
75
- markup.ai(:html => true).should == %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>|)
76
94
  end
77
95
 
78
- it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
79
- markup = [ 1, :two, "three" ]
80
- markup.ai(:html => true).should == <<-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
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">&quot;three&quot;</kbd>
85
103
  ]</pre>
86
- EOS
104
+ EOS
87
105
  end
88
106
 
89
- it "wraps hash ap output with only an outer <pre> tag" do
90
- markup = [ { "hello" => "world" } ]
91
- markup.ai(:html => true).should == <<-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
92
110
  <pre>[
93
111
  <kbd style="color:white">[0] </kbd>{
94
112
  &quot;hello&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;world&quot;</kbd>
95
113
  }
96
114
  ]</pre>
97
- EOS
115
+ EOS
98
116
  end
99
117
 
100
- it "encodes HTML entities (plain)" do
118
+ it 'encodes HTML entities (plain)' do
101
119
  markup = ' &<hello>'
102
- markup.ai(:html => true, :plain => true).should == '<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>')
103
121
  end
104
122
 
105
- it "encodes HTML entities (color)" do
123
+ it 'encodes HTML entities (color)' do
106
124
  markup = ' &<hello>'
107
- markup.ai(:html => true).should == '<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>')
108
126
  end
109
127
  end
110
128
 
111
129
  #------------------------------------------------------------------------------
112
- describe "AwesomePrint.defaults" do
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/michaeldv/awesome_print/issues/98
122
- it "should properly merge the defaults" do
123
- AwesomePrint.defaults = { :indent => -2, :sort_keys => true }
124
- hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
125
- out = hash.ai(:plain => true)
126
- out.should == <<-EOS.strip
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 "Coexistence with the colorize gem" do
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 = "".method(:red)
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 "shoud not raise ArgumentError when formatting HTML" do
160
- out = "hello".ai(:color => { :string => :red }, :html => true)
161
- if RUBY_VERSION >= "1.9"
162
- out.should == %Q|<pre>[red]<kbd style="color:red">&quot;hello&quot;</kbd>[/red]</pre>|
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">&quot;hello&quot;</kbd>[/red]</pre>|)
163
173
  else
164
- out.should == %Q|<pre>[red]&quot;hello&quot;[/red]</pre>|
174
+ expect(out).to eq(%Q|<pre>[red]&quot;hello&quot;[/red]</pre>|)
165
175
  end
166
176
  end
167
177
 
168
- it "shoud not raise ArgumentError when formatting HTML (shade color)" do
169
- out = "hello".ai(:color => { :string => :redish }, :html => true)
170
- out.should == %Q|<pre><kbd style="color:darkred">&quot;hello&quot;</kbd></pre>|
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">&quot;hello&quot;</kbd></pre>|)
171
181
  end
172
182
 
173
- it "shoud not raise ArgumentError when formatting non-HTML" do
174
- out = "hello".ai(:color => { :string => :red }, :html => false)
175
- out.should == %Q|[red]"hello"[/red]|
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 "shoud not raise ArgumentError when formatting non-HTML (shade color)" do
179
- out = "hello".ai(:color => { :string => :redish }, :html => false)
180
- out.should == %Q|\e[0;31m"hello"\e[0m|
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 "Console" do
186
- it "should detect IRB" do
195
+ describe 'Console' do
196
+ it 'should detect IRB' do
187
197
  class IRB; end
188
- AwesomePrint.console?.should == true
189
- AwesomePrint.rails_console?.should == false
190
- Object.instance_eval{ remove_const :IRB }
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 "should detect Pry" do
204
+ it 'should detect Pry' do
194
205
  class Pry; end
195
- AwesomePrint.console?.should == true
196
- AwesomePrint.rails_console?.should == false
197
- Object.instance_eval{ remove_const :Pry }
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 "should detect Rails::Console" do
212
+ it 'should detect Rails::Console' do
201
213
  class IRB; end
202
- class Rails; class Console; end; end
203
- AwesomePrint.console?.should == true
204
- AwesomePrint.rails_console?.should == true
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["RAILS_ENV"] = "development"
212
- AwesomePrint.console?.should == true
213
- AwesomePrint.rails_console?.should == true
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 "should return the actual object when *not* running under console" do
218
- capture! { ap([ 1, 2, 3 ]) }.should == [ 1, 2, 3 ]
219
- capture! { ap({ :a => 1 }) }.should == { :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 })
220
232
  end
221
233
 
222
- it "should return nil when running under console" do
234
+ it 'should return nil when running under console' do
223
235
  class IRB; end
224
- capture! { ap([ 1, 2, 3 ]) }.should == nil
225
- capture! { ap({ :a => 1 }) }.should == nil
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 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
- out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
34
- hello.ai(:plain => true, :raw => false).should == 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
- out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
54
- hello.ai(:plain => true, :raw => false).should == 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
- out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
82
- hello.ai(:plain => true, :raw => false).should == 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