Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use each library version instead of RUBY_VERSION #1047

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/bigdecimal/remainder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions library/bigdecimal/round_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions library/bigdecimal/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =~ /\ .*/
Expand Down
2 changes: 1 addition & 1 deletion library/date/deconstruct_keys_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions library/date/strftime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion library/datetime/deconstruct_keys_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions library/datetime/strftime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions library/datetime/to_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/erb/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, '%')
Expand Down
10 changes: 8 additions & 2 deletions library/ipaddr/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"],
Expand Down
15 changes: 3 additions & 12 deletions library/logger/device/close_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 3 additions & 12 deletions library/logger/device/write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions library/matrix/unitary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions library/openssl/config/freeze_spec.rb

This file was deleted.

13 changes: 4 additions & 9 deletions library/stringio/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions library/stringio/shared/each.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions library/time/to_datetime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/uri/generic/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ''
Expand Down
2 changes: 1 addition & 1 deletion library/uri/generic/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down