From 604693ddf9940b28b27b7d95a97870cb59664380 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 8 Jul 2023 21:56:57 +0900 Subject: [PATCH 1/3] Use each library version instead of `RUBY_VERSION` Fixes #1046 https://bugs.ruby-lang.org/issues/19762 --- library/bigdecimal/remainder_spec.rb | 2 +- library/bigdecimal/round_spec.rb | 4 ++-- library/bigdecimal/to_s_spec.rb | 9 +++++++-- library/date/deconstruct_keys_spec.rb | 2 +- library/date/strftime_spec.rb | 4 ++-- library/datetime/deconstruct_keys_spec.rb | 2 +- library/datetime/strftime_spec.rb | 4 ++-- library/erb/new_spec.rb | 2 +- library/ipaddr/new_spec.rb | 10 ++++++++-- library/stringio/shared/each.rb | 4 ++-- library/uri/generic/host_spec.rb | 2 +- library/uri/generic/to_s_spec.rb | 2 +- 12 files changed, 29 insertions(+), 18 deletions(-) diff --git a/library/bigdecimal/remainder_spec.rb b/library/bigdecimal/remainder_spec.rb index 35e131a0dc..bac5f37ba9 100644 --- a/library/bigdecimal/remainder_spec.rb +++ b/library/bigdecimal/remainder_spec.rb @@ -54,7 +54,7 @@ @nan.remainder(@infinity).should.nan? end - version_is BigDecimal::VERSION, ""..."3.1.4" do + version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do it "returns NaN if Infinity is involved" do @infinity.remainder(@infinity).should.nan? @infinity.remainder(@one).should.nan? diff --git a/library/bigdecimal/round_spec.rb b/library/bigdecimal/round_spec.rb index bfc6dbc763..fba52df65d 100644 --- a/library/bigdecimal/round_spec.rb +++ b/library/bigdecimal/round_spec.rb @@ -228,13 +228,13 @@ -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) end - ruby_version_is ''...'3.2' do + version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do it 'raise for a non-existent round mode' do -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") end end - ruby_version_is '3.2' do + version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do it 'raise for a non-existent round mode' do -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") end diff --git a/library/bigdecimal/to_s_spec.rb b/library/bigdecimal/to_s_spec.rb index 042c7779f4..e0bd649d52 100644 --- a/library/bigdecimal/to_s_spec.rb +++ b/library/bigdecimal/to_s_spec.rb @@ -39,20 +39,25 @@ @bigneg.to_s("+").should_not =~ /^\+.*/ end - it "inserts a space every n chars, if integer n is supplied" do + it "inserts a space every n chars to fraction part, if integer n is supplied" do re =\ /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i @bigdec.to_s(3).should =~ re str1 = '-123.45678 90123 45678 9' BigDecimal("-123.45678901234567890").to_s('5F').should == str1 - BigDecimal('1000010').to_s('5F').should == "10000 10.0" # trailing zeroes removed BigDecimal("1.00000000000").to_s('1F').should == "1.0" # 0 is treated as no spaces BigDecimal("1.2345").to_s('0F').should == "1.2345" end + version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do + it "inserts a space every n chars to integer part, if integer n is supplied" do + BigDecimal('1000010').to_s('5F').should == "10 00010.0" + end + end + it "can return a leading space for values > 0" do @bigdec.to_s(" F").should =~ /\ .*/ @bigneg.to_s(" F").should_not =~ /\ .*/ diff --git a/library/date/deconstruct_keys_spec.rb b/library/date/deconstruct_keys_spec.rb index fc9caaf332..94b528099f 100644 --- a/library/date/deconstruct_keys_spec.rb +++ b/library/date/deconstruct_keys_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require 'date' -ruby_version_is "3.2" do +version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do describe "Date#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = Date.new(2022, 10, 5) diff --git a/library/date/strftime_spec.rb b/library/date/strftime_spec.rb index 33ecc4ce9d..fc6c1dae8d 100644 --- a/library/date/strftime_spec.rb +++ b/library/date/strftime_spec.rb @@ -23,14 +23,14 @@ end # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do + version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-Apr-2000" @date.strftime("%v").should == @date.strftime('%e-%b-%Y') end end - ruby_version_is "3.1" do + version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-APR-2000" @date.strftime("%v").should != @date.strftime('%e-%b-%Y') diff --git a/library/datetime/deconstruct_keys_spec.rb b/library/datetime/deconstruct_keys_spec.rb index c6c0f71f55..95a391cdd8 100644 --- a/library/datetime/deconstruct_keys_spec.rb +++ b/library/datetime/deconstruct_keys_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require 'date' -ruby_version_is "3.2" do +version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do describe "DateTime#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = DateTime.new(2022, 10, 5, 13, 30) diff --git a/library/datetime/strftime_spec.rb b/library/datetime/strftime_spec.rb index 725bcafb0d..847098cb50 100644 --- a/library/datetime/strftime_spec.rb +++ b/library/datetime/strftime_spec.rb @@ -33,14 +33,14 @@ end # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do + version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-Feb-2001" @time.strftime("%v").should == @time.strftime('%e-%b-%Y') end end - ruby_version_is "3.1" do + version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-FEB-2001" @time.strftime("%v").should != @time.strftime('%e-%b-%Y') diff --git a/library/erb/new_spec.rb b/library/erb/new_spec.rb index 4d7f7bf36a..a5aeeaeed1 100644 --- a/library/erb/new_spec.rb +++ b/library/erb/new_spec.rb @@ -140,7 +140,7 @@ end describe "warning about arguments" do - ruby_version_is "3.1" do + version_is ERB.version, "2.2.1" do #ruby_version_is "3.1" do it "warns when passed safe_level and later arguments" do -> { ERB.new(@eruby_str, nil, '%') diff --git a/library/ipaddr/new_spec.rb b/library/ipaddr/new_spec.rb index 053928c3cf..714c1e2f1a 100644 --- a/library/ipaddr/new_spec.rb +++ b/library/ipaddr/new_spec.rb @@ -77,7 +77,13 @@ a.family.should == Socket::AF_INET6 end - ruby_version_is ""..."3.1" do + ipaddr_version = if defined?(IPAddr::VERSION) #ruby_version_is ""..."3.1" do + IPAddr::VERSION + else + "1.2.2" + end + + version_is ipaddr_version, ""..."1.2.3" do #ruby_version_is ""..."3.1" do it "raises on incorrect IPAddr strings" do [ ["fe80::1%fxp0"], @@ -93,7 +99,7 @@ end end - ruby_version_is "3.1" do + version_is ipaddr_version, "1.2.3" do #ruby_version_is "3.1" do it "raises on incorrect IPAddr strings" do [ ["::1/255.255.255.0"], diff --git a/library/stringio/shared/each.rb b/library/stringio/shared/each.rb index bf3265ee46..acd8d22c14 100644 --- a/library/stringio/shared/each.rb +++ b/library/stringio/shared/each.rb @@ -36,7 +36,7 @@ seen.should == ["2 1 2 1 2"] end - ruby_version_is ''..."3.2" do + version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do it "yields each paragraph with two separation characters when passed an empty String as separator" do seen = [] io = StringIO.new("para1\n\npara2\n\n\npara3") @@ -45,7 +45,7 @@ end end - ruby_version_is "3.2" do + version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do it "yields each paragraph with all separation characters when passed an empty String as separator" do seen = [] io = StringIO.new("para1\n\npara2\n\n\npara3") diff --git a/library/uri/generic/host_spec.rb b/library/uri/generic/host_spec.rb index 2de0e7ec09..210124ef66 100644 --- a/library/uri/generic/host_spec.rb +++ b/library/uri/generic/host_spec.rb @@ -2,7 +2,7 @@ require 'uri' describe "URI::Generic#host" do - ruby_version_is "3.2" do + version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do # https://hackerone.com/reports/156615 it "returns empty string when host is empty" do URI.parse('http:////foo.com').host.should == '' diff --git a/library/uri/generic/to_s_spec.rb b/library/uri/generic/to_s_spec.rb index 1dd1f2d134..8cebd374a1 100644 --- a/library/uri/generic/to_s_spec.rb +++ b/library/uri/generic/to_s_spec.rb @@ -2,7 +2,7 @@ require 'uri' describe "URI::Generic#to_s" do - ruby_version_is "3.2" do + version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do # https://hackerone.com/reports/156615 it "preserves / characters when host is empty" do URI('http:///foo.com').to_s.should == 'http:///foo.com' From ddac6768b2796c5f5e80f2f11aab071ec0c8b28c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 10 Jul 2023 14:45:42 +0900 Subject: [PATCH 2/3] Remove old guards for before 3.0 - logger 1.4.2 since ruby 2.7.0 - matrix 0.3.1 since ruby 3.0.0 - stringio 3.0.0 since ruby 3.0.0 --- library/logger/device/close_spec.rb | 15 +++------------ library/logger/device/write_spec.rb | 15 +++------------ library/matrix/unitary_spec.rb | 6 ++---- library/openssl/config/freeze_spec.rb | 22 ---------------------- library/stringio/initialize_spec.rb | 13 ++++--------- 5 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 library/openssl/config/freeze_spec.rb diff --git a/library/logger/device/close_spec.rb b/library/logger/device/close_spec.rb index 7c5e118d56..1db5d582a7 100644 --- a/library/logger/device/close_spec.rb +++ b/library/logger/device/close_spec.rb @@ -15,17 +15,8 @@ rm_r @file_path end - version_is Logger::VERSION, ""..."1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) - end + it "closes the LogDevice's stream" do + @device.close + -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) end end diff --git a/library/logger/device/write_spec.rb b/library/logger/device/write_spec.rb index cd2d7e27a9..87ecf2ad6a 100644 --- a/library/logger/device/write_spec.rb +++ b/library/logger/device/write_spec.rb @@ -35,17 +35,8 @@ rm_r path end - version_is Logger::VERSION, ""..."1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) - end + it "fails if the device is already closed" do + @device.close + -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) end end diff --git a/library/matrix/unitary_spec.rb b/library/matrix/unitary_spec.rb index b579cb244d..04e6df8be0 100644 --- a/library/matrix/unitary_spec.rb +++ b/library/matrix/unitary_spec.rb @@ -14,10 +14,8 @@ Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary? end - version_is((Matrix::const_defined?(:VERSION) ? Matrix::VERSION : "0.1.0"), "0.3.0") do - it "returns true for unitary matrices with a Complex and a negative #imag" do - Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? - end + it "returns true for unitary matrices with a Complex and a negative #imag" do + Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? end it "raises an error for rectangular matrices" do diff --git a/library/openssl/config/freeze_spec.rb b/library/openssl/config/freeze_spec.rb deleted file mode 100644 index c814341b86..0000000000 --- a/library/openssl/config/freeze_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' -require_relative '../shared/constants' - -require 'openssl' - -version_is(OpenSSL::VERSION, ""..."2.2") do - describe "OpenSSL::Config#freeze" do - it "needs to be reviewed for completeness" - - it "freezes" do - c = OpenSSL::Config.new - -> { - c['foo'] = [ ['key', 'value'] ] - }.should_not raise_error - c.freeze - c.frozen?.should be_true - -> { - c['foo'] = [ ['key', 'value'] ] - }.should raise_error(TypeError) - end - end -end diff --git a/library/stringio/initialize_spec.rb b/library/stringio/initialize_spec.rb index c597e328d3..158c08488b 100644 --- a/library/stringio/initialize_spec.rb +++ b/library/stringio/initialize_spec.rb @@ -294,14 +294,9 @@ io.string.encoding.should == Encoding::EUC_JP end - guard_not -> { # [Bug #16497] - stringio_version = StringIO.const_defined?(:VERSION) ? StringIO::VERSION : "0.0.2" - version_is(stringio_version, "0.0.3"..."0.1.1") - } do - it "the #external_encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) - io = StringIO.new(s) - io.external_encoding.should == Encoding::EUC_JP - end + it "the #external_encoding to the encoding of the String when passed a String" do + s = ''.force_encoding(Encoding::EUC_JP) + io = StringIO.new(s) + io.external_encoding.should == Encoding::EUC_JP end end From d2e26637b19bbed9177514ef3558062967ac8339 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 10 Jul 2023 14:53:03 +0900 Subject: [PATCH 3/3] `Date::VERSION` is defined all supported versions It has been defined since date 3.0.3 bundled with ruby 2.7.0. --- library/datetime/to_time_spec.rb | 3 +-- library/time/to_datetime_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/library/datetime/to_time_spec.rb b/library/datetime/to_time_spec.rb index 95eca864da..84990d511c 100644 --- a/library/datetime/to_time_spec.rb +++ b/library/datetime/to_time_spec.rb @@ -18,8 +18,7 @@ time.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do + version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do it "returns a Time representing the same instant before Gregorian" do datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) time = datetime.to_time.utc diff --git a/library/time/to_datetime_spec.rb b/library/time/to_datetime_spec.rb index 6025950b59..6e4d67eb53 100644 --- a/library/time/to_datetime_spec.rb +++ b/library/time/to_datetime_spec.rb @@ -13,8 +13,7 @@ datetime.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do + version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do it "returns a DateTime representing the same instant before Gregorian" do time = Time.utc(1582, 10, 14, 23, 58, 59) datetime = time.to_datetime