Skip to content

Commit

Permalink
Use each library version instead of RUBY_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and eregon committed Jul 10, 2023
1 parent 30e1c35 commit 4da4175
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
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
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
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
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

0 comments on commit 4da4175

Please sign in to comment.