From 4da41759e7322866f0cce9c9f11c1f158c163e06 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 8 Jul 2023 21:56:57 +0900 Subject: [PATCH] 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'