amazing_print 1.3.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.
- checksums.yaml +4 -4
- data/Appraisals +0 -6
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +34 -36
- data/README.md +8 -5
- data/lib/amazing_print/colorize.rb +1 -3
- data/lib/amazing_print/core_ext/awesome_method_array.rb +4 -4
- data/lib/amazing_print/core_ext/class.rb +1 -1
- data/lib/amazing_print/core_ext/logger.rb +1 -3
- data/lib/amazing_print/core_ext/object.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +10 -3
- data/lib/amazing_print/ext/active_record.rb +5 -9
- data/lib/amazing_print/ext/active_support.rb +1 -3
- data/lib/amazing_print/ext/mongo_mapper.rb +4 -7
- data/lib/amazing_print/ext/mongoid.rb +2 -6
- data/lib/amazing_print/ext/nobrainer.rb +3 -5
- data/lib/amazing_print/ext/nokogiri.rb +1 -3
- data/lib/amazing_print/ext/ostruct.rb +1 -3
- data/lib/amazing_print/ext/ripple.rb +4 -5
- data/lib/amazing_print/formatter.rb +5 -6
- data/lib/amazing_print/formatters/array_formatter.rb +6 -5
- data/lib/amazing_print/formatters/base_formatter.rb +20 -25
- data/lib/amazing_print/formatters/class_formatter.rb +1 -0
- data/lib/amazing_print/formatters/dir_formatter.rb +1 -0
- data/lib/amazing_print/formatters/file_formatter.rb +1 -0
- data/lib/amazing_print/formatters/hash_formatter.rb +3 -2
- data/lib/amazing_print/formatters/method_formatter.rb +1 -0
- data/lib/amazing_print/formatters/object_formatter.rb +2 -1
- data/lib/amazing_print/formatters/simple_formatter.rb +1 -0
- data/lib/amazing_print/formatters/struct_formatter.rb +2 -1
- data/lib/amazing_print/inspector.rb +29 -5
- data/lib/amazing_print/version.rb +1 -1
- data/lib/amazing_print.rb +2 -6
- data/spec/active_record_helper.rb +3 -0
- data/spec/colors_spec.rb +6 -2
- data/spec/core_ext/logger_spec.rb +7 -7
- data/spec/core_ext/string_spec.rb +2 -2
- data/spec/ext/action_controller_spec.rb +2 -2
- data/spec/ext/active_model_spec.rb +1 -1
- data/spec/ext/active_record_spec.rb +23 -23
- data/spec/ext/active_support_spec.rb +3 -3
- data/spec/ext/mongo_mapper_spec.rb +15 -11
- data/spec/ext/mongoid_spec.rb +7 -3
- data/spec/ext/nobrainer_spec.rb +6 -2
- data/spec/ext/nokogiri_spec.rb +3 -3
- data/spec/ext/ripple_spec.rb +6 -2
- data/spec/formats_spec.rb +24 -18
- data/spec/methods_spec.rb +12 -4
- data/spec/misc_spec.rb +15 -10
- data/spec/objects_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -8
- metadata +19 -5
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :hash, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(hash, inspector)
|
11
|
+
super()
|
11
12
|
@hash = hash
|
12
13
|
@inspector = inspector
|
13
14
|
@options = inspector.options
|
@@ -55,12 +56,12 @@ module AmazingPrint
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
should_be_limited? ? limited(data, width,
|
59
|
+
should_be_limited? ? limited(data, width, is_hash: true) : data
|
59
60
|
end
|
60
61
|
|
61
62
|
def left_width(keys)
|
62
63
|
result = max_key_width(keys)
|
63
|
-
result += indentation if options[:indent]
|
64
|
+
result += indentation if options[:indent].positive?
|
64
65
|
result
|
65
66
|
end
|
66
67
|
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :object, :variables, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(object, inspector)
|
11
|
+
super()
|
11
12
|
@object = object
|
12
13
|
@variables = object.instance_variables
|
13
14
|
@inspector = inspector
|
@@ -38,7 +39,7 @@ module AmazingPrint
|
|
38
39
|
key = if key =~ /(@\w+)/
|
39
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
40
41
|
else
|
41
|
-
key.sub(/(attr_\w+)\s(
|
42
|
+
key.sub(/(attr_\w+)\s(:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -8,6 +8,7 @@ module AmazingPrint
|
|
8
8
|
attr_reader :struct, :variables, :inspector, :options
|
9
9
|
|
10
10
|
def initialize(struct, inspector)
|
11
|
+
super()
|
11
12
|
@struct = struct
|
12
13
|
@variables = struct.members
|
13
14
|
@inspector = inspector
|
@@ -38,7 +39,7 @@ module AmazingPrint
|
|
38
39
|
key = if key =~ /(@\w+)/
|
39
40
|
key.sub(Regexp.last_match(1), colorize(Regexp.last_match(1), :variable))
|
40
41
|
else
|
41
|
-
key.sub(/(attr_\w+)\s(
|
42
|
+
key.sub(/(attr_\w+)\s(:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -5,6 +5,9 @@
|
|
5
5
|
# AmazingPrint is freely distributable under the terms of MIT license.
|
6
6
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
7
7
|
#------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
# rubocop:disable Metrics/ClassLength
|
10
|
+
|
8
11
|
require_relative 'indentator'
|
9
12
|
|
10
13
|
module AmazingPrint
|
@@ -13,6 +16,15 @@ module AmazingPrint
|
|
13
16
|
|
14
17
|
AP = :__amazing_print__
|
15
18
|
|
19
|
+
##
|
20
|
+
# Unload the cached dotfile and load it again.
|
21
|
+
#
|
22
|
+
def self.reload_dotfile
|
23
|
+
@@dotfile = nil
|
24
|
+
new.send :load_dotfile
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
16
28
|
def initialize(options = {})
|
17
29
|
@options = {
|
18
30
|
indent: 4, # Number of spaces for indenting.
|
@@ -91,7 +103,7 @@ module AmazingPrint
|
|
91
103
|
if defined? @colorize_stdout
|
92
104
|
@colorize_stdout
|
93
105
|
else
|
94
|
-
@colorize_stdout =
|
106
|
+
@colorize_stdout = $stdout.tty? && (
|
95
107
|
(
|
96
108
|
ENV['TERM'] &&
|
97
109
|
ENV['TERM'] != 'dumb'
|
@@ -147,18 +159,28 @@ module AmazingPrint
|
|
147
159
|
@options.merge!(options)
|
148
160
|
end
|
149
161
|
|
162
|
+
def find_dotfile
|
163
|
+
xdg_config_home = File.expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
164
|
+
xdg_config_path = File.join(xdg_config_home, 'aprc') # ${XDG_CONFIG_HOME}/aprc
|
165
|
+
|
166
|
+
return xdg_config_path if File.exist?(xdg_config_path)
|
167
|
+
|
168
|
+
# default to ~/.aprc
|
169
|
+
File.join(ENV['HOME'], '.aprc')
|
170
|
+
end
|
171
|
+
|
150
172
|
# This method needs to be mocked during testing so that it always loads
|
151
173
|
# predictable values
|
152
174
|
#---------------------------------------------------------------------------
|
153
175
|
def load_dotfile
|
154
|
-
dotfile
|
176
|
+
return if @@dotfile # Load the dotfile only once.
|
177
|
+
|
178
|
+
dotfile = find_dotfile
|
155
179
|
load dotfile if dotfile_readable?(dotfile)
|
156
180
|
end
|
157
181
|
|
158
182
|
def dotfile_readable?(dotfile)
|
159
|
-
if @@dotfile_readable.nil? || @@dotfile != dotfile
|
160
|
-
@@dotfile_readable = File.readable?(@@dotfile = dotfile)
|
161
|
-
end
|
183
|
+
@@dotfile_readable = File.readable?(@@dotfile = dotfile) if @@dotfile_readable.nil? || @@dotfile != dotfile
|
162
184
|
@@dotfile_readable
|
163
185
|
end
|
164
186
|
@@dotfile_readable = @@dotfile = nil
|
@@ -173,3 +195,5 @@ module AmazingPrint
|
|
173
195
|
end
|
174
196
|
end
|
175
197
|
end
|
198
|
+
|
199
|
+
# rubocop:enable Metrics/ClassLength
|
data/lib/amazing_print.rb
CHANGED
@@ -23,12 +23,8 @@ unless defined?(AmazingPrint::Inspector)
|
|
23
23
|
# Load the following under normal circumstances as well as in Rails
|
24
24
|
# console when required from ~/.irbrc or ~/.pryrc.
|
25
25
|
#
|
26
|
-
if defined?(ActiveRecord) || AmazingPrint.rails_console?
|
27
|
-
|
28
|
-
end
|
29
|
-
if defined?(ActiveSupport) || AmazingPrint.rails_console?
|
30
|
-
require_relative 'amazing_print/ext/active_support'
|
31
|
-
end
|
26
|
+
require_relative 'amazing_print/ext/active_record' if defined?(ActiveRecord) || AmazingPrint.rails_console?
|
27
|
+
require_relative 'amazing_print/ext/active_support' if defined?(ActiveSupport) || AmazingPrint.rails_console?
|
32
28
|
#
|
33
29
|
# Load remaining extensions.
|
34
30
|
#
|
@@ -27,8 +27,11 @@ if ExtVerifier.has_rails?
|
|
27
27
|
|
28
28
|
# Create models
|
29
29
|
class User < ActiveRecord::Base; has_many :emails; end
|
30
|
+
|
30
31
|
class SubUser < User; end
|
32
|
+
|
31
33
|
class Email < ActiveRecord::Base; belongs_to :user; end
|
34
|
+
|
32
35
|
class TableFreeModel
|
33
36
|
include ::ActiveModel::Validations
|
34
37
|
attr_reader(:name)
|
data/spec/colors_spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
|
5
7
|
RSpec.describe 'AmazingPrint' do
|
6
|
-
def stub_tty!(output = true, stream =
|
8
|
+
def stub_tty!(output = true, stream = $stdout)
|
7
9
|
if output
|
8
10
|
stream.instance_eval do
|
9
11
|
def tty?
|
@@ -31,7 +33,7 @@ RSpec.describe 'AmazingPrint' do
|
|
31
33
|
|
32
34
|
describe 'default settings (no forced colors)' do
|
33
35
|
before do
|
34
|
-
AmazingPrint.force_colors! false
|
36
|
+
AmazingPrint.force_colors! colors: false
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'colorizes tty processes by default' do
|
@@ -109,3 +111,5 @@ RSpec.describe 'AmazingPrint' do
|
|
109
111
|
end
|
110
112
|
end
|
111
113
|
end
|
114
|
+
|
115
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|
@@ -6,17 +6,17 @@ require 'logger'
|
|
6
6
|
require 'amazing_print/core_ext/logger'
|
7
7
|
|
8
8
|
RSpec.describe 'AmazingPrint logging extensions' do
|
9
|
-
let(:object) { double }
|
10
|
-
let(:options) { { sort_keys: true } }
|
11
|
-
|
12
9
|
subject(:logger) do
|
13
10
|
Logger.new('/dev/null')
|
14
11
|
rescue Errno::ENOENT
|
15
12
|
Logger.new('nul')
|
16
13
|
end
|
17
14
|
|
15
|
+
let(:object) { double }
|
16
|
+
let(:options) { { sort_keys: true } }
|
17
|
+
|
18
18
|
describe 'ap method' do
|
19
|
-
it '
|
19
|
+
it 'awesome_inspects the given object' do
|
20
20
|
expect(object).to receive(:ai)
|
21
21
|
logger.ap object
|
22
22
|
end
|
@@ -31,18 +31,18 @@ RSpec.describe 'AmazingPrint logging extensions' do
|
|
31
31
|
AmazingPrint.defaults = {}
|
32
32
|
end
|
33
33
|
|
34
|
-
it '
|
34
|
+
it 'fallbacks to the default :debug log level' do
|
35
35
|
expect(logger).to receive(:debug)
|
36
36
|
logger.ap nil
|
37
37
|
end
|
38
38
|
|
39
|
-
it '
|
39
|
+
it 'uses the global user default if no level passed' do
|
40
40
|
AmazingPrint.defaults = { log_level: :info }
|
41
41
|
expect(logger).to receive(:info)
|
42
42
|
logger.ap nil
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
45
|
+
it 'uses the passed in level' do
|
46
46
|
expect(logger).to receive(:warn)
|
47
47
|
logger.ap nil, :warn
|
48
48
|
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 "
|
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 "
|
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,7 +10,7 @@ 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 '
|
13
|
+
it 'formats as an object' do
|
14
14
|
expect(inspector.send(:awesome, parameters)).to match(
|
15
15
|
/\A#?<ActionController::Parameters {"post"=>{"id"=>1, "content"=>"Some"}} permitted: false>\z/
|
16
16
|
)
|
@@ -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 '
|
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
|
@@ -8,7 +8,7 @@ RSpec.describe 'ActiveModel::Errors formatting', skip: -> { !ExtVerifier.has_rai
|
|
8
8
|
@ap = AmazingPrint::Inspector.new(plain: true)
|
9
9
|
end
|
10
10
|
|
11
|
-
it '
|
11
|
+
it 'formats active_model_errors properly' do
|
12
12
|
model = TableFreeModel.new
|
13
13
|
model.errors.add(:name, "can't be blank")
|
14
14
|
|
@@ -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 '
|
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
|
@@ -216,7 +216,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
216
216
|
@ap = AmazingPrint::Inspector.new(plain: true)
|
217
217
|
end
|
218
218
|
|
219
|
-
it '
|
219
|
+
it 'prints the class' do
|
220
220
|
expect(@ap.awesome(User)).to eq <<~EOS.strip
|
221
221
|
class User < ActiveRecord::Base {
|
222
222
|
:id => :integer,
|
@@ -228,7 +228,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
228
228
|
EOS
|
229
229
|
end
|
230
230
|
|
231
|
-
it '
|
231
|
+
it 'prints the class for non-direct subclasses of ActiveRecord::Base' do
|
232
232
|
out = @ap.awesome(SubUser)
|
233
233
|
expect(out).to eq <<~EOS.strip
|
234
234
|
class SubUser < User {
|
@@ -241,11 +241,11 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
241
241
|
EOS
|
242
242
|
end
|
243
243
|
|
244
|
-
it '
|
244
|
+
it 'prints ActiveRecord::Base objects (ex. ancestors)' do
|
245
245
|
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
246
246
|
end
|
247
247
|
|
248
|
-
it '
|
248
|
+
it 'prints valid HTML for subclasses' do
|
249
249
|
@ap = AmazingPrint::Inspector.new(html: true)
|
250
250
|
expect(@ap.awesome(SubUser)).to match('SubUser < User')
|
251
251
|
end
|
@@ -257,7 +257,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
257
257
|
@ap = AmazingPrint::Inspector.new(plain: true)
|
258
258
|
end
|
259
259
|
|
260
|
-
it '
|
260
|
+
it 'formats class methods properly' do
|
261
261
|
# spec 1
|
262
262
|
out = @ap.awesome(User.methods.grep(/first/))
|
263
263
|
|
@@ -274,7 +274,7 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
274
274
|
expect(out).to match(
|
275
275
|
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
|
276
276
|
)
|
277
|
-
elsif RUBY_VERSION >= '2.7
|
277
|
+
elsif RUBY_VERSION >= '2.6.7'
|
278
278
|
expect(out).to match(
|
279
279
|
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
|
280
280
|
)
|
@@ -297,12 +297,14 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
297
297
|
)
|
298
298
|
elsif RUBY_VERSION >= '3.0.0'
|
299
299
|
expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:User> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
300
|
-
elsif RUBY_VERSION
|
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/)
|
304
|
+
elsif RUBY_VERSION >= '2.7.0'
|
301
305
|
expect(out).to match(
|
302
306
|
/\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
|
303
307
|
)
|
304
|
-
elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
|
305
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
|
306
308
|
else
|
307
309
|
expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
308
310
|
end
|
@@ -312,20 +314,18 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
|
|
312
314
|
|
313
315
|
if ActiveRecord::VERSION::MAJOR < 3
|
314
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/)
|
315
327
|
else
|
316
|
-
|
317
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
|
318
|
-
elsif RUBY_VERSION >= '3.0.0'
|
319
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:User> \(ActiveModel::Validations::ClassMethods\)/)
|
320
|
-
elsif RUBY_VERSION =~ /2\.7\.(0|1)/
|
321
|
-
expect(out).to match(
|
322
|
-
/\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
|
323
|
-
)
|
324
|
-
elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
|
325
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
|
326
|
-
else
|
327
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
|
328
|
-
end
|
328
|
+
expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
|
329
329
|
end
|
330
330
|
end
|
331
331
|
end
|
@@ -15,21 +15,21 @@ RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails?
|
|
15
15
|
@ap = AmazingPrint::Inspector.new
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'formats ActiveSupport::TimeWithZone as regular Time' do
|
19
19
|
Time.zone = 'Eastern Time (US & Canada)'
|
20
20
|
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
21
21
|
expect(@ap.send(:awesome, time))
|
22
22
|
.to eq("\e[0;32mSat, 10 Feb 2007 #{expected_ar_time_str} EST -05:00\e[0m")
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'formats HashWithIndifferentAccess as regular Hash' do
|
26
26
|
hash = HashWithIndifferentAccess.new({ hello: 'world' })
|
27
27
|
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\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
|
31
31
|
# we ignore that and format Date instance as regular date.
|
32
|
-
it '
|
32
|
+
it 'formates Date object as date' do
|
33
33
|
date = Date.new(2003, 5, 26)
|
34
34
|
expect(date.ai(plain: true)).to eq('Mon, 26 May 2003')
|
35
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,11 +29,11 @@ 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 '
|
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
|
-
.gsub(
|
36
|
+
.gsub(/#<Proc:.+?>/, 'amazing_print_PROC_STUB')
|
35
37
|
.gsub(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
36
38
|
|
37
39
|
str = if MongoMapper::Version >= '0.13'
|
@@ -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 '
|
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 '
|
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 '
|
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 '
|
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
|
206
|
+
before do
|
205
207
|
@ap = AmazingPrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true })
|
206
208
|
end
|
207
209
|
|
208
|
-
it '
|
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 '
|
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
|
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 '
|
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
|
data/spec/ext/mongoid_spec.rb
CHANGED
@@ -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 '
|
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 '
|
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 '
|
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
|
data/spec/ext/nobrainer_spec.rb
CHANGED
@@ -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 '
|
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 '
|
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
|
data/spec/ext/nokogiri_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe 'AmazingPrint/Nokogiri' do
|
6
|
-
it '
|
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 '
|
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 '
|
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")
|