amazing_print 1.2.0 → 1.4.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +38 -54
  3. data/CHANGELOG.md +36 -2
  4. data/Gemfile.lock +48 -50
  5. data/README.md +20 -11
  6. data/lib/amazing_print/colorize.rb +1 -3
  7. data/lib/amazing_print/core_ext/awesome_method_array.rb +4 -4
  8. data/lib/amazing_print/core_ext/class.rb +1 -1
  9. data/lib/amazing_print/core_ext/logger.rb +10 -5
  10. data/lib/amazing_print/core_ext/object.rb +1 -1
  11. data/lib/amazing_print/custom_defaults.rb +10 -3
  12. data/lib/amazing_print/ext/action_view.rb +1 -1
  13. data/lib/amazing_print/ext/active_record.rb +12 -27
  14. data/lib/amazing_print/ext/active_support.rb +1 -3
  15. data/lib/amazing_print/ext/mongo_mapper.rb +5 -8
  16. data/lib/amazing_print/ext/mongoid.rb +2 -6
  17. data/lib/amazing_print/ext/nobrainer.rb +7 -5
  18. data/lib/amazing_print/ext/nokogiri.rb +1 -3
  19. data/lib/amazing_print/ext/ostruct.rb +1 -3
  20. data/lib/amazing_print/ext/ripple.rb +4 -5
  21. data/lib/amazing_print/formatter.rb +5 -6
  22. data/lib/amazing_print/formatters/array_formatter.rb +6 -5
  23. data/lib/amazing_print/formatters/base_formatter.rb +20 -25
  24. data/lib/amazing_print/formatters/class_formatter.rb +1 -0
  25. data/lib/amazing_print/formatters/dir_formatter.rb +1 -0
  26. data/lib/amazing_print/formatters/file_formatter.rb +1 -0
  27. data/lib/amazing_print/formatters/hash_formatter.rb +5 -4
  28. data/lib/amazing_print/formatters/method_formatter.rb +1 -0
  29. data/lib/amazing_print/formatters/object_formatter.rb +2 -1
  30. data/lib/amazing_print/formatters/simple_formatter.rb +1 -0
  31. data/lib/amazing_print/formatters/struct_formatter.rb +2 -1
  32. data/lib/amazing_print/inspector.rb +29 -5
  33. data/lib/amazing_print/version.rb +1 -1
  34. data/lib/amazing_print.rb +2 -6
  35. data/spec/active_record_helper.rb +11 -0
  36. data/spec/colors_spec.rb +38 -46
  37. data/spec/core_ext/logger_spec.rb +42 -18
  38. data/spec/core_ext/string_spec.rb +2 -2
  39. data/spec/ext/action_controller_spec.rb +4 -4
  40. data/spec/ext/action_view_spec.rb +6 -1
  41. data/spec/ext/active_model_spec.rb +37 -0
  42. data/spec/ext/active_record_spec.rb +44 -23
  43. data/spec/ext/active_support_spec.rb +13 -4
  44. data/spec/ext/mongo_mapper_spec.rb +16 -12
  45. data/spec/ext/mongoid_spec.rb +7 -3
  46. data/spec/ext/nobrainer_spec.rb +6 -2
  47. data/spec/ext/nokogiri_spec.rb +3 -3
  48. data/spec/ext/ripple_spec.rb +6 -2
  49. data/spec/formats_spec.rb +24 -18
  50. data/spec/methods_spec.rb +12 -4
  51. data/spec/misc_spec.rb +15 -10
  52. data/spec/objects_spec.rb +4 -0
  53. data/spec/spec_helper.rb +4 -8
  54. data/spec/support/active_record_data/6_1_diana.txt +109 -0
  55. data/spec/support/active_record_data/6_1_multi.txt +220 -0
  56. data/spec/support/ext_verifier.rb +2 -4
  57. data/spec/support/rails_versions.rb +5 -0
  58. metadata +80 -60
@@ -6,19 +6,24 @@ require 'logger'
6
6
  require 'amazing_print/core_ext/logger'
7
7
 
8
8
  RSpec.describe 'AmazingPrint logging extensions' do
9
- before(:all) do
10
- @logger = begin
11
- Logger.new('/dev/null')
12
- rescue Errno::ENOENT
13
- Logger.new('nul')
14
- end
9
+ subject(:logger) do
10
+ Logger.new('/dev/null')
11
+ rescue Errno::ENOENT
12
+ Logger.new('nul')
15
13
  end
16
14
 
15
+ let(:object) { double }
16
+ let(:options) { { sort_keys: true } }
17
+
17
18
  describe 'ap method' do
18
- it 'should awesome_inspect the given object' do
19
- object = double
19
+ it 'awesome_inspects the given object' do
20
20
  expect(object).to receive(:ai)
21
- @logger.ap object
21
+ logger.ap object
22
+ end
23
+
24
+ it 'passes options to `ai`' do
25
+ expect(object).to receive(:ai).with(options)
26
+ logger.ap object, options
22
27
  end
23
28
 
24
29
  describe 'the log level' do
@@ -26,20 +31,39 @@ RSpec.describe 'AmazingPrint logging extensions' do
26
31
  AmazingPrint.defaults = {}
27
32
  end
28
33
 
29
- it 'should fallback to the default :debug log level' do
30
- expect(@logger).to receive(:debug)
31
- @logger.ap(nil)
34
+ it 'fallbacks to the default :debug log level' do
35
+ expect(logger).to receive(:debug)
36
+ logger.ap nil
32
37
  end
33
38
 
34
- it 'should use the global user default if no level passed' do
39
+ it 'uses the global user default if no level passed' do
35
40
  AmazingPrint.defaults = { log_level: :info }
36
- expect(@logger).to receive(:info)
37
- @logger.ap(nil)
41
+ expect(logger).to receive(:info)
42
+ logger.ap nil
43
+ end
44
+
45
+ it 'uses the passed in level' do
46
+ expect(logger).to receive(:warn)
47
+ logger.ap nil, :warn
48
+ end
49
+
50
+ it 'makes no difference if passed as a hash or a part of options' do
51
+ expect(logger).to receive(:warn)
52
+ logger.ap nil, { level: :warn }
38
53
  end
39
54
 
40
- it 'should use the passed in level' do
41
- expect(@logger).to receive(:warn)
42
- @logger.ap(nil, :warn)
55
+ context 'when given options' do
56
+ it 'uses the default log level with the options' do
57
+ expect(logger).to receive(:debug)
58
+ expect(object).to receive(:ai).with(options)
59
+ logger.ap object, options
60
+ end
61
+
62
+ it 'still uses the passed in level with options' do
63
+ expect(logger).to receive(:warn)
64
+ expect(object).to receive(:ai).with(options)
65
+ logger.ap object, options.merge({ level: :warn })
66
+ end
43
67
  end
44
68
  end
45
69
  end
@@ -4,11 +4,11 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe 'String extensions' do
6
6
  %i[gray red green yellow blue purple cyan white].each_with_index do |color, i|
7
- it "should have #{color} color" do
7
+ it "has #{color} color" do
8
8
  expect(color.to_s.send(color)).to eq("\e[1;#{30 + i}m#{color}\e[0m")
9
9
  end
10
10
 
11
- it "should have #{color}ish color" do
11
+ it "has #{color}ish color" do
12
12
  expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m")
13
13
  end
14
14
  end
@@ -10,9 +10,9 @@ RSpec.describe 'AmazingPrint::ActionController', skip: -> { !ExtVerifier.has_rai
10
10
  ActionController::Parameters.new post: { id: 1, content: 'Some' }
11
11
  end
12
12
 
13
- it 'should format as an object' do
14
- expect(inspector.send(:awesome, parameters)).to eq(
15
- '<ActionController::Parameters {"post"=>{"id"=>1, "content"=>"Some"}} permitted: false>'
13
+ it 'formats as an object' do
14
+ expect(inspector.send(:awesome, parameters)).to match(
15
+ /\A#?<ActionController::Parameters {"post"=>{"id"=>1, "content"=>"Some"}} permitted: false>\z/
16
16
  )
17
17
  end
18
18
  end
@@ -33,7 +33,7 @@ RSpec.describe 'AmazingPrint::ActionController', skip: -> { !ExtVerifier.has_rai
33
33
  ActionController::Parameters.new post: { id: 1, content: 'Some' }
34
34
  end
35
35
 
36
- it 'should format as a hash' do
36
+ it 'formats as a hash' do
37
37
  expect(inspector.send(:awesome, parameters.permit!)).to eq expected_output
38
38
  end
39
39
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe 'AmazingPrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do
5
+ RSpec.describe 'AmazingPrint ActionView extensions',
6
+ skip: -> { !ExtVerifier.has_rails? || ActiveRecord::VERSION::STRING >= '6.1' }.call do
6
7
  before do
7
8
  @view = ActionView::Base.new
8
9
  end
@@ -16,4 +17,8 @@ RSpec.describe 'AmazingPrint ActionView extensions', skip: -> { !ExtVerifier.has
16
17
  markup = ' &<hello>'
17
18
  expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
18
19
  end
20
+
21
+ it 'uses HTML and does set output to HTML safe' do
22
+ expect(@view.ap('<p>Hello World</p>')).to be_html_safe
23
+ end
19
24
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'active_record_helper'
5
+
6
+ RSpec.describe 'ActiveModel::Errors formatting', skip: -> { !ExtVerifier.has_rails? }.call do
7
+ before do
8
+ @ap = AmazingPrint::Inspector.new(plain: true)
9
+ end
10
+
11
+ it 'formats active_model_errors properly' do
12
+ model = TableFreeModel.new
13
+ model.errors.add(:name, "can't be blank")
14
+
15
+ out = @ap.awesome(model.errors)
16
+
17
+ str = <<~ERRORS.strip
18
+ #<ActiveModel::Errors:placeholder_id> {
19
+ "name" => nil,
20
+ :details => {
21
+ :name => [
22
+ [0] {
23
+ :error => "can't be blank"
24
+ }
25
+ ]
26
+ },
27
+ :messages => {
28
+ :name => [
29
+ [0] "can't be blank"
30
+ ]
31
+ }
32
+ }
33
+ ERRORS
34
+
35
+ expect(out).to be_similar_to(str)
36
+ end
37
+ end
@@ -99,7 +99,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
99
99
  @ap = AmazingPrint::Inspector.new(plain: true)
100
100
  end
101
101
 
102
- it 'should show the entire record' do
102
+ it 'shows the entire record' do
103
103
  e = Email.create(email_address: 'foo@bar.com')
104
104
  u = User.last
105
105
  u.emails << e
@@ -128,7 +128,9 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
128
128
  out = @ap.awesome(@diana)
129
129
 
130
130
  raw_object_string =
131
- if activerecord_6_0?
131
+ if activerecord_6_1?
132
+ ActiveRecordData.raw_6_1_diana
133
+ elsif activerecord_6_0?
132
134
  ActiveRecordData.raw_6_0_diana
133
135
  elsif activerecord_5_2?
134
136
  ActiveRecordData.raw_5_2_diana
@@ -154,7 +156,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
154
156
  end
155
157
  end
156
158
 
157
- if RUBY_PLATFORM == 'java'
159
+ if RUBY_PLATFORM == 'java' && !activerecord_6_1?
158
160
  raw_object_string.gsub!(
159
161
  'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
160
162
  'ArJdbc::SQLite3::SQLite3Integer'
@@ -168,7 +170,9 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
168
170
  out = @ap.awesome([@diana, @laura])
169
171
 
170
172
  raw_object_string =
171
- if activerecord_6_0?
173
+ if activerecord_6_1?
174
+ ActiveRecordData.raw_6_1_multi
175
+ elsif activerecord_6_0?
172
176
  ActiveRecordData.raw_6_0_multi
173
177
  elsif activerecord_5_2?
174
178
  ActiveRecordData.raw_5_2_multi
@@ -194,7 +198,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
194
198
  end
195
199
  end
196
200
 
197
- if RUBY_PLATFORM == 'java'
201
+ if RUBY_PLATFORM == 'java' && !activerecord_6_1?
198
202
  raw_object_string.gsub!(
199
203
  'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
200
204
  'ArJdbc::SQLite3::SQLite3Integer'
@@ -212,7 +216,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
212
216
  @ap = AmazingPrint::Inspector.new(plain: true)
213
217
  end
214
218
 
215
- it 'should print the class' do
219
+ it 'prints the class' do
216
220
  expect(@ap.awesome(User)).to eq <<~EOS.strip
217
221
  class User < ActiveRecord::Base {
218
222
  :id => :integer,
@@ -224,7 +228,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
224
228
  EOS
225
229
  end
226
230
 
227
- it 'should print the class for non-direct subclasses of ActiveRecord::Base' do
231
+ it 'prints the class for non-direct subclasses of ActiveRecord::Base' do
228
232
  out = @ap.awesome(SubUser)
229
233
  expect(out).to eq <<~EOS.strip
230
234
  class SubUser < User {
@@ -237,9 +241,14 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
237
241
  EOS
238
242
  end
239
243
 
240
- it 'should print ActiveRecord::Base objects (ex. ancestors)' do
244
+ it 'prints ActiveRecord::Base objects (ex. ancestors)' do
241
245
  expect { @ap.awesome(User.ancestors) }.not_to raise_error
242
246
  end
247
+
248
+ it 'prints valid HTML for subclasses' do
249
+ @ap = AmazingPrint::Inspector.new(html: true)
250
+ expect(@ap.awesome(SubUser)).to match('SubUser &lt; User')
251
+ end
243
252
  end
244
253
 
245
254
  #------------------------------------------------------------------------------
@@ -248,7 +257,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
248
257
  @ap = AmazingPrint::Inspector.new(plain: true)
249
258
  end
250
259
 
251
- it 'should format class methods properly' do
260
+ it 'formats class methods properly' do
252
261
  # spec 1
253
262
  out = @ap.awesome(User.methods.grep(/first/))
254
263
 
@@ -257,7 +266,15 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
257
266
  expect(out).to match(
258
267
  /\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
259
268
  )
260
- elsif RUBY_VERSION >= '2.7.0'
269
+ elsif RUBY_VERSION >= '3.0.0'
270
+ expect(out).to match(
271
+ /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
272
+ )
273
+ elsif RUBY_VERSION >= '2.7.2'
274
+ expect(out).to match(
275
+ /\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
276
+ )
277
+ elsif RUBY_VERSION >= '2.6.7'
261
278
  expect(out).to match(
262
279
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
263
280
  )
@@ -278,12 +295,16 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
278
295
  expect(out).to match(
279
296
  /\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
280
297
  )
298
+ elsif RUBY_VERSION >= '3.0.0'
299
+ 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'
301
+ 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'
303
+ expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
281
304
  elsif RUBY_VERSION >= '2.7.0'
282
305
  expect(out).to match(
283
306
  /\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
284
307
  )
285
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./
286
- expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
287
308
  else
288
309
  expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
289
310
  end
@@ -293,18 +314,18 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
293
314
 
294
315
  if ActiveRecord::VERSION::MAJOR < 3
295
316
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
317
+ elsif RUBY_PLATFORM == 'java'
318
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
319
+ elsif RUBY_VERSION >= '3.0.0'
320
+ 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')
322
+ expect(out).to match(
323
+ /\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
324
+ )
325
+ elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
326
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
296
327
  else
297
- if RUBY_PLATFORM == 'java'
298
- expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
299
- elsif RUBY_VERSION >= '2.7.0'
300
- expect(out).to match(
301
- /\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
302
- )
303
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./
304
- expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
305
- else
306
- expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
307
- end
328
+ expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
308
329
  end
309
330
  end
310
331
  end
@@ -3,24 +3,33 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do
6
+ let(:expected_ar_time_str) do
7
+ if activerecord_6_1?
8
+ '15:30:45.000000000'
9
+ else
10
+ '15:30:45'
11
+ end
12
+ end
13
+
6
14
  before do
7
15
  @ap = AmazingPrint::Inspector.new
8
16
  end
9
17
 
10
- it 'should format ActiveSupport::TimeWithZone as regular Time' do
18
+ it 'formats ActiveSupport::TimeWithZone as regular Time' do
11
19
  Time.zone = 'Eastern Time (US & Canada)'
12
20
  time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
13
- expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
21
+ expect(@ap.send(:awesome, time))
22
+ .to eq("\e[0;32mSat, 10 Feb 2007 #{expected_ar_time_str} EST -05:00\e[0m")
14
23
  end
15
24
 
16
- it 'should format HashWithIndifferentAccess as regular Hash' do
25
+ it 'formats HashWithIndifferentAccess as regular Hash' do
17
26
  hash = HashWithIndifferentAccess.new({ hello: 'world' })
18
27
  expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
19
28
  end
20
29
 
21
30
  # ActiveSupport sticks in instance variables to the date object. Make sure
22
31
  # we ignore that and format Date instance as regular date.
23
- it 'should formate Date object as date' do
32
+ it 'formates Date object as date' do
24
33
  date = Date.new(2003, 5, 26)
25
34
  expect(date.ai(plain: true)).to eq('Mon, 26 May 2003')
26
35
  expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Lint/ConstantDefinitionInBlock
4
+
3
5
  require 'spec_helper'
4
6
 
5
7
  RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do
@@ -27,12 +29,12 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
27
29
  # before { @ap.options[:raw] = true }
28
30
  before { @ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true, raw: true) }
29
31
 
30
- it 'should print class instance' do
32
+ it 'prints class instance' do
31
33
  user = MongoUser.new(first_name: 'Al', last_name: 'Capone')
32
34
 
33
35
  out = @ap.send(:awesome, user)
34
- out.gsub!(/#\<Proc:.+?\>/, 'amazing_print_PROC_STUB')
35
- out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
36
+ .gsub(/#<Proc:.+?>/, 'amazing_print_PROC_STUB')
37
+ .gsub(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
36
38
 
37
39
  str = if MongoMapper::Version >= '0.13'
38
40
  <<~EOS.strip
@@ -129,7 +131,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
129
131
  expect(out).to be_similar_to(str)
130
132
  end
131
133
 
132
- it 'should print the class' do
134
+ it 'prints the class' do
133
135
  expect(@ap.send(:awesome, MongoUser)).to eq <<~EOS.strip
134
136
  class MongoUser < Object {
135
137
  "_id" => :object_id,
@@ -139,7 +141,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
139
141
  EOS
140
142
  end
141
143
 
142
- it 'should print the class when type is undefined' do
144
+ it 'prints the class when type is undefined' do
143
145
  class Chamelion
144
146
  include MongoMapper::Document
145
147
  key :last_attribute
@@ -178,7 +180,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
178
180
  end
179
181
 
180
182
  describe 'with show associations turned off (default)' do
181
- it 'should render the class as normal' do
183
+ it 'renders the class as normal' do
182
184
  expect(@ap.send(:awesome, Parent)).to eq <<~EOS.strip
183
185
  class Parent < Object {
184
186
  "_id" => :object_id,
@@ -187,7 +189,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
187
189
  EOS
188
190
  end
189
191
 
190
- it 'should render an instance as normal' do
192
+ it 'renders an instance as normal' do
191
193
  parent = Parent.new(name: 'test')
192
194
  out = @ap.send(:awesome, parent)
193
195
  str = <<~EOS.strip
@@ -201,11 +203,11 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
201
203
  end
202
204
 
203
205
  describe 'with show associations turned on and inline embedded turned off' do
204
- before :each do
206
+ before do
205
207
  @ap = AmazingPrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true })
206
208
  end
207
209
 
208
- it 'should render the class with associations shown' do
210
+ it 'renders the class with associations shown' do
209
211
  expect(@ap.send(:awesome, Parent)).to eq <<~EOS.strip
210
212
  class Parent < Object {
211
213
  "_id" => :object_id,
@@ -216,7 +218,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
216
218
  EOS
217
219
  end
218
220
 
219
- it 'should render an instance with associations shown' do
221
+ it 'renders an instance with associations shown' do
220
222
  parent = Parent.new(name: 'test')
221
223
  out = @ap.send(:awesome, parent)
222
224
  str = <<~EOS.strip
@@ -232,7 +234,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
232
234
  end
233
235
 
234
236
  describe 'with show associations turned on and inline embedded turned on' do
235
- before :each do
237
+ before do
236
238
  @ap = AmazingPrint::Inspector.new plain: true,
237
239
  mongo_mapper: {
238
240
  show_associations: true,
@@ -240,7 +242,7 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
240
242
  }
241
243
  end
242
244
 
243
- it 'should render an instance with associations shown and embeds there' do
245
+ it 'renders an instance with associations shown and embeds there' do
244
246
  parent = Parent.new(name: 'test', child: Child.new(data: 5))
245
247
  out = @ap.send(:awesome, parent)
246
248
  str = <<~EOS.strip
@@ -259,3 +261,5 @@ RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
259
261
  end
260
262
  end
261
263
  end
264
+
265
+ # rubocop:enable Lint/ConstantDefinitionInBlock
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Lint/ConstantDefinitionInBlock
4
+
3
5
  require 'spec_helper'
4
6
 
5
7
  RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
@@ -23,7 +25,7 @@ RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.ca
23
25
  @ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
24
26
  end
25
27
 
26
- it 'should print class instance' do
28
+ it 'prints class instance' do
27
29
  user = MongoUser.new first_name: 'Al', last_name: 'Capone'
28
30
  out = @ap.send :awesome, user
29
31
 
@@ -38,7 +40,7 @@ RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.ca
38
40
  expect(out).to be_similar_to(str, { skip_bson: true })
39
41
  end
40
42
 
41
- it 'should print the class' do
43
+ it 'prints the class' do
42
44
  class_spec = <<~EOS.strip
43
45
  class MongoUser < Object {
44
46
  :_id => :"bson/object_id",
@@ -50,7 +52,7 @@ RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.ca
50
52
  expect(@ap.send(:awesome, MongoUser)).to eq class_spec
51
53
  end
52
54
 
53
- it 'should print the class when type is undefined' do
55
+ it 'prints the class when type is undefined' do
54
56
  class Chamelion
55
57
  include Mongoid::Document
56
58
  field :last_attribute
@@ -66,3 +68,5 @@ RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.ca
66
68
  expect(@ap.send(:awesome, Chamelion)).to eq class_spec
67
69
  end
68
70
  end
71
+
72
+ # rubocop:enable Lint/ConstantDefinitionInBlock
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Lint/ConstantDefinitionInBlock
4
+
3
5
  require 'spec_helper'
4
6
 
5
7
  RSpec.describe 'AmazingPrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer? }.call do
@@ -30,7 +32,7 @@ RSpec.describe 'AmazingPrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer?
30
32
  @ap = AmazingPrint::Inspector.new plain: true
31
33
  end
32
34
 
33
- it 'should print class instance' do
35
+ it 'prints class instance' do
34
36
  user = SomeModel.new first_name: 'Al', last_name: 'Capone'
35
37
  out = @ap.send :awesome, user
36
38
 
@@ -45,7 +47,7 @@ RSpec.describe 'AmazingPrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer?
45
47
  expect(out).to eq(str)
46
48
  end
47
49
 
48
- it 'should print the class' do
50
+ it 'prints the class' do
49
51
  class_spec = <<~EOS.strip
50
52
  class SomeModel < Object {
51
53
  :id => :string,
@@ -58,3 +60,5 @@ RSpec.describe 'AmazingPrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer?
58
60
  expect(@ap.send(:awesome, SomeModel)).to eq class_spec
59
61
  end
60
62
  end
63
+
64
+ # rubocop:enable Lint/ConstantDefinitionInBlock
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe 'AmazingPrint/Nokogiri' do
6
- it 'should colorize tags' do
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
9
  output = xml.ai.gsub(/\n\n/, "\n")
@@ -17,7 +17,7 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
17
17
  EOS
18
18
  end
19
19
 
20
- it 'should colorize contents' do
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
23
  <?xml version=\"1.0\"?>\e[1;32m
@@ -29,7 +29,7 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
29
29
  EOS
30
30
  end
31
31
 
32
- it 'should colorize class and id' do
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
35
  output = xml.ai.gsub(/\n\n/, "\n")
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Lint/ConstantDefinitionInBlock
4
+
3
5
  require 'spec_helper'
4
6
 
5
7
  RSpec.describe 'AmazingPrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call do
@@ -24,7 +26,7 @@ RSpec.describe 'AmazingPrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call
24
26
  @ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
25
27
  end
26
28
 
27
- it 'should print class instance' do
29
+ it 'prints class instance' do
28
30
  user = RippleUser.new _id: '12345', first_name: 'Al', last_name: 'Capone'
29
31
  out = @ap.send :awesome, user
30
32
 
@@ -37,7 +39,7 @@ RSpec.describe 'AmazingPrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call
37
39
  EOS
38
40
  end
39
41
 
40
- it 'should print the class' do
42
+ it 'prints the class' do
41
43
  expect(@ap.send(:awesome, RippleUser)).to eq <<~EOS.strip
42
44
  class RippleUser < Object {
43
45
  :_id => :string,
@@ -47,3 +49,5 @@ RSpec.describe 'AmazingPrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call
47
49
  EOS
48
50
  end
49
51
  end
52
+
53
+ # rubocop:enable Lint/ConstantDefinitionInBlock