amazing_print 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +16 -0
  3. data/CHANGELOG.md +56 -33
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +61 -44
  6. data/README.md +3 -4
  7. data/lib/amazing_print/colorize.rb +5 -12
  8. data/lib/amazing_print/colors.rb +37 -0
  9. data/lib/amazing_print/core_ext/awesome_method_array.rb +1 -1
  10. data/lib/amazing_print/custom_defaults.rb +7 -1
  11. data/lib/amazing_print/ext/mongoid.rb +14 -2
  12. data/lib/amazing_print/ext_loader.rb +27 -0
  13. data/lib/amazing_print/formatters/array_formatter.rb +1 -1
  14. data/lib/amazing_print/formatters/base_formatter.rb +8 -3
  15. data/lib/amazing_print/formatters/dir_formatter.rb +10 -1
  16. data/lib/amazing_print/formatters/file_formatter.rb +10 -1
  17. data/lib/amazing_print/formatters/hash_formatter.rb +3 -5
  18. data/lib/amazing_print/formatters/mswin_helper.rb +63 -0
  19. data/lib/amazing_print/inspector.rb +6 -3
  20. data/lib/amazing_print/version.rb +1 -1
  21. data/lib/amazing_print.rb +3 -9
  22. data/spec/colors_spec.rb +9 -4
  23. data/spec/ext/action_controller_spec.rb +3 -3
  24. data/spec/ext/active_record_spec.rb +30 -60
  25. data/spec/ext/active_support_spec.rb +2 -2
  26. data/spec/ext/mongoid_spec.rb +110 -47
  27. data/spec/ext/nokogiri_spec.rb +6 -6
  28. data/spec/ext/sequel_spec.rb +1 -1
  29. data/spec/formats_spec.rb +97 -89
  30. data/spec/misc_spec.rb +15 -61
  31. data/spec/spec_helper.rb +7 -1
  32. data/spec/support/active_record_data/7_0_diana.txt +110 -0
  33. data/spec/support/active_record_data/7_0_multi.txt +222 -0
  34. data/spec/support/rails_versions.rb +5 -0
  35. metadata +13 -156
  36. data/lib/amazing_print/core_ext/string.rb +0 -45
  37. data/spec/core_ext/string_spec.rb +0 -15
@@ -6,9 +6,10 @@
6
6
  # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
7
7
  #------------------------------------------------------------------------------
8
8
 
9
- # rubocop:disable Metrics/ClassLength
9
+ # rubocop:disable Metrics/ClassLength, Metrics/MethodLength
10
10
 
11
11
  require_relative 'indentator'
12
+ require_relative 'ext_loader'
12
13
 
13
14
  module AmazingPrint
14
15
  class Inspector
@@ -70,6 +71,8 @@ module AmazingPrint
70
71
  @formatter = AmazingPrint::Formatter.new(self)
71
72
  @indentator = AmazingPrint::Indentator.new(@options[:indent].abs)
72
73
  Thread.current[AP] ||= []
74
+
75
+ ExtLoader.call
73
76
  end
74
77
 
75
78
  def current_indentation
@@ -166,7 +169,7 @@ module AmazingPrint
166
169
  return xdg_config_path if File.exist?(xdg_config_path)
167
170
 
168
171
  # default to ~/.aprc
169
- File.join(ENV['HOME'], '.aprc')
172
+ File.join(Dir.home, '.aprc')
170
173
  end
171
174
 
172
175
  # This method needs to be mocked during testing so that it always loads
@@ -196,4 +199,4 @@ module AmazingPrint
196
199
  end
197
200
  end
198
201
 
199
- # rubocop:enable Metrics/ClassLength
202
+ # rubocop:enable Metrics/ClassLength, Metrics/MethodLength
@@ -7,6 +7,6 @@
7
7
  #------------------------------------------------------------------------------
8
8
  module AmazingPrint
9
9
  def self.version
10
- '1.4.0'
10
+ '1.6.0'
11
11
  end
12
12
  end
data/lib/amazing_print.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  # so do nothing for subsequent requires.
11
11
  #
12
12
  unless defined?(AmazingPrint::Inspector)
13
- %w[awesome_method_array string object class kernel].each do |file|
13
+ %w[awesome_method_array object class kernel].each do |file|
14
14
  require_relative "amazing_print/core_ext/#{file}"
15
15
  end
16
16
 
@@ -33,12 +33,6 @@ unless defined?(AmazingPrint::Inspector)
33
33
  require_relative 'amazing_print/ext/action_view'
34
34
  end
35
35
  end
36
- require_relative 'amazing_print/ext/mongo_mapper' if defined?(MongoMapper)
37
- require_relative 'amazing_print/ext/mongoid' if defined?(Mongoid)
38
- require_relative 'amazing_print/ext/nokogiri' if defined?(Nokogiri)
39
- require_relative 'amazing_print/ext/nobrainer' if defined?(NoBrainer)
40
- require_relative 'amazing_print/ext/ripple' if defined?(Ripple)
41
- require_relative 'amazing_print/ext/sequel' if defined?(Sequel)
42
- require_relative 'amazing_print/ext/ostruct' if defined?(OpenStruct)
36
+
37
+ AmazingPrint::ExtLoader.call
43
38
  end
44
- # test
data/spec/colors_spec.rb CHANGED
@@ -102,11 +102,16 @@ RSpec.describe 'AmazingPrint' do
102
102
  stub_tty!
103
103
  end
104
104
  end
105
+ end
106
+
107
+ describe 'AmazingPrint::Colors' do
108
+ %i[gray red green yellow blue purple cyan white].each_with_index do |color, i|
109
+ it "has #{color} color" do
110
+ expect(AmazingPrint::Colors.public_send(color, color.to_s)).to eq("\e[1;#{i + 30}m#{color}\e[0m")
111
+ end
105
112
 
106
- describe 'uncolor' do
107
- it 'removes any ANSI color codes' do
108
- expect('red'.red + 'blue'.blue).to eq "\e[1;31mred\e[0m\e[1;34mblue\e[0m"
109
- expect(('red'.red + 'blue'.blue).uncolor).to eq 'redblue'
113
+ it "has #{color}ish color" do
114
+ expect(AmazingPrint::Colors.public_send(:"#{color}ish", color.to_s)).to eq("\e[0;#{i + 30}m#{color}\e[0m")
110
115
  end
111
116
  end
112
117
  end
@@ -21,9 +21,9 @@ RSpec.describe 'AmazingPrint::ActionController', skip: -> { !ExtVerifier.has_rai
21
21
  let(:expected_output) do
22
22
  <<~OUTPUT
23
23
  {
24
- \"post\"\e[0;37m => \e[0m{
25
- \"id\"\e[0;37m => \e[0m\e[1;34m1\e[0m,
26
- \"content\"\e[0;37m => \e[0m\e[0;33m\"Some\"\e[0m
24
+ \e[0;33m"post"\e[0m\e[0;37m => \e[0m{
25
+ \e[0;33m"id"\e[0m\e[0;37m => \e[0m\e[1;34m1\e[0m,
26
+ \e[0;33m"content"\e[0m\e[0;37m => \e[0m\e[0;33m"Some"\e[0m
27
27
  }
28
28
  }
29
29
  OUTPUT
@@ -23,11 +23,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
23
23
  :rank => 1
24
24
  }
25
25
  EOS
26
- if RUBY_VERSION < '1.9'
27
- str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
28
- else
29
- str.sub!('?', '1992-10-10 12:30:00 UTC')
30
- end
26
+ str.sub!('?', '1992-10-10 12:30:00 UTC')
31
27
  expect(out).to be_similar_to(str)
32
28
  end
33
29
 
@@ -51,13 +47,8 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
51
47
  }
52
48
  ]
53
49
  EOS
54
- if RUBY_VERSION < '1.9'
55
- str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
56
- str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
57
- else
58
- str.sub!('??', '1992-10-10 12:30:00 UTC')
59
- str.sub!('?!', '2003-05-26 14:15:00 UTC')
60
- end
50
+ str.sub!('??', '1992-10-10 12:30:00 UTC')
51
+ str.sub!('?!', '2003-05-26 14:15:00 UTC')
61
52
  expect(out).to be_similar_to(str)
62
53
  end
63
54
 
@@ -83,13 +74,8 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
83
74
  }
84
75
  ]
85
76
  EOS
86
- if RUBY_VERSION < '1.9'
87
- str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
88
- str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
89
- else
90
- str.sub!('??', '1992-10-10 12:30:00 UTC')
91
- str.sub!('?!', '2003-05-26 14:15:00 UTC')
92
- end
77
+ str.sub!('??', '1992-10-10 12:30:00 UTC')
78
+ str.sub!('?!', '2003-05-26 14:15:00 UTC')
93
79
  expect(out).to be_similar_to(str)
94
80
  end
95
81
  end
@@ -128,7 +114,9 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
128
114
  out = @ap.awesome(@diana)
129
115
 
130
116
  raw_object_string =
131
- if activerecord_6_1?
117
+ if activerecord_7_0?
118
+ ActiveRecordData.raw_7_0_diana
119
+ elsif activerecord_6_1?
132
120
  ActiveRecordData.raw_6_1_diana
133
121
  elsif activerecord_6_0?
134
122
  ActiveRecordData.raw_6_0_diana
@@ -139,21 +127,13 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
139
127
  elsif activerecord_5_0?
140
128
  ActiveRecordData.raw_5_0_diana
141
129
  elsif activerecord_4_2?
142
- if RUBY_VERSION > '1.9.3'
143
- ActiveRecordData.raw_4_2_diana
144
- else
145
- ActiveRecordData.raw_4_2_diana_legacy
146
- end
130
+ ActiveRecordData.raw_4_2_diana
147
131
  elsif activerecord_4_1?
148
132
  ActiveRecordData.raw_4_1_diana
149
133
  elsif activerecord_4_0?
150
134
  ActiveRecordData.raw_4_0_diana
151
135
  elsif activerecord_3_2?
152
- if RUBY_VERSION > '1.9.3'
153
- ActiveRecordData.raw_3_2_diana
154
- else
155
- ActiveRecordData.raw_3_2_diana_legacy
156
- end
136
+ ActiveRecordData.raw_3_2_diana
157
137
  end
158
138
 
159
139
  if RUBY_PLATFORM == 'java' && !activerecord_6_1?
@@ -170,7 +150,9 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
170
150
  out = @ap.awesome([@diana, @laura])
171
151
 
172
152
  raw_object_string =
173
- if activerecord_6_1?
153
+ if activerecord_7_0?
154
+ ActiveRecordData.raw_7_0_multi
155
+ elsif activerecord_6_1?
174
156
  ActiveRecordData.raw_6_1_multi
175
157
  elsif activerecord_6_0?
176
158
  ActiveRecordData.raw_6_0_multi
@@ -181,21 +163,13 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
181
163
  elsif activerecord_5_0?
182
164
  ActiveRecordData.raw_5_0_multi
183
165
  elsif activerecord_4_2?
184
- if RUBY_VERSION > '1.9.3'
185
- ActiveRecordData.raw_4_2_multi
186
- else
187
- ActiveRecordData.raw_4_2_multi_legacy
188
- end
166
+ ActiveRecordData.raw_4_2_multi
189
167
  elsif activerecord_4_1?
190
168
  ActiveRecordData.raw_4_1_multi
191
169
  elsif activerecord_4_0?
192
170
  ActiveRecordData.raw_4_0_multi
193
171
  elsif activerecord_3_2?
194
- if RUBY_VERSION > '1.9.3'
195
- ActiveRecordData.raw_3_2_multi
196
- else
197
- ActiveRecordData.raw_3_2_multi_legacy
198
- end
172
+ ActiveRecordData.raw_3_2_multi
199
173
  end
200
174
 
201
175
  if RUBY_PLATFORM == 'java' && !activerecord_6_1?
@@ -266,24 +240,24 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
266
240
  expect(out).to match(
267
241
  /\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
268
242
  )
269
- elsif RUBY_VERSION >= '3.0.0'
243
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
244
+ expect(out).to match(
245
+ /\s*first\(\*(\*|args),\s+\?,\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
246
+ )
247
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
270
248
  expect(out).to match(
271
249
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
272
250
  )
273
- elsif RUBY_VERSION >= '2.7.2'
251
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
274
252
  expect(out).to match(
275
253
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
276
254
  )
277
- elsif RUBY_VERSION >= '2.6.7'
255
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7')
278
256
  expect(out).to match(
279
257
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
280
258
  )
281
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./
259
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4')
282
260
  expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
283
- elsif RUBY_VERSION >= '1.9'
284
- expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
285
- else
286
- expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
287
261
  end
288
262
  else
289
263
  expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
@@ -295,18 +269,16 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
295
269
  expect(out).to match(
296
270
  /\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
297
271
  )
298
- elsif RUBY_VERSION >= '3.0.0'
272
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
299
273
  expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:User> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
300
- elsif RUBY_VERSION >= '2.6.7' && RUBY_VERSION < '2.7.0'
274
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
301
275
  expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
302
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
276
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
303
277
  expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
304
- elsif RUBY_VERSION >= '2.7.0'
278
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
305
279
  expect(out).to match(
306
280
  /\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
307
281
  )
308
- else
309
- expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
310
282
  end
311
283
 
312
284
  # spec 3
@@ -316,16 +288,14 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
316
288
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
317
289
  elsif RUBY_PLATFORM == 'java'
318
290
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
319
- elsif RUBY_VERSION >= '3.0.0'
291
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
320
292
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:User> \(ActiveModel::Validations::ClassMethods\)/)
321
- elsif RUBY_VERSION =~ /2\.7\.(0|1)/ || (RUBY_VERSION >= '2.6.7' && RUBY_VERSION < '2.7.0')
293
+ elsif (Gem::Version.new('2.6.7')..Gem::Version.new('2.7.1')).cover? Gem::Version.new(RUBY_VERSION)
322
294
  expect(out).to match(
323
295
  /\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
324
296
  )
325
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
297
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
326
298
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
327
- else
328
- expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
329
299
  end
330
300
  end
331
301
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do
6
6
  let(:expected_ar_time_str) do
7
- if activerecord_6_1?
7
+ if activerecord_6_1? || activerecord_7_0?
8
8
  '15:30:45.000000000'
9
9
  else
10
10
  '15:30:45'
@@ -24,7 +24,7 @@ RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails?
24
24
 
25
25
  it 'formats HashWithIndifferentAccess as regular Hash' do
26
26
  hash = HashWithIndifferentAccess.new({ hello: 'world' })
27
- expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
27
+ expect(@ap.send(:awesome, hash)).to eq("{\n \e[0;33m\"hello\"\e[0m\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
28
28
  end
29
29
 
30
30
  # ActiveSupport sticks in instance variables to the date object. Make sure
@@ -5,67 +5,130 @@
5
5
  require 'spec_helper'
6
6
 
7
7
  RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
8
- if ExtVerifier.has_mongoid?
9
- before :all do
10
- class MongoUser
11
- include Mongoid::Document
8
+ before do
9
+ @ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
10
+ end
12
11
 
13
- field :first_name, type: String
14
- field :last_name, type: String
12
+ describe 'Document' do
13
+ if ExtVerifier.has_mongoid?
14
+ before :all do
15
+ class MongoUser
16
+ include Mongoid::Document
17
+
18
+ field :first_name, type: String
19
+ field :last_name, type: String
20
+ end
21
+ end
22
+
23
+ after :all do
24
+ Object.instance_eval { remove_const :MongoUser }
25
+ Object.instance_eval { remove_const :Chamelion }
15
26
  end
16
27
  end
17
28
 
18
- after :all do
19
- Object.instance_eval { remove_const :MongoUser }
20
- Object.instance_eval { remove_const :Chamelion }
29
+ it 'prints class instance' do
30
+ user = MongoUser.new first_name: 'Al', last_name: 'Capone'
31
+ out = @ap.send :awesome, user
32
+
33
+ object_id = user.id.inspect
34
+ str = <<~EOS.strip
35
+ #<MongoUser:placeholder_id> {
36
+ :_id => #{object_id},
37
+ :first_name => "Al",
38
+ :last_name => "Capone"
39
+ }
40
+ EOS
41
+ expect(out).to be_similar_to(str, { skip_bson: true })
21
42
  end
22
- end
23
43
 
24
- before do
25
- @ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
26
- end
44
+ it 'prints the class' do
45
+ class_spec = <<~EOS.strip
46
+ class MongoUser < Object {
47
+ :_id => :"bson/object_id",
48
+ :first_name => :string,
49
+ :last_name => :string
50
+ }
51
+ EOS
27
52
 
28
- it 'prints class instance' do
29
- user = MongoUser.new first_name: 'Al', last_name: 'Capone'
30
- out = @ap.send :awesome, user
31
-
32
- object_id = user.id.inspect
33
- str = <<~EOS.strip
34
- #<MongoUser:placeholder_id> {
35
- :_id => #{object_id},
36
- :first_name => "Al",
37
- :last_name => "Capone"
38
- }
39
- EOS
40
- expect(out).to be_similar_to(str, { skip_bson: true })
41
- end
53
+ expect(@ap.send(:awesome, MongoUser)).to eq class_spec
54
+ end
55
+
56
+ it 'prints the class when type is undefined' do
57
+ class Chamelion
58
+ include Mongoid::Document
59
+ field :last_attribute
60
+ end
42
61
 
43
- it 'prints the class' do
44
- class_spec = <<~EOS.strip
45
- class MongoUser < Object {
46
- :_id => :"bson/object_id",
47
- :first_name => :string,
48
- :last_name => :string
49
- }
50
- EOS
62
+ class_spec = <<~EOS.strip
63
+ class Chamelion < Object {
64
+ :_id => :"bson/object_id",
65
+ :last_attribute => :object
66
+ }
67
+ EOS
51
68
 
52
- expect(@ap.send(:awesome, MongoUser)).to eq class_spec
69
+ expect(@ap.send(:awesome, Chamelion)).to eq class_spec
70
+ end
53
71
  end
54
72
 
55
- it 'prints the class when type is undefined' do
56
- class Chamelion
57
- include Mongoid::Document
58
- field :last_attribute
73
+ describe 'Document with aliased fields' do
74
+ if ExtVerifier.has_mongoid?
75
+ before :all do
76
+ class MongoUser
77
+ include Mongoid::Document
78
+
79
+ field :fn, as: :first_name, type: String
80
+ field :ln, as: :last_name, type: String
81
+ end
82
+ end
83
+
84
+ after :all do
85
+ Object.instance_eval { remove_const :MongoUser }
86
+ Object.instance_eval { remove_const :Chamelion }
87
+ end
88
+ end
89
+
90
+ it 'prints class instance' do
91
+ user = MongoUser.new first_name: 'Al', last_name: 'Capone'
92
+ out = @ap.send :awesome, user
93
+
94
+ object_id = user.id.inspect
95
+ str = <<~EOS.strip
96
+ #<MongoUser:placeholder_id> {
97
+ :_id => #{object_id},
98
+ :"first_name(fn)" => "Al",
99
+ :"last_name(ln)" => "Capone"
100
+ }
101
+ EOS
102
+ expect(out).to be_similar_to(str, { skip_bson: true })
103
+ end
104
+
105
+ it 'prints the class' do
106
+ class_spec = <<~EOS.strip
107
+ class MongoUser < Object {
108
+ :_id => :"bson/object_id",
109
+ :"first_name(fn)" => :string,
110
+ :"last_name(ln)" => :string
111
+ }
112
+ EOS
113
+
114
+ expect(@ap.send(:awesome, MongoUser)).to eq class_spec
59
115
  end
60
116
 
61
- class_spec = <<~EOS.strip
62
- class Chamelion < Object {
63
- :_id => :"bson/object_id",
64
- :last_attribute => :object
65
- }
66
- EOS
117
+ it 'prints the class when type is undefined' do
118
+ class Chamelion
119
+ include Mongoid::Document
120
+ field :la, as: :last_attribute
121
+ end
67
122
 
68
- expect(@ap.send(:awesome, Chamelion)).to eq class_spec
123
+ class_spec = <<~EOS.strip
124
+ class Chamelion < Object {
125
+ :_id => :"bson/object_id",
126
+ :"last_attribute(la)" => :object
127
+ }
128
+ EOS
129
+
130
+ expect(@ap.send(:awesome, Chamelion)).to eq class_spec
131
+ end
69
132
  end
70
133
  end
71
134
 
@@ -6,9 +6,9 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
6
6
  it 'colorizes tags' do
7
7
  xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
8
8
  # FIXME: Due to something strange with Nokogiri and JRuby, we need to remove extra blank lines.
9
- output = xml.ai.gsub(/\n\n/, "\n")
9
+ output = xml.ai.gsub("\n\n", "\n")
10
10
  expect(output).to eq <<~EOS
11
- <?xml version=\"1.0\"?>\e[1;32m
11
+ <?xml version="1.0"?>\e[1;32m
12
12
  \e[0m<\e[1;36mhtml\e[0m>\e[1;32m
13
13
  \e[0m<\e[1;36mbody\e[0m>\e[1;32m
14
14
  \e[0m<\e[1;36mh1\e[0m/>\e[1;32m
@@ -20,7 +20,7 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
20
20
  it 'colorizes contents' do
21
21
  xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
22
22
  expect(xml.ai).to eq <<~EOS
23
- <?xml version=\"1.0\"?>\e[1;32m
23
+ <?xml version="1.0"?>\e[1;32m
24
24
  \e[0m<\e[1;36mhtml\e[0m>\e[1;32m
25
25
  \e[0m<\e[1;36mbody\e[0m>\e[1;32m
26
26
  \e[0m<\e[1;36mh1\e[0m>\e[1;32mHello\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
@@ -32,13 +32,13 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
32
32
  it 'colorizes class and id' do
33
33
  xml = Nokogiri::XML('<html><body><h1><span class="world" id="hello"></span></h1></body></html>')
34
34
  # FIXME: Due to something strange with Nokogiri and JRuby, we need to remove extra blank lines.
35
- output = xml.ai.gsub(/\n\n/, "\n")
35
+ output = xml.ai.gsub("\n\n", "\n")
36
36
  expect(output).to eq <<~EOS
37
- <?xml version=\"1.0\"?>\e[1;32m
37
+ <?xml version="1.0"?>\e[1;32m
38
38
  \e[0m<\e[1;36mhtml\e[0m>\e[1;32m
39
39
  \e[0m<\e[1;36mbody\e[0m>\e[1;32m
40
40
  \e[0m<\e[1;36mh1\e[0m>\e[1;32m
41
- \e[0m<\e[1;36mspan\e[0m \e[1;33mclass=\"world\"\e[0m \e[1;33mid=\"hello\"\e[0m/>\e[1;32m
41
+ \e[0m<\e[1;36mspan\e[0m \e[1;33mclass="world"\e[0m \e[1;33mid="hello"\e[0m/>\e[1;32m
42
42
  \e[0m<\e[1;36m/h1\e[0m>\e[1;32m
43
43
  \e[0m<\e[1;36m/body\e[0m>\e[1;32m
44
44
  \e[0m<\e[1;36m/html\e[0m>
@@ -39,7 +39,7 @@ RSpec.describe 'AmazingPrint/Sequel', skip: -> { !ExtVerifier.has_sequel? }.call
39
39
  end
40
40
 
41
41
  it 'does not crash if on Sequel::Model' do
42
- out = @ap.awesome(::Sequel::Model)
42
+ out = @ap.awesome(Sequel::Model)
43
43
  expect(out).to be_similar_to('Sequel::Model < Object')
44
44
  end
45
45
  end