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