amazing_print 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95f05f3413c3497f346ec0bb7de2ed94a065aa6224a0a6bc8b36c699728ea4b2
4
- data.tar.gz: 112760cadb1e3b76240163a64a462323975e5885ea0e002845790d75fb0c6858
3
+ metadata.gz: 5d771d603c88c997bca4379eba3dc4cd794994e5810edb0859ad5c47c3b2590c
4
+ data.tar.gz: 87ea8f90780f57731ad4cff0bfbce9eb2d837681829979bd23e839f62415a1b0
5
5
  SHA512:
6
- metadata.gz: 2f2e2fddf5cbf25953721ab0bc8f0ff0648fbe93710508137af6022ef5b8c5153be9292cbea2910fe4ef8b434c2a3510585f2ef5e98097296f78e0c74f292140
7
- data.tar.gz: 0b2e88771d4c2835e586a5ccf5c3c6e8822267475a65ddd80faf5908e526b099ea888953395fb77047df776ba7f6e7e63cf8bf50cb7676b253b2c67987b1437c
6
+ metadata.gz: d1d1d0eb8ca306adbf3af3eec93d9cbb3fa6a47f1ad0e3b836d473bc4a0595be02dcd27af60de86a3f524bb373e5e0d2b9053f6b40dfac437add803dc075a315
7
+ data.tar.gz: 3c74f2a0333fad6e5c34b5209124767b931d56c88423960f55945b694e27dadd41636259f7a1a395e64d4971887c2d1f095b64714acd525748dae5423d670872
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Unreleased
2
2
 
3
+ ## v1.5.0
4
+ - Drop support for Ruby 2.3 and 2.4 as well as JRuby 9.1
5
+ - Add File/Dir formatters for mswin platform #48
6
+ - Don't monkey patch String class #91
7
+ - Fix ruby19 hash syntax so it can be copy-pasted #94
8
+
3
9
  ## v1.4.0
4
10
  - Support loading config from `$XDG_CONFIG_HOME/aprc` - #63
5
11
  - Remove support for Rails 5.1 #75
data/Gemfile CHANGED
@@ -4,3 +4,12 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in amazing_print.gemspec
6
6
  gemspec
7
+
8
+ # Development dependencies
9
+ gem 'appraisal', '~> 2.3'
10
+ gem 'fakefs', '~> 1.2'
11
+ gem 'nokogiri', '~> 1.10'
12
+ gem 'pry'
13
+ gem 'rspec', '~> 3.9'
14
+ gem 'rubocop', '~> 1.20'
15
+ gem 'rubocop-rspec', '~> 2.4'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amazing_print (1.3.1.pre)
4
+ amazing_print (1.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,56 +12,62 @@ GEM
12
12
  thor (>= 0.14.0)
13
13
  ast (2.4.2)
14
14
  coderay (1.1.3)
15
- diff-lcs (1.4.4)
16
- fakefs (1.3.2)
15
+ diff-lcs (1.5.0)
16
+ fakefs (1.9.0)
17
+ json (2.6.3)
17
18
  method_source (1.0.0)
18
- mini_portile2 (2.6.1)
19
- nokogiri (1.12.5)
20
- mini_portile2 (~> 2.6.1)
19
+ nokogiri (1.15.2-x86_64-linux)
21
20
  racc (~> 1.4)
22
- parallel (1.21.0)
23
- parser (3.0.2.0)
21
+ parallel (1.23.0)
22
+ parser (3.2.2.1)
24
23
  ast (~> 2.4.1)
25
- pry (0.14.1)
24
+ pry (0.14.2)
26
25
  coderay (~> 1.1)
27
26
  method_source (~> 1.0)
28
- racc (1.5.2)
29
- rainbow (3.0.0)
27
+ racc (1.6.2)
28
+ rainbow (3.1.1)
30
29
  rake (13.0.6)
31
- regexp_parser (2.1.1)
30
+ regexp_parser (2.8.0)
32
31
  rexml (3.2.5)
33
- rspec (3.10.0)
34
- rspec-core (~> 3.10.0)
35
- rspec-expectations (~> 3.10.0)
36
- rspec-mocks (~> 3.10.0)
37
- rspec-core (3.10.1)
38
- rspec-support (~> 3.10.0)
39
- rspec-expectations (3.10.1)
32
+ rspec (3.12.0)
33
+ rspec-core (~> 3.12.0)
34
+ rspec-expectations (~> 3.12.0)
35
+ rspec-mocks (~> 3.12.0)
36
+ rspec-core (3.12.2)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-expectations (3.12.3)
40
39
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.10.0)
42
- rspec-mocks (3.10.2)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-mocks (3.12.5)
43
42
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-support (3.10.2)
46
- rubocop (1.22.1)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.0)
45
+ rubocop (1.51.0)
46
+ json (~> 2.3)
47
47
  parallel (~> 1.10)
48
- parser (>= 3.0.0.0)
48
+ parser (>= 3.2.0.0)
49
49
  rainbow (>= 2.2.2, < 4.0)
50
50
  regexp_parser (>= 1.8, < 3.0)
51
- rexml
52
- rubocop-ast (>= 1.12.0, < 2.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.28.0, < 2.0)
53
53
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.12.0)
56
- parser (>= 3.0.1.1)
57
- rubocop-rspec (2.5.0)
58
- rubocop (~> 1.19)
59
- ruby-progressbar (1.11.0)
60
- thor (1.1.0)
61
- unicode-display_width (2.1.0)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.28.1)
56
+ parser (>= 3.2.1.0)
57
+ rubocop-capybara (2.18.0)
58
+ rubocop (~> 1.41)
59
+ rubocop-factory_bot (2.23.1)
60
+ rubocop (~> 1.33)
61
+ rubocop-rspec (2.22.0)
62
+ rubocop (~> 1.33)
63
+ rubocop-capybara (~> 2.17)
64
+ rubocop-factory_bot (~> 2.22)
65
+ ruby-progressbar (1.13.0)
66
+ thor (1.2.2)
67
+ unicode-display_width (2.4.2)
62
68
 
63
69
  PLATFORMS
64
- ruby
70
+ x86_64-linux
65
71
 
66
72
  DEPENDENCIES
67
73
  amazing_print!
@@ -74,4 +80,4 @@ DEPENDENCIES
74
80
  rubocop-rspec (~> 2.4)
75
81
 
76
82
  BUNDLED WITH
77
- 2.2.27
83
+ 2.3.12
data/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  [![RubyGems][gem_version_badge]][ruby_gems]
4
4
  [![RubyGems][gem_downloads_badge]][ruby_gems]
5
5
  |
6
- [![Travis CI][travis_ci_badge]][travis_ci]
7
6
  ![Specs](https://github.com/amazing-print/amazing_print/workflows/Specs/badge.svg)
8
- ![Lint](https://github.com/amazing-print/amazing_print/workflows/Lint/badge.svg)
7
+ ![Lint](https://github.com/amazing-print/amazing_print/workflows/Lints/badge.svg)
9
8
  |
10
9
  [![Gitter](https://badges.gitter.im/amazing-print/community.svg)](https://gitter.im/amazing-print/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
11
10
 
@@ -2,24 +2,17 @@
2
2
 
3
3
  autoload :CGI, 'cgi'
4
4
 
5
+ require_relative 'colors'
6
+
5
7
  module AmazingPrint
6
8
  module Colorize
7
9
  # Pick the color and apply it to the given string as necessary.
8
10
  #------------------------------------------------------------------------------
9
11
  def colorize(str, type)
10
12
  str = CGI.escapeHTML(str) if options[:html]
11
- if options[:plain] || !options[:color][type] || !inspector.colorize?
12
- str
13
- #
14
- # Check if the string color method is defined by amazing_print and accepts
15
- # html parameter or it has been overriden by some gem such as colorize.
16
- #
17
- elsif str.method(options[:color][type]).arity == -1 # Accepts html parameter.
18
- str.send(options[:color][type], options[:html])
19
- else
20
- str = %(<kbd style="color:#{options[:color][type]}">#{str}</kbd>) if options[:html]
21
- str.send(options[:color][type])
22
- end
13
+ return str if options[:plain] || !options[:color][type] || !inspector.colorize?
14
+
15
+ AmazingPrint::Colors.public_send(options[:color][type], str, options[:html])
23
16
  end
24
17
  end
25
18
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmazingPrint
4
+ module Colors
5
+ module_function
6
+
7
+ #
8
+ # ANSI color codes:
9
+ # \e => escape
10
+ # 30 => color base
11
+ # 1 => bright
12
+ # 0 => normal
13
+ #
14
+ # For HTML coloring we use <kbd> tag instead of <span> to require monospace
15
+ # font. Note that beloved <tt> has been removed from HTML5.
16
+ #
17
+ %w[gray red green yellow blue purple cyan white].zip(
18
+ %w[black darkred darkgreen brown navy darkmagenta darkcyan slategray]
19
+ ).each_with_index do |(color, shade), i|
20
+ # NOTE: Format strings are created once only, for performance, and remembered by closures.
21
+
22
+ term_bright_seq = "\e[1;#{i + 30}m%s\e[0m"
23
+ html_bright_seq = %(<kbd style="color:#{color}">%s</kbd>)
24
+
25
+ define_method color do |str, html = false|
26
+ (html ? html_bright_seq : term_bright_seq) % str
27
+ end
28
+
29
+ term_normal_seq = "\e[0;#{i + 30}m%s\e[0m"
30
+ html_normal_seq = %(<kbd style="color:#{shade}">%s</kbd>)
31
+
32
+ define_method "#{color}ish" do |str, html = false|
33
+ (html ? html_normal_seq : term_normal_seq) % str
34
+ end
35
+ end
36
+ end
37
+ end
@@ -15,7 +15,7 @@ module AmazingPrint
15
15
  end
16
16
 
17
17
  def format
18
- if array.length.zero?
18
+ if array.empty?
19
19
  '[]'
20
20
  elsif methods_array?
21
21
  methods_array
@@ -3,6 +3,7 @@
3
3
  require 'shellwords'
4
4
 
5
5
  require_relative 'base_formatter'
6
+ require_relative 'mswin_helper' if RUBY_PLATFORM.include?('mswin')
6
7
 
7
8
  module AmazingPrint
8
9
  module Formatters
@@ -17,9 +18,17 @@ module AmazingPrint
17
18
  end
18
19
 
19
20
  def format
20
- ls = `ls -alF #{dir.path.shellescape}`
21
+ ls = info
21
22
  colorize(ls.empty? ? dir.inspect : "#{dir.inspect}\n#{ls.chop}", :dir)
22
23
  end
24
+
25
+ def info
26
+ if RUBY_PLATFORM.include?('mswin')
27
+ "#{GetChildItem.new(@dir.path)}\n"
28
+ else
29
+ `ls -alF #{dir.path.shellescape}`
30
+ end
31
+ end
23
32
  end
24
33
  end
25
34
  end
@@ -3,6 +3,7 @@
3
3
  require 'shellwords'
4
4
 
5
5
  require_relative 'base_formatter'
6
+ require_relative 'mswin_helper' if RUBY_PLATFORM.include?('mswin')
6
7
 
7
8
  module AmazingPrint
8
9
  module Formatters
@@ -17,9 +18,17 @@ module AmazingPrint
17
18
  end
18
19
 
19
20
  def format
20
- ls = File.directory?(file) ? `ls -adlF #{file.path.shellescape}` : `ls -alF #{file.path.shellescape}`
21
+ ls = info
21
22
  colorize(ls.empty? ? file.inspect : "#{file.inspect}\n#{ls.chop}", :file)
22
23
  end
24
+
25
+ def info
26
+ if RUBY_PLATFORM.include?('mswin')
27
+ "#{GetChildItem.new(@file.path)}\n"
28
+ else
29
+ File.directory?(file) ? `ls -adlF #{file.path.shellescape}` : `ls -alF #{file.path.shellescape}`
30
+ end
31
+ end
23
32
  end
24
33
  end
25
34
  end
@@ -87,7 +87,8 @@ module AmazingPrint
87
87
 
88
88
  def ruby19_syntax(key, value, width)
89
89
  key[0] = ''
90
- "#{align(key, width - 1)}#{colorize(': ', :hash)}#{inspector.awesome(value)}"
90
+ key << ':'
91
+ "#{align(key, width)} #{inspector.awesome(value)}"
91
92
  end
92
93
 
93
94
  def pre_ruby19_syntax(key, value, width)
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fiddle'
4
+ require 'fiddle/import'
5
+
6
+ module AmazingPrint
7
+ module Formatters
8
+ module Kernel32
9
+ extend Fiddle::Importer
10
+ dlload 'kernel32'
11
+ extern 'unsigned long GetFileAttributesA(const char*)'
12
+ end
13
+
14
+ class GetChildItem
15
+ def initialize(fname)
16
+ @fname = fname
17
+ @stat = File.send(File.symlink?(@fname) ? :lstat : :stat, @fname)
18
+ @attrs = Kernel32::GetFileAttributesA @fname
19
+ end
20
+
21
+ # docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
22
+ FILE_ATTRIBUTE_ARCHIVE = 0x20
23
+ FILE_ATTRIBUTE_READONLY = 0x1
24
+ FILE_ATTRIBUTE_HIDDEN = 0x2
25
+ FILE_ATTRIBUTE_SYSTEM = 0x4
26
+
27
+ def mode
28
+ r = ['-'] * 6
29
+ r[0] = 'd' if @stat.directory?
30
+ r[1] = 'a' unless (@attrs & FILE_ATTRIBUTE_ARCHIVE).zero?
31
+ r[2] = 'r' unless (@attrs & FILE_ATTRIBUTE_READONLY).zero?
32
+ r[3] = 'h' unless (@attrs & FILE_ATTRIBUTE_HIDDEN).zero?
33
+ r[4] = 's' unless (@attrs & FILE_ATTRIBUTE_SYSTEM).zero?
34
+ r[5] = 'l' if File.symlink? @fname
35
+ r.join
36
+ end
37
+
38
+ def last_write_time
39
+ @stat.mtime.strftime '%Y-%m-%d %H:%M'
40
+ end
41
+
42
+ def length
43
+ @stat.file? ? @stat.size.to_s : ''
44
+ end
45
+
46
+ def name
47
+ @fname
48
+ end
49
+
50
+ def to_s
51
+ format '%-12<Mode>s %<LastWriteTime>s %14<Length>s %<Name>s',
52
+ {
53
+ Mode: mode,
54
+ LastWriteTime: last_write_time,
55
+ Length: length,
56
+ Name: name
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ puts AmazingPrint::Formatters::GetChildItem.new ARGV[0] if __FILE__ == $PROGRAM_NAME
@@ -166,7 +166,7 @@ module AmazingPrint
166
166
  return xdg_config_path if File.exist?(xdg_config_path)
167
167
 
168
168
  # default to ~/.aprc
169
- File.join(ENV['HOME'], '.aprc')
169
+ File.join(Dir.home, '.aprc')
170
170
  end
171
171
 
172
172
  # This method needs to be mocked during testing so that it always loads
@@ -7,6 +7,6 @@
7
7
  #------------------------------------------------------------------------------
8
8
  module AmazingPrint
9
9
  def self.version
10
- '1.4.0'
10
+ '1.5.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
 
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
+ "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
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
@@ -139,21 +125,13 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
139
125
  elsif activerecord_5_0?
140
126
  ActiveRecordData.raw_5_0_diana
141
127
  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
128
+ ActiveRecordData.raw_4_2_diana
147
129
  elsif activerecord_4_1?
148
130
  ActiveRecordData.raw_4_1_diana
149
131
  elsif activerecord_4_0?
150
132
  ActiveRecordData.raw_4_0_diana
151
133
  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
134
+ ActiveRecordData.raw_3_2_diana
157
135
  end
158
136
 
159
137
  if RUBY_PLATFORM == 'java' && !activerecord_6_1?
@@ -181,21 +159,13 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
181
159
  elsif activerecord_5_0?
182
160
  ActiveRecordData.raw_5_0_multi
183
161
  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
162
+ ActiveRecordData.raw_4_2_multi
189
163
  elsif activerecord_4_1?
190
164
  ActiveRecordData.raw_4_1_multi
191
165
  elsif activerecord_4_0?
192
166
  ActiveRecordData.raw_4_0_multi
193
167
  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
168
+ ActiveRecordData.raw_3_2_multi
199
169
  end
200
170
 
201
171
  if RUBY_PLATFORM == 'java' && !activerecord_6_1?
@@ -266,24 +236,24 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
266
236
  expect(out).to match(
267
237
  /\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
268
238
  )
269
- elsif RUBY_VERSION >= '3.0.0'
239
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
240
+ expect(out).to match(
241
+ /\s*first\(\*(\*|args),\s+\?,\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
242
+ )
243
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
270
244
  expect(out).to match(
271
245
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
272
246
  )
273
- elsif RUBY_VERSION >= '2.7.2'
247
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
274
248
  expect(out).to match(
275
249
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
276
250
  )
277
- elsif RUBY_VERSION >= '2.6.7'
251
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7')
278
252
  expect(out).to match(
279
253
  /\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
280
254
  )
281
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./
255
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4')
282
256
  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
257
  end
288
258
  else
289
259
  expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
@@ -295,18 +265,16 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
295
265
  expect(out).to match(
296
266
  /\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
297
267
  )
298
- elsif RUBY_VERSION >= '3.0.0'
268
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
299
269
  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'
270
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
301
271
  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'
272
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
303
273
  expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
304
- elsif RUBY_VERSION >= '2.7.0'
274
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
305
275
  expect(out).to match(
306
276
  /\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
307
277
  )
308
- else
309
- expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
310
278
  end
311
279
 
312
280
  # spec 3
@@ -316,16 +284,14 @@ RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }
316
284
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
317
285
  elsif RUBY_PLATFORM == 'java'
318
286
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
319
- elsif RUBY_VERSION >= '3.0.0'
287
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
320
288
  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')
289
+ elsif (Gem::Version.new('2.6.7')..Gem::Version.new('2.7.1')).cover? Gem::Version.new(RUBY_VERSION)
322
290
  expect(out).to match(
323
291
  /\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
324
292
  )
325
- elsif RUBY_VERSION =~ /^2\.4\.([4-9]|[1-9][0-9])|^2\.[56]\./ || RUBY_VERSION >= '2.7.2'
293
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
326
294
  expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
327
- else
328
- expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
329
295
  end
330
296
  end
331
297
  end
@@ -8,7 +8,7 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
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")
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
@@ -34,11 +34,11 @@ RSpec.describe 'AmazingPrint/Nokogiri' do
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")
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