amazing_print 1.6.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -2
- data/lib/amazing_print/ext/active_record.rb +32 -2
- data/lib/amazing_print/ext/nobrainer.rb +2 -2
- data/lib/amazing_print/formatters/base_formatter.rb +5 -1
- data/lib/amazing_print/formatters/hash_formatter.rb +29 -9
- data/lib/amazing_print/formatters/mswin_helper.rb +4 -4
- data/lib/amazing_print/formatters/object_formatter.rb +1 -1
- data/lib/amazing_print/formatters/struct_formatter.rb +1 -1
- data/lib/amazing_print/inspector.rb +1 -1
- data/lib/amazing_print/version.rb +1 -1
- metadata +6 -63
- data/.gitignore +0 -35
- data/Appraisals +0 -66
- data/Gemfile +0 -18
- data/Gemfile.lock +0 -94
- data/LICENSE +0 -22
- data/Rakefile +0 -25
- data/spec/active_record_helper.rb +0 -43
- data/spec/colors_spec.rb +0 -120
- data/spec/core_ext/logger_spec.rb +0 -70
- data/spec/ext/action_controller_spec.rb +0 -40
- data/spec/ext/action_view_spec.rb +0 -24
- data/spec/ext/active_model_spec.rb +0 -37
- data/spec/ext/active_record_spec.rb +0 -302
- data/spec/ext/active_support_spec.rb +0 -37
- data/spec/ext/mongo_mapper_spec.rb +0 -265
- data/spec/ext/mongoid_spec.rb +0 -135
- data/spec/ext/nobrainer_spec.rb +0 -64
- data/spec/ext/nokogiri_spec.rb +0 -52
- data/spec/ext/ostruct_spec.rb +0 -24
- data/spec/ext/ripple_spec.rb +0 -53
- data/spec/ext/sequel_spec.rb +0 -45
- data/spec/formats_spec.rb +0 -795
- data/spec/methods_spec.rb +0 -520
- data/spec/misc_spec.rb +0 -206
- data/spec/objects_spec.rb +0 -225
- data/spec/sequel_helper.rb +0 -18
- data/spec/spec_helper.rb +0 -112
- data/spec/support/active_record_data/3_2_diana.txt +0 -24
- data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
- data/spec/support/active_record_data/3_2_multi.txt +0 -50
- data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
- data/spec/support/active_record_data/4_0_diana.txt +0 -98
- data/spec/support/active_record_data/4_0_multi.txt +0 -198
- data/spec/support/active_record_data/4_1_diana.txt +0 -97
- data/spec/support/active_record_data/4_1_multi.txt +0 -196
- data/spec/support/active_record_data/4_2_diana.txt +0 -109
- data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
- data/spec/support/active_record_data/4_2_multi.txt +0 -220
- data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
- data/spec/support/active_record_data/5_0_diana.txt +0 -105
- data/spec/support/active_record_data/5_0_multi.txt +0 -212
- data/spec/support/active_record_data/5_1_diana.txt +0 -104
- data/spec/support/active_record_data/5_1_multi.txt +0 -210
- data/spec/support/active_record_data/5_2_diana.txt +0 -104
- data/spec/support/active_record_data/5_2_multi.txt +0 -210
- data/spec/support/active_record_data/6_0_diana.txt +0 -104
- data/spec/support/active_record_data/6_0_multi.txt +0 -210
- data/spec/support/active_record_data/6_1_diana.txt +0 -109
- data/spec/support/active_record_data/6_1_multi.txt +0 -220
- data/spec/support/active_record_data/7_0_diana.txt +0 -110
- data/spec/support/active_record_data/7_0_multi.txt +0 -222
- data/spec/support/active_record_data.rb +0 -22
- data/spec/support/ext_verifier.rb +0 -46
- data/spec/support/mongoid_versions.rb +0 -24
- data/spec/support/rails_versions.rb +0 -62
data/spec/colors_spec.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
RSpec.describe 'AmazingPrint' do
|
8
|
-
def stub_tty!(output = true, stream = $stdout)
|
9
|
-
if output
|
10
|
-
stream.instance_eval do
|
11
|
-
def tty?
|
12
|
-
true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
else
|
16
|
-
stream.instance_eval do
|
17
|
-
def tty?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'colorization' do
|
25
|
-
PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
|
26
|
-
COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
|
27
|
-
|
28
|
-
before do
|
29
|
-
ENV['TERM'] = 'xterm-colors'
|
30
|
-
ENV.delete('ANSICON')
|
31
|
-
@arr = [1, :two, 'three', [nil, [true, false]]]
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'default settings (no forced colors)' do
|
35
|
-
before do
|
36
|
-
AmazingPrint.force_colors! colors: false
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'colorizes tty processes by default' do
|
40
|
-
stub_tty!
|
41
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "colorizes processes with ENV['ANSICON'] by default" do
|
45
|
-
stub_tty!
|
46
|
-
term = ENV['ANSICON']
|
47
|
-
ENV['ANSICON'] = '1'
|
48
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
49
|
-
ensure
|
50
|
-
ENV['ANSICON'] = term
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'does not colorize tty processes running in dumb terminals by default' do
|
54
|
-
stub_tty!
|
55
|
-
term = ENV['TERM']
|
56
|
-
ENV['TERM'] = 'dumb'
|
57
|
-
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
58
|
-
ensure
|
59
|
-
ENV['TERM'] = term
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does not colorize subprocesses by default' do
|
63
|
-
stub_tty! false
|
64
|
-
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
65
|
-
ensure
|
66
|
-
stub_tty!
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'forced colors override' do
|
71
|
-
before do
|
72
|
-
AmazingPrint.force_colors!
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'still colorizes tty processes' do
|
76
|
-
stub_tty!
|
77
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
81
|
-
stub_tty!
|
82
|
-
term = ENV['ANSICON']
|
83
|
-
ENV['ANSICON'] = '1'
|
84
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
85
|
-
ensure
|
86
|
-
ENV['ANSICON'] = term
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'colorizes dumb terminals' do
|
90
|
-
stub_tty!
|
91
|
-
term = ENV['TERM']
|
92
|
-
ENV['TERM'] = 'dumb'
|
93
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
94
|
-
ensure
|
95
|
-
ENV['TERM'] = term
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'colorizes subprocess' do
|
99
|
-
stub_tty! false
|
100
|
-
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
101
|
-
ensure
|
102
|
-
stub_tty!
|
103
|
-
end
|
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
|
112
|
-
|
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")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock, Style/OptionalBooleanParameter
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'logger'
|
6
|
-
require 'amazing_print/core_ext/logger'
|
7
|
-
|
8
|
-
RSpec.describe 'AmazingPrint logging extensions' do
|
9
|
-
subject(:logger) do
|
10
|
-
Logger.new('/dev/null')
|
11
|
-
rescue Errno::ENOENT
|
12
|
-
Logger.new('nul')
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:object) { double }
|
16
|
-
let(:options) { { sort_keys: true } }
|
17
|
-
|
18
|
-
describe 'ap method' do
|
19
|
-
it 'awesome_inspects the given object' do
|
20
|
-
expect(object).to receive(:ai)
|
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
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'the log level' do
|
30
|
-
before do
|
31
|
-
AmazingPrint.defaults = {}
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'fallbacks to the default :debug log level' do
|
35
|
-
expect(logger).to receive(:debug)
|
36
|
-
logger.ap nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses the global user default if no level passed' do
|
40
|
-
AmazingPrint.defaults = { log_level: :info }
|
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 }
|
53
|
-
end
|
54
|
-
|
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
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'AmazingPrint::ActionController', skip: -> { !ExtVerifier.has_rails? }.call do
|
6
|
-
let(:inspector) { AmazingPrint::Inspector.new }
|
7
|
-
|
8
|
-
context 'with unpermitted ActionController::Parameters' do
|
9
|
-
let(:parameters) do
|
10
|
-
ActionController::Parameters.new post: { id: 1, content: 'Some' }
|
11
|
-
end
|
12
|
-
|
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
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with permitted ActionController::Parameters' do
|
21
|
-
let(:expected_output) do
|
22
|
-
<<~OUTPUT
|
23
|
-
{
|
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
|
-
}
|
28
|
-
}
|
29
|
-
OUTPUT
|
30
|
-
.chomp
|
31
|
-
end
|
32
|
-
let(:parameters) do
|
33
|
-
ActionController::Parameters.new post: { id: 1, content: 'Some' }
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'formats as a hash' do
|
37
|
-
expect(inspector.send(:awesome, parameters.permit!)).to eq expected_output
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'AmazingPrint ActionView extensions',
|
6
|
-
skip: -> { !ExtVerifier.has_rails? || ActiveRecord::VERSION::STRING >= '6.1' }.call do
|
7
|
-
before do
|
8
|
-
@view = ActionView::Base.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
|
12
|
-
markup = rand
|
13
|
-
expect(@view.ap(markup, plain: true)).to eq(%(<pre class="debug_dump">#{markup}</pre>))
|
14
|
-
end
|
15
|
-
|
16
|
-
it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
|
17
|
-
markup = ' &<hello>'
|
18
|
-
expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
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
|
24
|
-
end
|
@@ -1,37 +0,0 @@
|
|
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
|
@@ -1,302 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'active_record_helper'
|
5
|
-
|
6
|
-
RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do
|
7
|
-
describe 'ActiveRecord instance, attributes only (default)' do
|
8
|
-
before do
|
9
|
-
ActiveRecord::Base.default_timezone = :utc
|
10
|
-
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
11
|
-
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
12
|
-
@ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'display single record' do
|
16
|
-
out = @ap.awesome(@diana)
|
17
|
-
str = <<~EOS.strip
|
18
|
-
#<User:placeholder_id> {
|
19
|
-
:admin => false,
|
20
|
-
:created_at => ?,
|
21
|
-
:id => nil,
|
22
|
-
:name => "Diana",
|
23
|
-
:rank => 1
|
24
|
-
}
|
25
|
-
EOS
|
26
|
-
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
27
|
-
expect(out).to be_similar_to(str)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'display multiple records' do
|
31
|
-
out = @ap.awesome([@diana, @laura])
|
32
|
-
str = <<~EOS.strip
|
33
|
-
[
|
34
|
-
[0] #<User:placeholder_id> {
|
35
|
-
:admin => false,
|
36
|
-
:created_at => ??,
|
37
|
-
:id => nil,
|
38
|
-
:name => "Diana",
|
39
|
-
:rank => 1
|
40
|
-
},
|
41
|
-
[1] #<User:placeholder_id> {
|
42
|
-
:admin => true,
|
43
|
-
:created_at => ?!,
|
44
|
-
:id => nil,
|
45
|
-
:name => "Laura",
|
46
|
-
:rank => 2
|
47
|
-
}
|
48
|
-
]
|
49
|
-
EOS
|
50
|
-
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
51
|
-
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
52
|
-
expect(out).to be_similar_to(str)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'display multiple records on a relation' do
|
56
|
-
@diana.save
|
57
|
-
@laura.save
|
58
|
-
out = @ap.awesome(User.all)
|
59
|
-
str = <<~EOS.strip
|
60
|
-
[
|
61
|
-
[0] #<User:placeholder_id> {
|
62
|
-
:admin => false,
|
63
|
-
:created_at => ??,
|
64
|
-
:id => 1,
|
65
|
-
:name => "Diana",
|
66
|
-
:rank => 1
|
67
|
-
},
|
68
|
-
[1] #<User:placeholder_id> {
|
69
|
-
:admin => true,
|
70
|
-
:created_at => ?!,
|
71
|
-
:id => 2,
|
72
|
-
:name => "Laura",
|
73
|
-
:rank => 2
|
74
|
-
}
|
75
|
-
]
|
76
|
-
EOS
|
77
|
-
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
78
|
-
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
79
|
-
expect(out).to be_similar_to(str)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe 'Linked records (joins)' do
|
84
|
-
before do
|
85
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'shows the entire record' do
|
89
|
-
e = Email.create(email_address: 'foo@bar.com')
|
90
|
-
u = User.last
|
91
|
-
u.emails << e
|
92
|
-
email_record = User.joins(:emails).select('users.id, emails.email_address').last
|
93
|
-
out = @ap.awesome(email_record)
|
94
|
-
raw_object_string = <<~EOS.strip
|
95
|
-
#<User:placeholder_id> {
|
96
|
-
"id" => #{u.id},
|
97
|
-
"email_address" => "#{e.email_address}"
|
98
|
-
}
|
99
|
-
EOS
|
100
|
-
expect(out).to be_similar_to(raw_object_string)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
#------------------------------------------------------------------------------
|
105
|
-
describe 'ActiveRecord instance (raw)' do
|
106
|
-
before do
|
107
|
-
ActiveRecord::Base.default_timezone = :utc
|
108
|
-
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
109
|
-
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
110
|
-
@ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true, raw: true)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'display single record' do
|
114
|
-
out = @ap.awesome(@diana)
|
115
|
-
|
116
|
-
raw_object_string =
|
117
|
-
if activerecord_7_0?
|
118
|
-
ActiveRecordData.raw_7_0_diana
|
119
|
-
elsif activerecord_6_1?
|
120
|
-
ActiveRecordData.raw_6_1_diana
|
121
|
-
elsif activerecord_6_0?
|
122
|
-
ActiveRecordData.raw_6_0_diana
|
123
|
-
elsif activerecord_5_2?
|
124
|
-
ActiveRecordData.raw_5_2_diana
|
125
|
-
elsif activerecord_5_1?
|
126
|
-
ActiveRecordData.raw_5_1_diana
|
127
|
-
elsif activerecord_5_0?
|
128
|
-
ActiveRecordData.raw_5_0_diana
|
129
|
-
elsif activerecord_4_2?
|
130
|
-
ActiveRecordData.raw_4_2_diana
|
131
|
-
elsif activerecord_4_1?
|
132
|
-
ActiveRecordData.raw_4_1_diana
|
133
|
-
elsif activerecord_4_0?
|
134
|
-
ActiveRecordData.raw_4_0_diana
|
135
|
-
elsif activerecord_3_2?
|
136
|
-
ActiveRecordData.raw_3_2_diana
|
137
|
-
end
|
138
|
-
|
139
|
-
if RUBY_PLATFORM == 'java' && !activerecord_6_1?
|
140
|
-
raw_object_string.gsub!(
|
141
|
-
'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
|
142
|
-
'ArJdbc::SQLite3::SQLite3Integer'
|
143
|
-
)
|
144
|
-
end
|
145
|
-
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
146
|
-
expect(out).to be_similar_to(raw_object_string)
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'display multiple records' do
|
150
|
-
out = @ap.awesome([@diana, @laura])
|
151
|
-
|
152
|
-
raw_object_string =
|
153
|
-
if activerecord_7_0?
|
154
|
-
ActiveRecordData.raw_7_0_multi
|
155
|
-
elsif activerecord_6_1?
|
156
|
-
ActiveRecordData.raw_6_1_multi
|
157
|
-
elsif activerecord_6_0?
|
158
|
-
ActiveRecordData.raw_6_0_multi
|
159
|
-
elsif activerecord_5_2?
|
160
|
-
ActiveRecordData.raw_5_2_multi
|
161
|
-
elsif activerecord_5_1?
|
162
|
-
ActiveRecordData.raw_5_1_multi
|
163
|
-
elsif activerecord_5_0?
|
164
|
-
ActiveRecordData.raw_5_0_multi
|
165
|
-
elsif activerecord_4_2?
|
166
|
-
ActiveRecordData.raw_4_2_multi
|
167
|
-
elsif activerecord_4_1?
|
168
|
-
ActiveRecordData.raw_4_1_multi
|
169
|
-
elsif activerecord_4_0?
|
170
|
-
ActiveRecordData.raw_4_0_multi
|
171
|
-
elsif activerecord_3_2?
|
172
|
-
ActiveRecordData.raw_3_2_multi
|
173
|
-
end
|
174
|
-
|
175
|
-
if RUBY_PLATFORM == 'java' && !activerecord_6_1?
|
176
|
-
raw_object_string.gsub!(
|
177
|
-
'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
|
178
|
-
'ArJdbc::SQLite3::SQLite3Integer'
|
179
|
-
)
|
180
|
-
end
|
181
|
-
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
182
|
-
raw_object_string.sub!('?', '2003-05-26 14:15:00')
|
183
|
-
expect(out).to be_similar_to(raw_object_string)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
#------------------------------------------------------------------------------
|
188
|
-
describe 'ActiveRecord class' do
|
189
|
-
before do
|
190
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'prints the class' do
|
194
|
-
expect(@ap.awesome(User)).to eq <<~EOS.strip
|
195
|
-
class User < ActiveRecord::Base {
|
196
|
-
:id => :integer,
|
197
|
-
:name => :string,
|
198
|
-
:rank => :integer,
|
199
|
-
:admin => :boolean,
|
200
|
-
:created_at => :datetime
|
201
|
-
}
|
202
|
-
EOS
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'prints the class for non-direct subclasses of ActiveRecord::Base' do
|
206
|
-
out = @ap.awesome(SubUser)
|
207
|
-
expect(out).to eq <<~EOS.strip
|
208
|
-
class SubUser < User {
|
209
|
-
:id => :integer,
|
210
|
-
:name => :string,
|
211
|
-
:rank => :integer,
|
212
|
-
:admin => :boolean,
|
213
|
-
:created_at => :datetime
|
214
|
-
}
|
215
|
-
EOS
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'prints ActiveRecord::Base objects (ex. ancestors)' do
|
219
|
-
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'prints valid HTML for subclasses' do
|
223
|
-
@ap = AmazingPrint::Inspector.new(html: true)
|
224
|
-
expect(@ap.awesome(SubUser)).to match('SubUser < User')
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
#------------------------------------------------------------------------------
|
229
|
-
describe 'ActiveRecord methods formatting' do
|
230
|
-
before do
|
231
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'formats class methods properly' do
|
235
|
-
# spec 1
|
236
|
-
out = @ap.awesome(User.methods.grep(/first/))
|
237
|
-
|
238
|
-
if ActiveRecord::VERSION::STRING >= '3.2'
|
239
|
-
if RUBY_PLATFORM == 'java'
|
240
|
-
expect(out).to match(
|
241
|
-
/\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
|
242
|
-
)
|
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')
|
248
|
-
expect(out).to match(
|
249
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
|
250
|
-
)
|
251
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
252
|
-
expect(out).to match(
|
253
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
|
254
|
-
)
|
255
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7')
|
256
|
-
expect(out).to match(
|
257
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
|
258
|
-
)
|
259
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4')
|
260
|
-
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
|
261
|
-
end
|
262
|
-
else
|
263
|
-
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
264
|
-
end
|
265
|
-
|
266
|
-
# spec 2
|
267
|
-
out = @ap.awesome(User.methods.grep(/primary_key/))
|
268
|
-
if RUBY_PLATFORM == 'java'
|
269
|
-
expect(out).to match(
|
270
|
-
/\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
|
271
|
-
)
|
272
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
273
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:User> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
274
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
|
275
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
276
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
277
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
|
278
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
279
|
-
expect(out).to match(
|
280
|
-
/\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
|
281
|
-
)
|
282
|
-
end
|
283
|
-
|
284
|
-
# spec 3
|
285
|
-
out = @ap.awesome(User.methods.grep(/validate/))
|
286
|
-
|
287
|
-
if ActiveRecord::VERSION::MAJOR < 3
|
288
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
289
|
-
elsif RUBY_PLATFORM == 'java'
|
290
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
|
291
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
292
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:User> \(ActiveModel::Validations::ClassMethods\)/)
|
293
|
-
elsif (Gem::Version.new('2.6.7')..Gem::Version.new('2.7.1')).cover? Gem::Version.new(RUBY_VERSION)
|
294
|
-
expect(out).to match(
|
295
|
-
/\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
|
296
|
-
)
|
297
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
298
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do
|
6
|
-
let(:expected_ar_time_str) do
|
7
|
-
if activerecord_6_1? || activerecord_7_0?
|
8
|
-
'15:30:45.000000000'
|
9
|
-
else
|
10
|
-
'15:30:45'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
@ap = AmazingPrint::Inspector.new
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'formats ActiveSupport::TimeWithZone as regular Time' do
|
19
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
20
|
-
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
21
|
-
expect(@ap.send(:awesome, time))
|
22
|
-
.to eq("\e[0;32mSat, 10 Feb 2007 #{expected_ar_time_str} EST -05:00\e[0m")
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'formats HashWithIndifferentAccess as regular Hash' do
|
26
|
-
hash = HashWithIndifferentAccess.new({ hello: 'world' })
|
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
|
-
end
|
29
|
-
|
30
|
-
# ActiveSupport sticks in instance variables to the date object. Make sure
|
31
|
-
# we ignore that and format Date instance as regular date.
|
32
|
-
it 'formates Date object as date' do
|
33
|
-
date = Date.new(2003, 5, 26)
|
34
|
-
expect(date.ai(plain: true)).to eq('Mon, 26 May 2003')
|
35
|
-
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
36
|
-
end
|
37
|
-
end
|