diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b02c076aab..f44b460416 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,10 @@ jobs: fail-fast: false matrix: os: [ ubuntu, macos, windows ] - ruby: [ 3.2.9, 3.3.10, 3.4.8, 4.0.1 ] + ruby: [ 3.3.10, 3.4.8, 4.0.1 ] mspecopt: [""] rubyopt: [""] - exclude: - - { os: windows, ruby: 3.2.9 } # 3.2.9 has some issue with file time microseconds include: - - { os: windows, ruby: 3.2.8 } # 3.2.9 has some issue with file time microseconds - { os: ubuntu, ruby: 4.0.1, mspecopt: "--repeat 2" } - { os: ubuntu, ruby: 4.0.1, rubyopt: "--enable-frozen-string-literal" } - { os: ubuntu, ruby: 4.0.1, rubyopt: "--parser=parse.y" } diff --git a/README.md b/README.md index 674ada4c9e..14a0068346 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ For older specs try these commits: * Ruby 2.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd) * Ruby 3.0.7 - [Suite](https://github.com/ruby/spec/commit/affef93d9940f615e4836f64b011da211f570913) using [MSpec](https://github.com/ruby/mspec/commit/0aabb3e548eb5ea6cad0125f8f46cee34542b6b7) * Ruby 3.1.6 - [Suite](https://github.com/ruby/spec/commit/ec960f2389d1c2265d32397fa8afa6d462014efc) using [MSpec](https://github.com/ruby/mspec/commit/484310dbed35b84c74484fd674602f88c42d063a) +* Ruby 3.2.9 - [Suite](https://github.com/ruby/spec/commit/97f076242b7fc6e60703e6a6053365065cd6fc30) using [MSpec](https://github.com/ruby/mspec/commit/54704795e21128a930af2021c72c49cb87065134) ### Running the specs diff --git a/command_line/syntax_error_spec.rb b/command_line/syntax_error_spec.rb index 9ba87b9e22..88864c048e 100644 --- a/command_line/syntax_error_spec.rb +++ b/command_line/syntax_error_spec.rb @@ -3,17 +3,11 @@ describe "The interpreter" do it "prints an error when given a file with invalid syntax" do out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1", exit_status: 1) - - # it's tempting not to rely on error message and rely only on exception class name, - # but CRuby before 3.2 doesn't print class name for syntax error - out.should include_any_of("syntax error", "SyntaxError") + out.should.include?("SyntaxError") end it "prints an error when given code via -e with invalid syntax" do out = ruby_exe(nil, args: "-e 'a{' 2>&1", exit_status: 1) - - # it's tempting not to rely on error message and rely only on exception class name, - # but CRuby before 3.2 doesn't print class name for syntax error - out.should include_any_of("syntax error", "SyntaxError") + out.should.include?("SyntaxError") end end diff --git a/core/array/pack/c_spec.rb b/core/array/pack/c_spec.rb index 47b71b663d..7a2b95def8 100644 --- a/core/array/pack/c_spec.rb +++ b/core/array/pack/c_spec.rb @@ -45,20 +45,10 @@ [1, 2, 3, 4, 5].pack(pack_format('*')).should == "\x01\x02\x03\x04\x05" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [1, 2, 3].pack(pack_format("\000", 2)).should == "\x01\x02" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [1, 2, 3].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [1, 2, 3].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/core/array/pack/shared/basic.rb b/core/array/pack/shared/basic.rb index a63f64d296..2ebd75f6c5 100644 --- a/core/array/pack/shared/basic.rb +++ b/core/array/pack/shared/basic.rb @@ -32,22 +32,11 @@ [@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should be_an_instance_of(String) end - ruby_version_is ""..."3.3" do - it "warns that a directive is unknown" do - # additional directive ('a') is required for the X directive - -> { [@obj, @obj].pack("a K" + pack_format) }.should complain(/unknown pack directive 'K' in 'a K#{pack_format}'/) - -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/) - -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/) - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError when a directive is unknown" do - # additional directive ('a') is required for the X directive - -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/) - -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/) - -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/) - end + it "raise ArgumentError when a directive is unknown" do + # additional directive ('a') is required for the X directive + -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/) + -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/) + -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/) end it "calls #to_str to coerce the directives string" do diff --git a/core/array/pack/shared/float.rb b/core/array/pack/shared/float.rb index 76c800b74d..3f60fee215 100644 --- a/core/array/pack/shared/float.rb +++ b/core/array/pack/shared/float.rb @@ -25,20 +25,10 @@ [2.9, 1.4, 8.2].pack(pack_format("*")).should == "\x9a\x999@33\xb3?33\x03A" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -105,20 +95,10 @@ [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@9\x99\x9a?\xb333A\x0333" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -177,20 +157,10 @@ [2.9, 1.4, 8.2].pack(pack_format("*")).should == "333333\x07@ffffff\xf6?ffffff\x20@" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -248,20 +218,10 @@ [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@\x07333333?\xf6ffffff@\x20ffffff" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/core/array/pack/shared/integer.rb b/core/array/pack/shared/integer.rb index 61f7cca184..ff2ee49201 100644 --- a/core/array/pack/shared/integer.rb +++ b/core/array/pack/shared/integer.rb @@ -41,21 +41,10 @@ str.should == "\x78\x65\xcd\xab\x21\x43" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\xcd\xab" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -105,21 +94,10 @@ str.should == "\x65\x78\xab\xcd\x43\x21" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x65\x78\xab\xcd" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -169,21 +147,10 @@ str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -233,21 +200,10 @@ str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -357,21 +313,10 @@ str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -429,21 +374,10 @@ str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/core/array/pack/shared/unicode.rb b/core/array/pack/shared/unicode.rb index 4d8eaef323..0eccc7098c 100644 --- a/core/array/pack/shared/unicode.rb +++ b/core/array/pack/shared/unicode.rb @@ -67,20 +67,10 @@ -> { [obj].pack("U") }.should raise_error(TypeError) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [1, 2, 3].pack("U\x00U").should == "\x01\x02" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [1, 2, 3].pack("U\x00U") - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [1, 2, 3].pack("U\x00U") + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/core/array/pack/w_spec.rb b/core/array/pack/w_spec.rb index e770288d67..ebadb94cab 100644 --- a/core/array/pack/w_spec.rb +++ b/core/array/pack/w_spec.rb @@ -24,20 +24,10 @@ [obj].pack("w").should == "\x05" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [1, 2, 3].pack("w\x00w").should == "\x01\x02" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [1, 2, 3].pack("w\x00w") - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [1, 2, 3].pack("w\x00w") + }.should raise_error(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/core/array/rassoc_spec.rb b/core/array/rassoc_spec.rb index 632a05e8b3..a7ffb75fb5 100644 --- a/core/array/rassoc_spec.rb +++ b/core/array/rassoc_spec.rb @@ -36,17 +36,15 @@ def o.==(other); other == 'foobar'; end [[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1] end - ruby_version_is "3.3" do - it "calls to_ary on non-array elements" do - s1 = [1, 2] - s2 = ArraySpecs::ArrayConvertible.new(2, 3) - a = [s1, s2] - - s1.should_not_receive(:to_ary) - a.rassoc(2).should equal(s1) - - a.rassoc(3).should == [2, 3] - s2.called.should equal(:to_ary) - end + it "calls to_ary on non-array elements" do + s1 = [1, 2] + s2 = ArraySpecs::ArrayConvertible.new(2, 3) + a = [s1, s2] + + s1.should_not_receive(:to_ary) + a.rassoc(2).should equal(s1) + + a.rassoc(3).should == [2, 3] + s2.called.should equal(:to_ary) end end diff --git a/core/array/sum_spec.rb b/core/array/sum_spec.rb index 06abe06135..1886d692fa 100644 --- a/core/array/sum_spec.rb +++ b/core/array/sum_spec.rb @@ -74,13 +74,11 @@ [b].sum(a).should == 42 end - ruby_bug '#19530', ''...'3.3' do - it "calls + on the init value" do - a = mock("a") - b = mock("b") - a.should_receive(:+).with(42).and_return(b) - [42].sum(a).should == b - end + it "calls + on the init value" do + a = mock("a") + b = mock("b") + a.should_receive(:+).with(42).and_return(b) + [42].sum(a).should == b end end diff --git a/core/basicobject/instance_eval_spec.rb b/core/basicobject/instance_eval_spec.rb index 633b5c2cb1..f8d9d75059 100644 --- a/core/basicobject/instance_eval_spec.rb +++ b/core/basicobject/instance_eval_spec.rb @@ -84,11 +84,9 @@ def foo end - ruby_version_is "3.3" do - it "uses the caller location as default location" do - f = Object.new - f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] - end + it "uses the caller location as default location" do + f = Object.new + f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] end it "has access to receiver's instance variables" do diff --git a/core/binding/eval_spec.rb b/core/binding/eval_spec.rb index bb2036f739..7852e1c939 100644 --- a/core/binding/eval_spec.rb +++ b/core/binding/eval_spec.rb @@ -60,14 +60,6 @@ bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 end - ruby_version_is ""..."3.3" do - it "uses (eval) as __FILE__ if single argument given" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__FILE__").should == '(eval)' - end - end - it "uses 1 as __LINE__" do obj = BindingSpecs::Demo.new(1) bind = obj.get_binding @@ -107,9 +99,7 @@ bind.eval("'bar'.foo").should == "foo" end - ruby_version_is "3.3" do - it "uses the caller location as default filename" do - binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] - end + it "uses the caller location as default filename" do + binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] end end diff --git a/core/data/with_spec.rb b/core/data/with_spec.rb index fd0a99d1fa..83cb97fa60 100644 --- a/core/data/with_spec.rb +++ b/core/data/with_spec.rb @@ -44,14 +44,12 @@ def subclass.new(*) data_copy.unit.should == "m" end - ruby_version_is "3.3" do - it "calls #initialize" do - data = DataSpecs::DataWithOverriddenInitialize.new(42, "m") - ScratchPad.clear + it "calls #initialize" do + data = DataSpecs::DataWithOverriddenInitialize.new(42, "m") + ScratchPad.clear - data.with(amount: 0) + data.with(amount: 0) - ScratchPad.recorded.should == [:initialize, [], {amount: 0, unit: "m"}] - end + ScratchPad.recorded.should == [:initialize, [], {amount: 0, unit: "m"}] end end diff --git a/core/dir/chdir_spec.rb b/core/dir/chdir_spec.rb index 015386a902..fd277e4e1d 100644 --- a/core/dir/chdir_spec.rb +++ b/core/dir/chdir_spec.rb @@ -125,96 +125,94 @@ def to_str; DirSpecs.mock_dir; end end end -ruby_version_is '3.3' do - describe "Dir#chdir" do - before :all do - DirSpecs.create_mock_dirs - end +describe "Dir#chdir" do + before :all do + DirSpecs.create_mock_dirs + end - after :all do - DirSpecs.delete_mock_dirs - end + after :all do + DirSpecs.delete_mock_dirs + end - before :each do - @original = Dir.pwd - end + before :each do + @original = Dir.pwd + end - after :each do - Dir.chdir(@original) - end + after :each do + Dir.chdir(@original) + end - it "changes the current working directory to self" do - dir = Dir.new(DirSpecs.mock_dir) - dir.chdir - Dir.pwd.should == DirSpecs.mock_dir - ensure - dir.close - end + it "changes the current working directory to self" do + dir = Dir.new(DirSpecs.mock_dir) + dir.chdir + Dir.pwd.should == DirSpecs.mock_dir + ensure + dir.close + end - it "changes the current working directory to self for duration of the block when a block is given" do - dir = Dir.new(DirSpecs.mock_dir) - pwd_in_block = nil + it "changes the current working directory to self for duration of the block when a block is given" do + dir = Dir.new(DirSpecs.mock_dir) + pwd_in_block = nil - dir.chdir { pwd_in_block = Dir.pwd } + dir.chdir { pwd_in_block = Dir.pwd } - pwd_in_block.should == DirSpecs.mock_dir - Dir.pwd.should == @original - ensure - dir.close - end + pwd_in_block.should == DirSpecs.mock_dir + Dir.pwd.should == @original + ensure + dir.close + end - it "returns 0 when successfully changing directory" do - dir = Dir.new(DirSpecs.mock_dir) - dir.chdir.should == 0 - ensure - dir.close - end + it "returns 0 when successfully changing directory" do + dir = Dir.new(DirSpecs.mock_dir) + dir.chdir.should == 0 + ensure + dir.close + end - it "returns the value of the block when a block is given" do - dir = Dir.new(DirSpecs.mock_dir) - dir.chdir { :block_value }.should == :block_value - ensure - dir.close - end + it "returns the value of the block when a block is given" do + dir = Dir.new(DirSpecs.mock_dir) + dir.chdir { :block_value }.should == :block_value + ensure + dir.close + end + + platform_is_not :windows do + it "does not raise an Errno::ENOENT if the original directory no longer exists" do + dir_name1 = tmp('testdir1') + dir_name2 = tmp('testdir2') + Dir.should_not.exist?(dir_name1) + Dir.should_not.exist?(dir_name2) + Dir.mkdir dir_name1 + Dir.mkdir dir_name2 - platform_is_not :windows do - it "does not raise an Errno::ENOENT if the original directory no longer exists" do - dir_name1 = tmp('testdir1') - dir_name2 = tmp('testdir2') - Dir.should_not.exist?(dir_name1) - Dir.should_not.exist?(dir_name2) - Dir.mkdir dir_name1 - Dir.mkdir dir_name2 - - dir2 = Dir.new(dir_name2) - - begin - Dir.chdir(dir_name1) do - dir2.chdir { Dir.unlink dir_name1 } - end - Dir.pwd.should == @original - ensure - Dir.unlink dir_name1 if Dir.exist?(dir_name1) - Dir.unlink dir_name2 if Dir.exist?(dir_name2) + dir2 = Dir.new(dir_name2) + + begin + Dir.chdir(dir_name1) do + dir2.chdir { Dir.unlink dir_name1 } end + Dir.pwd.should == @original ensure - dir2.close + Dir.unlink dir_name1 if Dir.exist?(dir_name1) + Dir.unlink dir_name2 if Dir.exist?(dir_name2) end + ensure + dir2.close end + end - it "always returns to the original directory when given a block" do - dir = Dir.new(DirSpecs.mock_dir) + it "always returns to the original directory when given a block" do + dir = Dir.new(DirSpecs.mock_dir) - begin - dir.chdir do - raise StandardError, "something bad happened" - end - rescue StandardError + begin + dir.chdir do + raise StandardError, "something bad happened" end - - Dir.pwd.should == @original - ensure - dir.close + rescue StandardError end + + Dir.pwd.should == @original + ensure + dir.close end end diff --git a/core/dir/close_spec.rb b/core/dir/close_spec.rb index f7cce318b8..10ad1369c8 100644 --- a/core/dir/close_spec.rb +++ b/core/dir/close_spec.rb @@ -24,7 +24,7 @@ dir.close.should == nil end - ruby_version_is '3.3'...'3.4' do + ruby_version_is ''...'3.4' do platform_is_not :windows do it "does not raise an error even if the file descriptor is closed with another Dir instance" do dir = Dir.open DirSpecs.mock_dir diff --git a/core/dir/fchdir_spec.rb b/core/dir/fchdir_spec.rb index 52600a95f2..d5e77f7f03 100644 --- a/core/dir/fchdir_spec.rb +++ b/core/dir/fchdir_spec.rb @@ -1,73 +1,71 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -ruby_version_is '3.3' do - platform_is_not :windows do - describe "Dir.fchdir" do - before :all do - DirSpecs.create_mock_dirs - end +platform_is_not :windows do + describe "Dir.fchdir" do + before :all do + DirSpecs.create_mock_dirs + end - after :all do - DirSpecs.delete_mock_dirs - end + after :all do + DirSpecs.delete_mock_dirs + end - before :each do - @original = Dir.pwd - end + before :each do + @original = Dir.pwd + end - after :each do - Dir.chdir(@original) - end + after :each do + Dir.chdir(@original) + end - it "changes the current working directory to the directory specified by the integer file descriptor" do - dir = Dir.new(DirSpecs.mock_dir) - Dir.fchdir dir.fileno - Dir.pwd.should == DirSpecs.mock_dir - ensure - dir.close - end + it "changes the current working directory to the directory specified by the integer file descriptor" do + dir = Dir.new(DirSpecs.mock_dir) + Dir.fchdir dir.fileno + Dir.pwd.should == DirSpecs.mock_dir + ensure + dir.close + end - it "returns 0 when successfully changing directory" do - dir = Dir.new(DirSpecs.mock_dir) - Dir.fchdir(dir.fileno).should == 0 - ensure - dir.close - end + it "returns 0 when successfully changing directory" do + dir = Dir.new(DirSpecs.mock_dir) + Dir.fchdir(dir.fileno).should == 0 + ensure + dir.close + end - it "returns the value of the block when a block is given" do - dir = Dir.new(DirSpecs.mock_dir) - Dir.fchdir(dir.fileno) { :block_value }.should == :block_value - ensure - dir.close - end + it "returns the value of the block when a block is given" do + dir = Dir.new(DirSpecs.mock_dir) + Dir.fchdir(dir.fileno) { :block_value }.should == :block_value + ensure + dir.close + end - it "changes to the specified directory for the duration of the block" do - dir = Dir.new(DirSpecs.mock_dir) - Dir.fchdir(dir.fileno) { Dir.pwd }.should == DirSpecs.mock_dir - Dir.pwd.should == @original - ensure - dir.close - end + it "changes to the specified directory for the duration of the block" do + dir = Dir.new(DirSpecs.mock_dir) + Dir.fchdir(dir.fileno) { Dir.pwd }.should == DirSpecs.mock_dir + Dir.pwd.should == @original + ensure + dir.close + end - it "raises a SystemCallError if the file descriptor given is not valid" do - -> { Dir.fchdir(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fchdir") - -> { Dir.fchdir(-1) { } }.should raise_error(SystemCallError, "Bad file descriptor - fchdir") - end + it "raises a SystemCallError if the file descriptor given is not valid" do + -> { Dir.fchdir(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fchdir") + -> { Dir.fchdir(-1) { } }.should raise_error(SystemCallError, "Bad file descriptor - fchdir") + end - it "raises a SystemCallError if the file descriptor given is not for a directory" do - -> { Dir.fchdir $stdout.fileno }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/) - -> { Dir.fchdir($stdout.fileno) { } }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/) - end + it "raises a SystemCallError if the file descriptor given is not for a directory" do + -> { Dir.fchdir $stdout.fileno }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/) + -> { Dir.fchdir($stdout.fileno) { } }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/) end end +end - platform_is :windows do - describe "Dir.fchdir" do - it "raises NotImplementedError" do - -> { Dir.fchdir 1 }.should raise_error(NotImplementedError) - -> { Dir.fchdir(1) { } }.should raise_error(NotImplementedError) - end +platform_is :windows do + describe "Dir.fchdir" do + it "raises NotImplementedError" do + -> { Dir.fchdir 1 }.should raise_error(NotImplementedError) + -> { Dir.fchdir(1) { } }.should raise_error(NotImplementedError) end end end diff --git a/core/dir/for_fd_spec.rb b/core/dir/for_fd_spec.rb index ba467f2f86..1559e1baa4 100644 --- a/core/dir/for_fd_spec.rb +++ b/core/dir/for_fd_spec.rb @@ -2,77 +2,75 @@ require_relative 'fixtures/common' quarantine! do # leads to "Errno::EBADF: Bad file descriptor - closedir" in DirSpecs.delete_mock_dirs -ruby_version_is '3.3' do - platform_is_not :windows do - describe "Dir.for_fd" do - before :all do - DirSpecs.create_mock_dirs - end +platform_is_not :windows do + describe "Dir.for_fd" do + before :all do + DirSpecs.create_mock_dirs + end - after :all do - DirSpecs.delete_mock_dirs - end + after :all do + DirSpecs.delete_mock_dirs + end - before :each do - @original = Dir.pwd - end + before :each do + @original = Dir.pwd + end - after :each do - Dir.chdir(@original) - end + after :each do + Dir.chdir(@original) + end - it "returns a new Dir object representing the directory specified by the given integer directory file descriptor" do - dir = Dir.new(DirSpecs.mock_dir) - dir_new = Dir.for_fd(dir.fileno) + it "returns a new Dir object representing the directory specified by the given integer directory file descriptor" do + dir = Dir.new(DirSpecs.mock_dir) + dir_new = Dir.for_fd(dir.fileno) - dir_new.should.instance_of?(Dir) - dir_new.children.should == dir.children - dir_new.fileno.should == dir.fileno - ensure - dir.close - end + dir_new.should.instance_of?(Dir) + dir_new.children.should == dir.children + dir_new.fileno.should == dir.fileno + ensure + dir.close + end - it "returns a new Dir object without associated path" do - dir = Dir.new(DirSpecs.mock_dir) - dir_new = Dir.for_fd(dir.fileno) + it "returns a new Dir object without associated path" do + dir = Dir.new(DirSpecs.mock_dir) + dir_new = Dir.for_fd(dir.fileno) - dir_new.path.should == nil - ensure - dir.close - end + dir_new.path.should == nil + ensure + dir.close + end - it "calls #to_int to convert a value to an Integer" do - dir = Dir.new(DirSpecs.mock_dir) - obj = mock("fd") - obj.should_receive(:to_int).and_return(dir.fileno) + it "calls #to_int to convert a value to an Integer" do + dir = Dir.new(DirSpecs.mock_dir) + obj = mock("fd") + obj.should_receive(:to_int).and_return(dir.fileno) - dir_new = Dir.for_fd(obj) - dir_new.fileno.should == dir.fileno - ensure - dir.close - end + dir_new = Dir.for_fd(obj) + dir_new.fileno.should == dir.fileno + ensure + dir.close + end - it "raises TypeError when value cannot be converted to Integer" do - -> { - Dir.for_fd(nil) - }.should raise_error(TypeError, "no implicit conversion from nil to integer") - end + it "raises TypeError when value cannot be converted to Integer" do + -> { + Dir.for_fd(nil) + }.should raise_error(TypeError, "no implicit conversion from nil to integer") + end - it "raises a SystemCallError if the file descriptor given is not valid" do - -> { Dir.for_fd(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fdopendir") - end + it "raises a SystemCallError if the file descriptor given is not valid" do + -> { Dir.for_fd(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fdopendir") + end - it "raises a SystemCallError if the file descriptor given is not for a directory" do - -> { Dir.for_fd $stdout.fileno }.should raise_error(SystemCallError, "Not a directory - fdopendir") - end + it "raises a SystemCallError if the file descriptor given is not for a directory" do + -> { Dir.for_fd $stdout.fileno }.should raise_error(SystemCallError, "Not a directory - fdopendir") end end +end - platform_is :windows do - describe "Dir.for_fd" do - it "raises NotImplementedError" do - -> { Dir.for_fd 1 }.should raise_error(NotImplementedError) - end +platform_is :windows do + describe "Dir.for_fd" do + it "raises NotImplementedError" do + -> { Dir.for_fd 1 }.should raise_error(NotImplementedError) end end end diff --git a/core/encoding/replicate_spec.rb b/core/encoding/replicate_spec.rb index 2da998837f..9fe0ba8747 100644 --- a/core/encoding/replicate_spec.rb +++ b/core/encoding/replicate_spec.rb @@ -2,87 +2,7 @@ require_relative '../../spec_helper' describe "Encoding#replicate" do - ruby_version_is ""..."3.3" do - before :all do - @i = 0 - end - - before :each do - @i += 1 - @prefix = "RS#{@i}" - end - - it "returns a replica of ASCII" do - name = @prefix + '-ASCII' - e = suppress_warning { Encoding::ASCII.replicate(name) } - e.name.should == name - Encoding.find(name).should == e - - "a".dup.force_encoding(e).valid_encoding?.should be_true - "\x80".dup.force_encoding(e).valid_encoding?.should be_false - end - - it "returns a replica of UTF-8" do - name = @prefix + 'UTF-8' - e = suppress_warning { Encoding::UTF_8.replicate(name) } - e.name.should == name - Encoding.find(name).should == e - - "a".dup.force_encoding(e).valid_encoding?.should be_true - "\u3042".dup.force_encoding(e).valid_encoding?.should be_true - "\x80".dup.force_encoding(e).valid_encoding?.should be_false - end - - it "returns a replica of UTF-16BE" do - name = @prefix + 'UTF-16-BE' - e = suppress_warning { Encoding::UTF_16BE.replicate(name) } - e.name.should == name - Encoding.find(name).should == e - - "a".dup.force_encoding(e).valid_encoding?.should be_false - "\x30\x42".dup.force_encoding(e).valid_encoding?.should be_true - "\x80".dup.force_encoding(e).valid_encoding?.should be_false - end - - it "returns a replica of ISO-2022-JP" do - name = @prefix + 'ISO-2022-JP' - e = suppress_warning { Encoding::ISO_2022_JP.replicate(name) } - Encoding.find(name).should == e - - e.name.should == name - e.dummy?.should be_true - end - - # NOTE: it's unclear of the value of this (for the complexity cost of it), - # but it is the current CRuby behavior. - it "can be associated with a String" do - name = @prefix + '-US-ASCII' - e = suppress_warning { Encoding::US_ASCII.replicate(name) } - e.name.should == name - Encoding.find(name).should == e - - s = "abc".dup.force_encoding(e) - s.encoding.should == e - s.encoding.name.should == name - end - end - - ruby_version_is ""..."3.3" do - it "warns about deprecation" do - -> { - Encoding::US_ASCII.replicate('MY-US-ASCII') - }.should complain(/warning: Encoding#replicate is deprecated and will be removed in Ruby 3.3; use the original encoding instead/) - end - - it "raises EncodingError if too many encodings" do - code = '1_000.times {|i| Encoding::US_ASCII.replicate("R_#{i}") }' - ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)') - end - end - - ruby_version_is "3.3" do - it "has been removed" do - Encoding::US_ASCII.should_not.respond_to?(:replicate, true) - end + it "has been removed" do + Encoding::US_ASCII.should_not.respond_to?(:replicate, true) end end diff --git a/core/exception/no_method_error_spec.rb b/core/exception/no_method_error_spec.rb index 772c569f67..d20878c6e3 100644 --- a/core/exception/no_method_error_spec.rb +++ b/core/exception/no_method_error_spec.rb @@ -66,204 +66,145 @@ end end - ruby_version_is ""..."3.3" do - it "calls #inspect when calling Exception#message" do - ScratchPad.record [] - test_class = Class.new do - def inspect - ScratchPad << :inspect_called - "" - end - end - instance = test_class.new - - begin - instance.bar - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']bar' for :#$/ - ScratchPad.recorded.should == [:inspect_called] - end - end - - it "fallbacks to a simpler representation of the receiver when receiver.inspect raises an exception" do - test_class = Class.new do - def inspect - raise NoMethodErrorSpecs::InstanceException - end - end - instance = test_class.new - - begin - instance.bar - rescue NoMethodError => error - message = error.message - message.should =~ /undefined method.+\bbar\b/ - message.should include test_class.inspect - end - end - - it "uses #name to display the receiver if it is a class" do - klass = Class.new { def self.name; "MyClass"; end } - - begin - klass.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for MyClass:Class$/ - end + it "uses a literal name when receiver is nil" do + begin + nil.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for nil\Z/ end + end - it "uses #name to display the receiver if it is a module" do - mod = Module.new { def self.name; "MyModule"; end } - - begin - mod.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for MyModule:Module$/ - end + it "uses a literal name when receiver is true" do + begin + true.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for true\Z/ end end - ruby_version_is "3.3" do - it "uses a literal name when receiver is nil" do - begin - nil.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for nil\Z/ - end + it "uses a literal name when receiver is false" do + begin + false.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for false\Z/ end + end - it "uses a literal name when receiver is true" do - begin - true.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for true\Z/ - end - end + it "uses #name when receiver is a class" do + klass = Class.new { def self.name; "MyClass"; end } - it "uses a literal name when receiver is false" do - begin - false.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for false\Z/ - end + begin + klass.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for class MyClass\Z/ end + end - it "uses #name when receiver is a class" do - klass = Class.new { def self.name; "MyClass"; end } + it "uses class' string representation when receiver is an anonymous class" do + klass = Class.new - begin - klass.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for class MyClass\Z/ - end + begin + klass.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for class #\Z/ end + end - it "uses class' string representation when receiver is an anonymous class" do - klass = Class.new + it "uses class' string representation when receiver is a singleton class" do + obj = Object.new + singleton_class = obj.singleton_class - begin - klass.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for class #\Z/ - end + begin + singleton_class.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for class #>\Z/ end + end - it "uses class' string representation when receiver is a singleton class" do - obj = Object.new - singleton_class = obj.singleton_class + it "uses #name when receiver is a module" do + mod = Module.new { def self.name; "MyModule"; end } - begin - singleton_class.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for class #>\Z/ - end + begin + mod.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for module MyModule\Z/ end + end - it "uses #name when receiver is a module" do - mod = Module.new { def self.name; "MyModule"; end } + it "uses module's string representation when receiver is an anonymous module" do + m = Module.new - begin - mod.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for module MyModule\Z/ - end + begin + m.foo + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for module #\Z/ end + end - it "uses module's string representation when receiver is an anonymous module" do - m = Module.new + it "uses class #name when receiver is an ordinary object" do + klass = Class.new { def self.name; "MyClass"; end } + instance = klass.new - begin - m.foo - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for module #\Z/ - end + begin + instance.bar + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']bar' for an instance of MyClass\Z/ end + end - it "uses class #name when receiver is an ordinary object" do - klass = Class.new { def self.name; "MyClass"; end } - instance = klass.new + it "uses class string representation when receiver is an instance of anonymous class" do + klass = Class.new + instance = klass.new - begin - instance.bar - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']bar' for an instance of MyClass\Z/ - end + begin + instance.bar + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']bar' for an instance of #\Z/ end + end - it "uses class string representation when receiver is an instance of anonymous class" do - klass = Class.new - instance = klass.new + it "uses class name when receiver has a singleton class" do + instance = NoMethodErrorSpecs::NoMethodErrorA.new + def instance.foo; end - begin - instance.bar - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']bar' for an instance of #\Z/ - end + begin + instance.bar + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']bar' for #\Z/ end + end - it "uses class name when receiver has a singleton class" do - instance = NoMethodErrorSpecs::NoMethodErrorA.new - def instance.foo; end - - begin - instance.bar - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']bar' for #\Z/ + it "does not call #inspect when calling Exception#message" do + ScratchPad.record [] + test_class = Class.new do + def inspect + ScratchPad << :inspect_called + "" end end + instance = test_class.new - it "does not call #inspect when calling Exception#message" do - ScratchPad.record [] - test_class = Class.new do - def inspect - ScratchPad << :inspect_called - "" - end - end - instance = test_class.new - - begin - instance.bar - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']bar' for an instance of #\Z/ - ScratchPad.recorded.should == [] - end + begin + instance.bar + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']bar' for an instance of #\Z/ + ScratchPad.recorded.should == [] end + end - it "does not truncate long class names" do - class_name = 'ExceptionSpecs::A' + 'a'*100 + it "does not truncate long class names" do + class_name = 'ExceptionSpecs::A' + 'a'*100 - begin - eval <<~RUBY - class #{class_name} - end + begin + eval <<~RUBY + class #{class_name} + end - obj = #{class_name}.new - obj.foo - RUBY - rescue NoMethodError => error - error.message.should =~ /\Aundefined method [`']foo' for an instance of #{class_name}\Z/ - end + obj = #{class_name}.new + obj.foo + RUBY + rescue NoMethodError => error + error.message.should =~ /\Aundefined method [`']foo' for an instance of #{class_name}\Z/ end end end diff --git a/core/false/singleton_method_spec.rb b/core/false/singleton_method_spec.rb index 738794b46c..16dc85d67c 100644 --- a/core/false/singleton_method_spec.rb +++ b/core/false/singleton_method_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' describe "FalseClass#singleton_method" do - ruby_version_is '3.3' do - it "raises regardless of whether FalseClass defines the method" do + it "raises regardless of whether FalseClass defines the method" do + -> { false.singleton_method(:foo) }.should raise_error(NameError) + begin + def (false).foo; end -> { false.singleton_method(:foo) }.should raise_error(NameError) - begin - def (false).foo; end - -> { false.singleton_method(:foo) }.should raise_error(NameError) - ensure - FalseClass.send(:remove_method, :foo) - end + ensure + FalseClass.send(:remove_method, :foo) end end end diff --git a/core/fiber/kill_spec.rb b/core/fiber/kill_spec.rb index 2f4c499280..abf23ff176 100644 --- a/core/fiber/kill_spec.rb +++ b/core/fiber/kill_spec.rb @@ -2,89 +2,87 @@ require_relative 'fixtures/classes' require_relative '../../shared/kernel/raise' -ruby_version_is "3.3" do - describe "Fiber#kill" do - it "kills a non-resumed fiber" do - fiber = Fiber.new{} +describe "Fiber#kill" do + it "kills a non-resumed fiber" do + fiber = Fiber.new{} - fiber.alive?.should == true + fiber.alive?.should == true - fiber.kill - fiber.alive?.should == false - end - - it "kills a resumed fiber" do - fiber = Fiber.new{while true; Fiber.yield; end} - fiber.resume - - fiber.alive?.should == true + fiber.kill + fiber.alive?.should == false + end - fiber.kill - fiber.alive?.should == false - end + it "kills a resumed fiber" do + fiber = Fiber.new{while true; Fiber.yield; end} + fiber.resume - it "can kill itself" do - fiber = Fiber.new do - Fiber.current.kill - end + fiber.alive?.should == true - fiber.alive?.should == true + fiber.kill + fiber.alive?.should == false + end - fiber.resume - fiber.alive?.should == false + it "can kill itself" do + fiber = Fiber.new do + Fiber.current.kill end - it "kills a resumed fiber from a child" do - parent = Fiber.new do - child = Fiber.new do - parent.kill - parent.alive?.should == true - end + fiber.alive?.should == true + + fiber.resume + fiber.alive?.should == false + end - child.resume + it "kills a resumed fiber from a child" do + parent = Fiber.new do + child = Fiber.new do + parent.kill + parent.alive?.should == true end - parent.resume - parent.alive?.should == false + child.resume end - it "executes the ensure block" do - ensure_executed = false + parent.resume + parent.alive?.should == false + end - fiber = Fiber.new do - while true; Fiber.yield; end - ensure - ensure_executed = true - end + it "executes the ensure block" do + ensure_executed = false - fiber.resume - fiber.kill - ensure_executed.should == true + fiber = Fiber.new do + while true; Fiber.yield; end + ensure + ensure_executed = true end - it "does not execute rescue block" do - rescue_executed = false + fiber.resume + fiber.kill + ensure_executed.should == true + end - fiber = Fiber.new do - while true; Fiber.yield; end - rescue Exception - rescue_executed = true - end + it "does not execute rescue block" do + rescue_executed = false - fiber.resume - fiber.kill - rescue_executed.should == false + fiber = Fiber.new do + while true; Fiber.yield; end + rescue Exception + rescue_executed = true end - it "repeatedly kills a fiber" do - fiber = Fiber.new do - while true; Fiber.yield; end - ensure - while true; Fiber.yield; end - end + fiber.resume + fiber.kill + rescue_executed.should == false + end - fiber.kill - fiber.alive?.should == false + it "repeatedly kills a fiber" do + fiber = Fiber.new do + while true; Fiber.yield; end + ensure + while true; Fiber.yield; end end + + fiber.kill + fiber.alive?.should == false end end diff --git a/core/fiber/storage_spec.rb b/core/fiber/storage_spec.rb index 015caaf3bb..6ffc13ee28 100644 --- a/core/fiber/storage_spec.rb +++ b/core/fiber/storage_spec.rb @@ -161,13 +161,11 @@ def key.to_str; "Foo"; end -> { Fiber[Object.new] = 44 }.should raise_error(TypeError) end - ruby_version_is "3.3" do - it "deletes the fiber storage key when assigning nil" do - Fiber.new(storage: {life: 42}) { - Fiber[:life] = nil - Fiber.current.storage - }.resume.should == {} - end + it "deletes the fiber storage key when assigning nil" do + Fiber.new(storage: {life: 42}) { + Fiber[:life] = nil + Fiber.current.storage + }.resume.should == {} end end diff --git a/core/file/basename_spec.rb b/core/file/basename_spec.rb index 87695ab97b..66a5b56ed9 100644 --- a/core/file/basename_spec.rb +++ b/core/file/basename_spec.rb @@ -162,11 +162,7 @@ it "rejects strings encoded with non ASCII-compatible encodings" do Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc| - begin - path = "/foo/bar".encode(enc) - rescue Encoding::ConverterNotFoundError - next - end + path = "/foo/bar".encode(enc) -> { File.basename(path) diff --git a/core/file/dirname_spec.rb b/core/file/dirname_spec.rb index 4206e07296..1b006af783 100644 --- a/core/file/dirname_spec.rb +++ b/core/file/dirname_spec.rb @@ -78,14 +78,12 @@ def object.to_int; 2; end File.dirname("foo/../").should == "foo" end - ruby_version_is "3.3" do # Ruby 3.2 has Encoding#replicate which can break this - it "rejects strings encoded with non ASCII-compatible encodings" do - Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc| - path = "/foo/bar".encode(enc) - -> { - File.dirname(path) - }.should raise_error(Encoding::CompatibilityError) - end + it "rejects strings encoded with non ASCII-compatible encodings" do + Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc| + path = "/foo/bar".encode(enc) + -> { + File.dirname(path) + }.should raise_error(Encoding::CompatibilityError) end end diff --git a/core/float/round_spec.rb b/core/float/round_spec.rb index 944bcf2a6e..3e6575100b 100644 --- a/core/float/round_spec.rb +++ b/core/float/round_spec.rb @@ -146,37 +146,35 @@ -4.809999999999999.round(5, half: :even).should eql(-4.81) end - ruby_bug "#19318", ""..."3.3" do - # These numbers are neighbouring floating point numbers round a - # precise value. They test that the rounding modes work correctly - # round that value and precision is not lost which might cause - # incorrect results. - it "does not lose precision during the rounding process" do - 767573.1875850001.round(5, half: nil).should eql(767573.18759) - 767573.1875850001.round(5, half: :up).should eql(767573.18759) - 767573.1875850001.round(5, half: :down).should eql(767573.18759) - 767573.1875850001.round(5, half: :even).should eql(767573.18759) - -767573.1875850001.round(5, half: nil).should eql(-767573.18759) - -767573.1875850001.round(5, half: :up).should eql(-767573.18759) - -767573.1875850001.round(5, half: :down).should eql(-767573.18759) - -767573.1875850001.round(5, half: :even).should eql(-767573.18759) - 767573.187585.round(5, half: nil).should eql(767573.18759) - 767573.187585.round(5, half: :up).should eql(767573.18759) - 767573.187585.round(5, half: :down).should eql(767573.18758) - 767573.187585.round(5, half: :even).should eql(767573.18758) - -767573.187585.round(5, half: nil).should eql(-767573.18759) - -767573.187585.round(5, half: :up).should eql(-767573.18759) - -767573.187585.round(5, half: :down).should eql(-767573.18758) - -767573.187585.round(5, half: :even).should eql(-767573.18758) - 767573.1875849998.round(5, half: nil).should eql(767573.18758) - 767573.1875849998.round(5, half: :up).should eql(767573.18758) - 767573.1875849998.round(5, half: :down).should eql(767573.18758) - 767573.1875849998.round(5, half: :even).should eql(767573.18758) - -767573.1875849998.round(5, half: nil).should eql(-767573.18758) - -767573.1875849998.round(5, half: :up).should eql(-767573.18758) - -767573.1875849998.round(5, half: :down).should eql(-767573.18758) - -767573.1875849998.round(5, half: :even).should eql(-767573.18758) - end + # These numbers are neighbouring floating point numbers round a + # precise value. They test that the rounding modes work correctly + # round that value and precision is not lost which might cause + # incorrect results. + it "does not lose precision during the rounding process" do + 767573.1875850001.round(5, half: nil).should eql(767573.18759) + 767573.1875850001.round(5, half: :up).should eql(767573.18759) + 767573.1875850001.round(5, half: :down).should eql(767573.18759) + 767573.1875850001.round(5, half: :even).should eql(767573.18759) + -767573.1875850001.round(5, half: nil).should eql(-767573.18759) + -767573.1875850001.round(5, half: :up).should eql(-767573.18759) + -767573.1875850001.round(5, half: :down).should eql(-767573.18759) + -767573.1875850001.round(5, half: :even).should eql(-767573.18759) + 767573.187585.round(5, half: nil).should eql(767573.18759) + 767573.187585.round(5, half: :up).should eql(767573.18759) + 767573.187585.round(5, half: :down).should eql(767573.18758) + 767573.187585.round(5, half: :even).should eql(767573.18758) + -767573.187585.round(5, half: nil).should eql(-767573.18759) + -767573.187585.round(5, half: :up).should eql(-767573.18759) + -767573.187585.round(5, half: :down).should eql(-767573.18758) + -767573.187585.round(5, half: :even).should eql(-767573.18758) + 767573.1875849998.round(5, half: nil).should eql(767573.18758) + 767573.1875849998.round(5, half: :up).should eql(767573.18758) + 767573.1875849998.round(5, half: :down).should eql(767573.18758) + 767573.1875849998.round(5, half: :even).should eql(767573.18758) + -767573.1875849998.round(5, half: nil).should eql(-767573.18758) + -767573.1875849998.round(5, half: :up).should eql(-767573.18758) + -767573.1875849998.round(5, half: :down).should eql(-767573.18758) + -767573.1875849998.round(5, half: :even).should eql(-767573.18758) end it "raises FloatDomainError for exceptional values with a half option" do diff --git a/core/hash/compact_spec.rb b/core/hash/compact_spec.rb index 13371bce43..48f8bb7cae 100644 --- a/core/hash/compact_spec.rb +++ b/core/hash/compact_spec.rb @@ -19,28 +19,26 @@ @hash.should == @initial_pairs end - ruby_version_is '3.3' do - it "retains the default value" do - hash = Hash.new(1) - hash.compact.default.should == 1 - hash[:a] = 1 - hash.compact.default.should == 1 - end + it "retains the default value" do + hash = Hash.new(1) + hash.compact.default.should == 1 + hash[:a] = 1 + hash.compact.default.should == 1 + end - it "retains the default_proc" do - pr = proc { |h, k| h[k] = [] } - hash = Hash.new(&pr) - hash.compact.default_proc.should == pr - hash[:a] = 1 - hash.compact.default_proc.should == pr - end + it "retains the default_proc" do + pr = proc { |h, k| h[k] = [] } + hash = Hash.new(&pr) + hash.compact.default_proc.should == pr + hash[:a] = 1 + hash.compact.default_proc.should == pr + end - it "retains compare_by_identity flag" do - hash = {}.compare_by_identity - hash.compact.compare_by_identity?.should == true - hash[:a] = 1 - hash.compact.compare_by_identity?.should == true - end + it "retains compare_by_identity flag" do + hash = {}.compare_by_identity + hash.compact.compare_by_identity?.should == true + hash[:a] = 1 + hash.compact.compare_by_identity?.should == true end end diff --git a/core/hash/constructor_spec.rb b/core/hash/constructor_spec.rb index 201a20c1f9..301f8675ce 100644 --- a/core/hash/constructor_spec.rb +++ b/core/hash/constructor_spec.rb @@ -117,13 +117,11 @@ def obj.to_hash() { 1 => 2, 3 => 4 } end Hash[hash].default_proc.should be_nil end - ruby_version_is '3.3' do - it "does not retain compare_by_identity flag" do - hash = { a: 1 }.compare_by_identity - Hash[hash].compare_by_identity?.should == false + it "does not retain compare_by_identity flag" do + hash = { a: 1 }.compare_by_identity + Hash[hash].compare_by_identity?.should == false - hash = {}.compare_by_identity - Hash[hash].compare_by_identity?.should == false - end + hash = {}.compare_by_identity + Hash[hash].compare_by_identity?.should == false end end diff --git a/core/hash/new_spec.rb b/core/hash/new_spec.rb index 5ae3e1f98d..8de44ec941 100644 --- a/core/hash/new_spec.rb +++ b/core/hash/new_spec.rb @@ -34,7 +34,7 @@ -> { Hash.new(nil) { 0 } }.should raise_error(ArgumentError) end - ruby_version_is "3.3"..."3.4" do + ruby_version_is ""..."3.4" do it "emits a deprecation warning if keyword arguments are passed" do -> { Hash.new(unknown: true) }.should complain( Regexp.new(Regexp.escape("Calling Hash.new with keyword arguments is deprecated and will be removed in Ruby 3.4; use Hash.new({ key: value }) instead")) diff --git a/core/hash/ruby2_keywords_hash_spec.rb b/core/hash/ruby2_keywords_hash_spec.rb index 7dbb9c0a98..ddf9038800 100644 --- a/core/hash/ruby2_keywords_hash_spec.rb +++ b/core/hash/ruby2_keywords_hash_spec.rb @@ -72,12 +72,10 @@ Hash.ruby2_keywords_hash(hash).default_proc.should == pr end - ruby_version_is '3.3' do - it "retains compare_by_identity_flag" do - hash = {}.compare_by_identity - Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true - hash[:a] = 1 - Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true - end + it "retains compare_by_identity_flag" do + hash = {}.compare_by_identity + Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true + hash[:a] = 1 + Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true end end diff --git a/core/io/binread_spec.rb b/core/io/binread_spec.rb index 9e36b84da9..e4576c1aa1 100644 --- a/core/io/binread_spec.rb +++ b/core/io/binread_spec.rb @@ -45,7 +45,7 @@ -> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) end - ruby_version_is "3.3"..."4.0" do + ruby_version_is ""..."4.0" do # https://bugs.ruby-lang.org/issues/19630 it "warns about deprecation given a path with a pipe" do cmd = "|echo ok" diff --git a/core/io/buffer/empty_spec.rb b/core/io/buffer/empty_spec.rb index e1fd4ab6a2..788b23f88f 100644 --- a/core/io/buffer/empty_spec.rb +++ b/core/io/buffer/empty_spec.rb @@ -14,11 +14,9 @@ @buffer.empty?.should be_true end - ruby_version_is "3.3" do - it "is true for a 0-length String-backed buffer created with .string" do - IO::Buffer.string(0) do |buffer| - buffer.empty?.should be_true - end + it "is true for a 0-length String-backed buffer created with .string" do + IO::Buffer.string(0) do |buffer| + buffer.empty?.should be_true end end diff --git a/core/io/buffer/for_spec.rb b/core/io/buffer/for_spec.rb index db299ef10a..d59a2a033a 100644 --- a/core/io/buffer/for_spec.rb +++ b/core/io/buffer/for_spec.rb @@ -23,43 +23,22 @@ -> { @buffer.set_string("d") }.should raise_error(IO::Buffer::AccessError, "Buffer is not writable!") end - ruby_version_is ""..."3.3" do - it "creates an external, read-only buffer" do - @buffer = IO::Buffer.for(@string) - - @buffer.should_not.internal? - @buffer.should_not.mapped? - @buffer.should.external? - - @buffer.should_not.empty? - @buffer.should_not.null? - - @buffer.should_not.shared? - @buffer.should.readonly? - - @buffer.should_not.locked? - @buffer.should.valid? - end - end + it "creates an external, read-only buffer" do + @buffer = IO::Buffer.for(@string) - ruby_version_is "3.3" do - it "creates an external, read-only buffer" do - @buffer = IO::Buffer.for(@string) + @buffer.should_not.internal? + @buffer.should_not.mapped? + @buffer.should.external? - @buffer.should_not.internal? - @buffer.should_not.mapped? - @buffer.should.external? + @buffer.should_not.empty? + @buffer.should_not.null? - @buffer.should_not.empty? - @buffer.should_not.null? + @buffer.should_not.shared? + @buffer.should_not.private? + @buffer.should.readonly? - @buffer.should_not.shared? - @buffer.should_not.private? - @buffer.should.readonly? - - @buffer.should_not.locked? - @buffer.should.valid? - end + @buffer.should_not.locked? + @buffer.should.valid? end end diff --git a/core/io/buffer/free_spec.rb b/core/io/buffer/free_spec.rb index f3a4918978..9a141e11f6 100644 --- a/core/io/buffer/free_spec.rb +++ b/core/io/buffer/free_spec.rb @@ -49,17 +49,15 @@ end end - ruby_version_is "3.3" do - context "with a String-backed buffer created with .string" do - it "disassociates the buffer from the string and nullifies the buffer" do - string = - IO::Buffer.string(4) do |buffer| - buffer.set_string("meat") - buffer.free - buffer.null?.should be_true - end - string.should == "meat" - end + context "with a String-backed buffer created with .string" do + it "disassociates the buffer from the string and nullifies the buffer" do + string = + IO::Buffer.string(4) do |buffer| + buffer.set_string("meat") + buffer.free + buffer.null?.should be_true + end + string.should == "meat" end end diff --git a/core/io/buffer/initialize_spec.rb b/core/io/buffer/initialize_spec.rb index adaa57b2e6..90b501f53d 100644 --- a/core/io/buffer/initialize_spec.rb +++ b/core/io/buffer/initialize_spec.rb @@ -12,37 +12,20 @@ @buffer.each(:U8).should.all? { |_offset, value| value.eql?(0) } end - ruby_version_is ""..."3.3" do - it "creates a buffer with default state" do - @buffer = IO::Buffer.new - - @buffer.should_not.shared? - @buffer.should_not.readonly? - - @buffer.should_not.empty? - @buffer.should_not.null? - - @buffer.should_not.locked? - @buffer.should.valid? - end - end - - ruby_version_is "3.3" do - it "creates a buffer with default state" do - @buffer = IO::Buffer.new + it "creates a buffer with default state" do + @buffer = IO::Buffer.new - @buffer.should_not.external? + @buffer.should_not.external? - @buffer.should_not.shared? - @buffer.should_not.private? - @buffer.should_not.readonly? + @buffer.should_not.shared? + @buffer.should_not.private? + @buffer.should_not.readonly? - @buffer.should_not.empty? - @buffer.should_not.null? + @buffer.should_not.empty? + @buffer.should_not.null? - @buffer.should_not.locked? - @buffer.should.valid? - end + @buffer.should_not.locked? + @buffer.should.valid? end context "with size argument" do @@ -125,22 +108,12 @@ -> { IO::Buffer.new(10, 0) }.should raise_error(IO::Buffer::AllocationError, "Could not allocate buffer!") end - ruby_version_is "3.3" do - it "raises ArgumentError if flags is negative" do - -> { IO::Buffer.new(10, -1) }.should raise_error(ArgumentError, "Flags can't be negative!") - end - end - - ruby_version_is ""..."3.3" do - it "raises IO::Buffer::AllocationError with non-Integer flags" do - -> { IO::Buffer.new(10, 0.0) }.should raise_error(IO::Buffer::AllocationError, "Could not allocate buffer!") - end + it "raises ArgumentError if flags is negative" do + -> { IO::Buffer.new(10, -1) }.should raise_error(ArgumentError, "Flags can't be negative!") end - ruby_version_is "3.3" do - it "raises TypeError with non-Integer flags" do - -> { IO::Buffer.new(10, 0.0) }.should raise_error(TypeError, "not an Integer") - end + it "raises TypeError with non-Integer flags" do + -> { IO::Buffer.new(10, 0.0) }.should raise_error(TypeError, "not an Integer") end end end diff --git a/core/io/buffer/map_spec.rb b/core/io/buffer/map_spec.rb index 85a6961145..d980eb0ae0 100644 --- a/core/io/buffer/map_spec.rb +++ b/core/io/buffer/map_spec.rb @@ -42,45 +42,23 @@ def open_big_file_fixture @buffer.get_string.should == "abcâdef\n".b end - ruby_version_is ""..."3.3" do - it "creates a mapped, external, shared buffer" do - @file = open_fixture - @buffer = IO::Buffer.map(@file) - - @buffer.should_not.internal? - @buffer.should.mapped? - @buffer.should.external? - - @buffer.should_not.empty? - @buffer.should_not.null? - - @buffer.should.shared? - @buffer.should_not.readonly? - - @buffer.should_not.locked? - @buffer.should.valid? - end - end - - ruby_version_is "3.3" do - it "creates a mapped, external, shared buffer" do - @file = open_fixture - @buffer = IO::Buffer.map(@file) + it "creates a mapped, external, shared buffer" do + @file = open_fixture + @buffer = IO::Buffer.map(@file) - @buffer.should_not.internal? - @buffer.should.mapped? - @buffer.should.external? + @buffer.should_not.internal? + @buffer.should.mapped? + @buffer.should.external? - @buffer.should_not.empty? - @buffer.should_not.null? + @buffer.should_not.empty? + @buffer.should_not.null? - @buffer.should.shared? - @buffer.should_not.private? - @buffer.should_not.readonly? + @buffer.should.shared? + @buffer.should_not.private? + @buffer.should_not.readonly? - @buffer.should_not.locked? - @buffer.should.valid? - end + @buffer.should_not.locked? + @buffer.should.valid? end platform_is_not :windows do @@ -317,63 +295,61 @@ def open_big_file_fixture end end - ruby_version_is "3.3" do - context "when PRIVATE is specified" do - it "sets private flag on the buffer, making it freely modifiable" do - @file = open_fixture - @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) + context "when PRIVATE is specified" do + it "sets private flag on the buffer, making it freely modifiable" do + @file = open_fixture + @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) - @buffer.should.private? - @buffer.should_not.shared? - @buffer.should_not.external? + @buffer.should.private? + @buffer.should_not.shared? + @buffer.should_not.external? - @buffer.get_string.should == "abc\xC3\xA2def\n".b - @buffer.set_string("test12345") - @buffer.get_string.should == "test12345".b + @buffer.get_string.should == "abc\xC3\xA2def\n".b + @buffer.set_string("test12345") + @buffer.get_string.should == "test12345".b - @file.read.should == "abcâdef\n" - end + @file.read.should == "abcâdef\n" + end - it "allows mapping read-only files and modifying the buffer" do - @file = File.open("#{__dir__}/../fixtures/read_text.txt", "r") - @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) + it "allows mapping read-only files and modifying the buffer" do + @file = File.open("#{__dir__}/../fixtures/read_text.txt", "r") + @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) - @buffer.should.private? - @buffer.should_not.shared? - @buffer.should_not.external? + @buffer.should.private? + @buffer.should_not.shared? + @buffer.should_not.external? - @buffer.get_string.should == "abc\xC3\xA2def\n".b - @buffer.set_string("test12345") - @buffer.get_string.should == "test12345".b + @buffer.get_string.should == "abc\xC3\xA2def\n".b + @buffer.set_string("test12345") + @buffer.get_string.should == "test12345".b - @file.read.should == "abcâdef\n" - end + @file.read.should == "abcâdef\n" + end - platform_is_not :windows do - it "is not shared across processes" do - file_name = tmp("shared_buffer") - @file = File.open(file_name, "w+") - @file << "I'm private" - @file.rewind - @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) - - IO.popen("-") do |child_pipe| - if child_pipe - # Synchronize on child's output. - child_pipe.readlines.first.chomp.should == @buffer.to_s - @buffer.get_string.should == "I'm private" - - @file.read.should == "I'm private" - else - @buffer.set_string("I'm shared!") - puts @buffer - end - ensure - child_pipe&.close + platform_is_not :windows do + it "is not shared across processes" do + file_name = tmp("shared_buffer") + @file = File.open(file_name, "w+") + @file << "I'm private" + @file.rewind + @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE) + + IO.popen("-") do |child_pipe| + if child_pipe + # Synchronize on child's output. + child_pipe.readlines.first.chomp.should == @buffer.to_s + @buffer.get_string.should == "I'm private" + + @file.read.should == "I'm private" + else + @buffer.set_string("I'm shared!") + puts @buffer end ensure - File.unlink(file_name) + child_pipe&.close end + ensure + File.unlink(file_name) end end end diff --git a/core/io/buffer/null_spec.rb b/core/io/buffer/null_spec.rb index 3fb1144d0e..3a0e7f841b 100644 --- a/core/io/buffer/null_spec.rb +++ b/core/io/buffer/null_spec.rb @@ -14,11 +14,9 @@ @buffer.null?.should be_false end - ruby_version_is "3.3" do - it "is false for a 0-length String-backed buffer created with .string" do - IO::Buffer.string(0) do |buffer| - buffer.null?.should be_false - end + it "is false for a 0-length String-backed buffer created with .string" do + IO::Buffer.string(0) do |buffer| + buffer.null?.should be_false end end diff --git a/core/io/buffer/private_spec.rb b/core/io/buffer/private_spec.rb index c27cfc3958..86b7a7a0d0 100644 --- a/core/io/buffer/private_spec.rb +++ b/core/io/buffer/private_spec.rb @@ -1,25 +1,23 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "IO::Buffer#private?" do - after :each do - @buffer&.free - @buffer = nil - end +describe "IO::Buffer#private?" do + after :each do + @buffer&.free + @buffer = nil + end - it "is true for a buffer created with PRIVATE flag" do - @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL | IO::Buffer::PRIVATE) - @buffer.private?.should be_true - end + it "is true for a buffer created with PRIVATE flag" do + @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL | IO::Buffer::PRIVATE) + @buffer.private?.should be_true + end - it "is false for a buffer created without PRIVATE flag" do - @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL) - @buffer.private?.should be_false - end + it "is false for a buffer created without PRIVATE flag" do + @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL) + @buffer.private?.should be_false + end - it "is false for a null buffer" do - @buffer = IO::Buffer.new(0) - @buffer.private?.should be_false - end + it "is false for a null buffer" do + @buffer = IO::Buffer.new(0) + @buffer.private?.should be_false end end diff --git a/core/io/buffer/resize_spec.rb b/core/io/buffer/resize_spec.rb index 0da3a23356..a5e80439da 100644 --- a/core/io/buffer/resize_spec.rb +++ b/core/io/buffer/resize_spec.rb @@ -44,17 +44,15 @@ end end - ruby_version_is "3.3" do - it "resizes private buffer, discarding excess contents" do - File.open(__FILE__, "r") do |file| - @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE) - @buffer.resize(10) - @buffer.size.should == 10 - @buffer.get_string.should == "require_re" - @buffer.resize(12) - @buffer.size.should == 12 - @buffer.get_string.should == "require_re\0\0" - end + it "resizes private buffer, discarding excess contents" do + File.open(__FILE__, "r") do |file| + @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE) + @buffer.resize(10) + @buffer.size.should == 10 + @buffer.get_string.should == "require_re" + @buffer.resize(12) + @buffer.size.should == 12 + @buffer.get_string.should == "require_re\0\0" end end end @@ -76,12 +74,10 @@ end end - ruby_version_is "3.3" do - context "with a String-backed buffer created with .string" do - it "disallows resizing, raising IO::Buffer::AccessError" do - IO::Buffer.string(4) do |buffer| - -> { buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!") - end + context "with a String-backed buffer created with .string" do + it "disallows resizing, raising IO::Buffer::AccessError" do + IO::Buffer.string(4) do |buffer| + -> { buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!") end end end diff --git a/core/io/buffer/shared/null_and_empty.rb b/core/io/buffer/shared/null_and_empty.rb index c8fe9e5e46..2ff5cf8f41 100644 --- a/core/io/buffer/shared/null_and_empty.rb +++ b/core/io/buffer/shared/null_and_empty.rb @@ -21,11 +21,9 @@ @buffer.send(@method).should be_false end - ruby_version_is "3.3" do - it "is false for a non-empty String-backed buffer created with .string" do - IO::Buffer.string(4) do |buffer| - buffer.send(@method).should be_false - end + it "is false for a non-empty String-backed buffer created with .string" do + IO::Buffer.string(4) do |buffer| + buffer.send(@method).should be_false end end diff --git a/core/io/buffer/string_spec.rb b/core/io/buffer/string_spec.rb index b2786fdb9c..bc7a73075e 100644 --- a/core/io/buffer/string_spec.rb +++ b/core/io/buffer/string_spec.rb @@ -1,64 +1,62 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "IO::Buffer.string" do - it "creates a modifiable buffer for the duration of the block" do - IO::Buffer.string(7) do |buffer| - @buffer = buffer +describe "IO::Buffer.string" do + it "creates a modifiable buffer for the duration of the block" do + IO::Buffer.string(7) do |buffer| + @buffer = buffer - buffer.size.should == 7 - buffer.get_string.should == "\0\0\0\0\0\0\0".b + buffer.size.should == 7 + buffer.get_string.should == "\0\0\0\0\0\0\0".b - buffer.set_string("test") - buffer.get_string.should == "test\0\0\0" - end - @buffer.should.null? + buffer.set_string("test") + buffer.get_string.should == "test\0\0\0" end + @buffer.should.null? + end - it "returns contents of the buffer as a binary string" do - string = - IO::Buffer.string(7) do |buffer| - buffer.set_string("ä test") - end - string.should == "\xC3\xA4 test".b - end + it "returns contents of the buffer as a binary string" do + string = + IO::Buffer.string(7) do |buffer| + buffer.set_string("ä test") + end + string.should == "\xC3\xA4 test".b + end - it "creates an external buffer" do - IO::Buffer.string(8) do |buffer| - buffer.should_not.internal? - buffer.should_not.mapped? - buffer.should.external? + it "creates an external buffer" do + IO::Buffer.string(8) do |buffer| + buffer.should_not.internal? + buffer.should_not.mapped? + buffer.should.external? - buffer.should_not.empty? - buffer.should_not.null? + buffer.should_not.empty? + buffer.should_not.null? - buffer.should_not.shared? - buffer.should_not.private? - buffer.should_not.readonly? + buffer.should_not.shared? + buffer.should_not.private? + buffer.should_not.readonly? - buffer.should_not.locked? - buffer.should.valid? - end + buffer.should_not.locked? + buffer.should.valid? end + end - it "returns an empty string if size is 0" do - string = - IO::Buffer.string(0) do |buffer| - buffer.size.should == 0 - end - string.should == "" - end + it "returns an empty string if size is 0" do + string = + IO::Buffer.string(0) do |buffer| + buffer.size.should == 0 + end + string.should == "" + end - it "raises ArgumentError if size is negative" do - -> { IO::Buffer.string(-1) {} }.should raise_error(ArgumentError, "negative string size (or size too big)") - end + it "raises ArgumentError if size is negative" do + -> { IO::Buffer.string(-1) {} }.should raise_error(ArgumentError, "negative string size (or size too big)") + end - it "raises RangeError if size is too large" do - -> { IO::Buffer.string(2 ** 232) {} }.should raise_error(RangeError, /\Abignum too big to convert into [`']long'\z/) - end + it "raises RangeError if size is too large" do + -> { IO::Buffer.string(2 ** 232) {} }.should raise_error(RangeError, /\Abignum too big to convert into [`']long'\z/) + end - it "raises LocalJumpError if no block is given" do - -> { IO::Buffer.string(7) }.should raise_error(LocalJumpError, "no block given") - end + it "raises LocalJumpError if no block is given" do + -> { IO::Buffer.string(7) }.should raise_error(LocalJumpError, "no block given") end end diff --git a/core/io/buffer/transfer_spec.rb b/core/io/buffer/transfer_spec.rb index cb8c843ff2..5b7b63e333 100644 --- a/core/io/buffer/transfer_spec.rb +++ b/core/io/buffer/transfer_spec.rb @@ -60,17 +60,15 @@ end end - ruby_version_is "3.3" do - context "with a String-backed buffer created with .string" do - it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do - IO::Buffer.string(4) do |buffer| - info = buffer.to_s - @buffer = buffer.transfer - @buffer.to_s.should == info - buffer.null?.should be_true - end - @buffer.null?.should be_false + context "with a String-backed buffer created with .string" do + it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do + IO::Buffer.string(4) do |buffer| + info = buffer.to_s + @buffer = buffer.transfer + @buffer.to_s.should == info + buffer.null?.should be_true end + @buffer.null?.should be_false end end diff --git a/core/io/foreach_spec.rb b/core/io/foreach_spec.rb index 6abe8901ba..28d6fef7ae 100644 --- a/core/io/foreach_spec.rb +++ b/core/io/foreach_spec.rb @@ -47,14 +47,12 @@ end end - ruby_version_is "3.3" do - # https://bugs.ruby-lang.org/issues/19630 - it "warns about deprecation given a path with a pipe" do - cmd = "|echo ok" - -> { - IO.foreach(cmd).to_a - }.should complain(/IO process creation with a leading '\|'/) - end + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.foreach(cmd).to_a + }.should complain(/IO process creation with a leading '\|'/) end end end diff --git a/core/io/gets_spec.rb b/core/io/gets_spec.rb index ca64bf860e..0587fa07c4 100644 --- a/core/io/gets_spec.rb +++ b/core/io/gets_spec.rb @@ -338,23 +338,11 @@ @io.gets.encoding.should == Encoding::BINARY end - ruby_version_is ''...'3.3' do - it "transcodes to internal encoding if the IO object's external encoding is BINARY" do - Encoding.default_external = Encoding::BINARY - Encoding.default_internal = Encoding::UTF_8 - @io = new_io @name, 'r' - @io.set_encoding Encoding::BINARY, Encoding::UTF_8 - @io.gets.encoding.should == Encoding::UTF_8 - end - end - - ruby_version_is '3.3' do - it "ignores the internal encoding if the IO object's external encoding is BINARY" do - Encoding.default_external = Encoding::BINARY - Encoding.default_internal = Encoding::UTF_8 - @io = new_io @name, 'r' - @io.set_encoding Encoding::BINARY, Encoding::UTF_8 - @io.gets.encoding.should == Encoding::BINARY - end + it "ignores the internal encoding if the IO object's external encoding is BINARY" do + Encoding.default_external = Encoding::BINARY + Encoding.default_internal = Encoding::UTF_8 + @io = new_io @name, 'r' + @io.set_encoding Encoding::BINARY, Encoding::UTF_8 + @io.gets.encoding.should == Encoding::BINARY end end diff --git a/core/io/pread_spec.rb b/core/io/pread_spec.rb index dc7bcedf3e..8f7d9b2521 100644 --- a/core/io/pread_spec.rb +++ b/core/io/pread_spec.rb @@ -1,140 +1,138 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' -guard -> { platform_is_not :windows or ruby_version_is "3.3" } do - describe "IO#pread" do - before :each do - @fname = tmp("io_pread.txt") - @contents = "1234567890" - touch(@fname) { |f| f.write @contents } - @file = File.open(@fname, "r+") - end - - after :each do - @file.close - rm_r @fname - end +describe "IO#pread" do + before :each do + @fname = tmp("io_pread.txt") + @contents = "1234567890" + touch(@fname) { |f| f.write @contents } + @file = File.open(@fname, "r+") + end - it "accepts a length, and an offset" do - @file.pread(4, 0).should == "1234" - @file.pread(3, 4).should == "567" - end + after :each do + @file.close + rm_r @fname + end - it "accepts a length, an offset, and an output buffer" do - buffer = +"foo" - @file.pread(3, 4, buffer).should.equal?(buffer) - buffer.should == "567" - end + it "accepts a length, and an offset" do + @file.pread(4, 0).should == "1234" + @file.pread(3, 4).should == "567" + end - it "shrinks the buffer in case of less bytes read" do - buffer = +"foo" - @file.pread(1, 0, buffer) - buffer.should == "1" - end + it "accepts a length, an offset, and an output buffer" do + buffer = +"foo" + @file.pread(3, 4, buffer).should.equal?(buffer) + buffer.should == "567" + end - it "grows the buffer in case of more bytes read" do - buffer = +"foo" - @file.pread(5, 0, buffer) - buffer.should == "12345" - end + it "shrinks the buffer in case of less bytes read" do + buffer = +"foo" + @file.pread(1, 0, buffer) + buffer.should == "1" + end - it "preserves the encoding of the given buffer" do - buffer = ''.encode(Encoding::ISO_8859_1) - @file.pread(10, 0, buffer) + it "grows the buffer in case of more bytes read" do + buffer = +"foo" + @file.pread(5, 0, buffer) + buffer.should == "12345" + end - buffer.encoding.should == Encoding::ISO_8859_1 - end + it "preserves the encoding of the given buffer" do + buffer = ''.encode(Encoding::ISO_8859_1) + @file.pread(10, 0, buffer) - it "does not advance the file pointer" do - @file.pread(4, 0).should == "1234" - @file.read.should == "1234567890" - end + buffer.encoding.should == Encoding::ISO_8859_1 + end - it "ignores the current offset" do - @file.pos = 3 - @file.pread(4, 0).should == "1234" - end + it "does not advance the file pointer" do + @file.pread(4, 0).should == "1234" + @file.read.should == "1234567890" + end - it "returns an empty string for maxlen = 0" do - @file.pread(0, 4).should == "" - end + it "ignores the current offset" do + @file.pos = 3 + @file.pread(4, 0).should == "1234" + end - it "returns a buffer for maxlen = 0 when buffer specified" do - buffer = +"foo" - @file.pread(0, 4, buffer).should.equal?(buffer) - buffer.should == "foo" - end + it "returns an empty string for maxlen = 0" do + @file.pread(0, 4).should == "" + end - it "ignores the offset for maxlen = 0, even if it is out of file bounds" do - @file.pread(0, 400).should == "" - end + it "returns a buffer for maxlen = 0 when buffer specified" do + buffer = +"foo" + @file.pread(0, 4, buffer).should.equal?(buffer) + buffer.should == "foo" + end - it "does not reset the buffer when reading with maxlen = 0" do - buffer = +"foo" - @file.pread(0, 4, buffer) - buffer.should == "foo" + it "ignores the offset for maxlen = 0, even if it is out of file bounds" do + @file.pread(0, 400).should == "" + end - @file.pread(0, 400, buffer) - buffer.should == "foo" - end + it "does not reset the buffer when reading with maxlen = 0" do + buffer = +"foo" + @file.pread(0, 4, buffer) + buffer.should == "foo" - it "converts maxlen to Integer using #to_int" do - maxlen = mock('maxlen') - maxlen.should_receive(:to_int).and_return(4) - @file.pread(maxlen, 0).should == "1234" - end + @file.pread(0, 400, buffer) + buffer.should == "foo" + end - it "converts offset to Integer using #to_int" do - offset = mock('offset') - offset.should_receive(:to_int).and_return(0) - @file.pread(4, offset).should == "1234" - end + it "converts maxlen to Integer using #to_int" do + maxlen = mock('maxlen') + maxlen.should_receive(:to_int).and_return(4) + @file.pread(maxlen, 0).should == "1234" + end - it "converts a buffer to String using to_str" do - buffer = mock('buffer') - buffer.should_receive(:to_str).at_least(1).and_return(+"foo") - @file.pread(4, 0, buffer) - buffer.should_not.is_a?(String) - buffer.to_str.should == "1234" - end + it "converts offset to Integer using #to_int" do + offset = mock('offset') + offset.should_receive(:to_int).and_return(0) + @file.pread(4, offset).should == "1234" + end - it "raises TypeError if maxlen is not an Integer and cannot be coerced into Integer" do - maxlen = Object.new - -> { @file.pread(maxlen, 0) }.should raise_error(TypeError, 'no implicit conversion of Object into Integer') - end + it "converts a buffer to String using to_str" do + buffer = mock('buffer') + buffer.should_receive(:to_str).at_least(1).and_return(+"foo") + @file.pread(4, 0, buffer) + buffer.should_not.is_a?(String) + buffer.to_str.should == "1234" + end - it "raises TypeError if offset is not an Integer and cannot be coerced into Integer" do - offset = Object.new - -> { @file.pread(4, offset) }.should raise_error(TypeError, 'no implicit conversion of Object into Integer') - end + it "raises TypeError if maxlen is not an Integer and cannot be coerced into Integer" do + maxlen = Object.new + -> { @file.pread(maxlen, 0) }.should raise_error(TypeError, 'no implicit conversion of Object into Integer') + end - it "raises ArgumentError for negative values of maxlen" do - -> { @file.pread(-4, 0) }.should raise_error(ArgumentError, 'negative string size (or size too big)') - end + it "raises TypeError if offset is not an Integer and cannot be coerced into Integer" do + offset = Object.new + -> { @file.pread(4, offset) }.should raise_error(TypeError, 'no implicit conversion of Object into Integer') + end - it "raised Errno::EINVAL for negative values of offset" do - -> { @file.pread(4, -1) }.should raise_error(Errno::EINVAL, /Invalid argument/) - end + it "raises ArgumentError for negative values of maxlen" do + -> { @file.pread(-4, 0) }.should raise_error(ArgumentError, 'negative string size (or size too big)') + end - it "raises TypeError if the buffer is not a String and cannot be coerced into String" do - buffer = Object.new - -> { @file.pread(4, 0, buffer) }.should raise_error(TypeError, 'no implicit conversion of Object into String') - end + it "raised Errno::EINVAL for negative values of offset" do + -> { @file.pread(4, -1) }.should raise_error(Errno::EINVAL, /Invalid argument/) + end - it "raises EOFError if end-of-file is reached" do - -> { @file.pread(1, 10) }.should raise_error(EOFError) - end + it "raises TypeError if the buffer is not a String and cannot be coerced into String" do + buffer = Object.new + -> { @file.pread(4, 0, buffer) }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end - it "raises IOError when file is not open in read mode" do - File.open(@fname, "w") do |file| - -> { file.pread(1, 1) }.should raise_error(IOError) - end - end + it "raises EOFError if end-of-file is reached" do + -> { @file.pread(1, 10) }.should raise_error(EOFError) + end - it "raises IOError when file is closed" do - file = File.open(@fname, "r+") - file.close + it "raises IOError when file is not open in read mode" do + File.open(@fname, "w") do |file| -> { file.pread(1, 1) }.should raise_error(IOError) end end + + it "raises IOError when file is closed" do + file = File.open(@fname, "r+") + file.close + -> { file.pread(1, 1) }.should raise_error(IOError) + end end diff --git a/core/io/pwrite_spec.rb b/core/io/pwrite_spec.rb index 2bc508b37d..fd0b6cf380 100644 --- a/core/io/pwrite_spec.rb +++ b/core/io/pwrite_spec.rb @@ -1,69 +1,67 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' -guard -> { platform_is_not :windows or ruby_version_is "3.3" } do - describe "IO#pwrite" do - before :each do - @fname = tmp("io_pwrite.txt") - @file = File.open(@fname, "w+") - end +describe "IO#pwrite" do + before :each do + @fname = tmp("io_pwrite.txt") + @file = File.open(@fname, "w+") + end - after :each do - @file.close - rm_r @fname - end + after :each do + @file.close + rm_r @fname + end - it "returns the number of bytes written" do - @file.pwrite("foo", 0).should == 3 - end + it "returns the number of bytes written" do + @file.pwrite("foo", 0).should == 3 + end - it "accepts a string and an offset" do - @file.pwrite("foo", 2) - @file.pread(3, 2).should == "foo" - end + it "accepts a string and an offset" do + @file.pwrite("foo", 2) + @file.pread(3, 2).should == "foo" + end - it "does not advance the pointer in the file" do - @file.pwrite("bar", 3) - @file.write("foo") - @file.pread(6, 0).should == "foobar" - end + it "does not advance the pointer in the file" do + @file.pwrite("bar", 3) + @file.write("foo") + @file.pread(6, 0).should == "foobar" + end - it "calls #to_s on the object to be written" do - object = mock("to_s") - object.should_receive(:to_s).and_return("foo") - @file.pwrite(object, 0) - @file.pread(3, 0).should == "foo" - end + it "calls #to_s on the object to be written" do + object = mock("to_s") + object.should_receive(:to_s).and_return("foo") + @file.pwrite(object, 0) + @file.pread(3, 0).should == "foo" + end - it "calls #to_int on the offset" do - offset = mock("to_int") - offset.should_receive(:to_int).and_return(2) - @file.pwrite("foo", offset) - @file.pread(3, 2).should == "foo" - end + it "calls #to_int on the offset" do + offset = mock("to_int") + offset.should_receive(:to_int).and_return(2) + @file.pwrite("foo", offset) + @file.pread(3, 2).should == "foo" + end - it "raises IOError when file is not open in write mode" do - File.open(@fname, "r") do |file| - -> { file.pwrite("foo", 1) }.should raise_error(IOError, "not opened for writing") - end + it "raises IOError when file is not open in write mode" do + File.open(@fname, "r") do |file| + -> { file.pwrite("foo", 1) }.should raise_error(IOError, "not opened for writing") end + end - it "raises IOError when file is closed" do - file = File.open(@fname, "w+") - file.close - -> { file.pwrite("foo", 1) }.should raise_error(IOError, "closed stream") - end + it "raises IOError when file is closed" do + file = File.open(@fname, "w+") + file.close + -> { file.pwrite("foo", 1) }.should raise_error(IOError, "closed stream") + end - it "raises a NoMethodError if object does not respond to #to_s" do - -> { - @file.pwrite(BasicObject.new, 0) - }.should raise_error(NoMethodError, /undefined method [`']to_s'/) - end + it "raises a NoMethodError if object does not respond to #to_s" do + -> { + @file.pwrite(BasicObject.new, 0) + }.should raise_error(NoMethodError, /undefined method [`']to_s'/) + end - it "raises a TypeError if the offset cannot be converted to an Integer" do - -> { - @file.pwrite("foo", Object.new) - }.should raise_error(TypeError, "no implicit conversion of Object into Integer") - end + it "raises a TypeError if the offset cannot be converted to an Integer" do + -> { + @file.pwrite("foo", Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") end end diff --git a/core/io/read_spec.rb b/core/io/read_spec.rb index 988ec2ce30..dfb42e09db 100644 --- a/core/io/read_spec.rb +++ b/core/io/read_spec.rb @@ -65,15 +65,6 @@ end platform_is_not :windows do - ruby_version_is ""..."3.3" do - it "uses an :open_args option" do - string = IO.read(@fname, nil, 0, open_args: ["r", nil, {encoding: Encoding::US_ASCII}]) - string.encoding.should == Encoding::US_ASCII - - string = IO.read(@fname, nil, 0, open_args: ["r", nil, {}]) - string.encoding.should == Encoding::UTF_8 - end - end end it "disregards other options if :open_args is given" do @@ -135,18 +126,9 @@ -> { IO.read @fname, -1 }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.3' do - it "raises an Errno::EINVAL when not passed a valid offset" do - -> { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL) - -> { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL) - end - end - - ruby_version_is '3.3' do - it "raises an ArgumentError when not passed a valid offset" do - -> { IO.read @fname, 0, -1 }.should raise_error(ArgumentError) - -> { IO.read @fname, -1, -1 }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when not passed a valid offset" do + -> { IO.read @fname, 0, -1 }.should raise_error(ArgumentError) + -> { IO.read @fname, -1, -1 }.should raise_error(ArgumentError) end it "uses the external encoding specified via the :external_encoding option" do @@ -232,14 +214,12 @@ end end - ruby_version_is "3.3" do - # https://bugs.ruby-lang.org/issues/19630 - it "warns about deprecation" do - cmd = "|echo ok" - -> { - IO.read(cmd) - }.should complain(/IO process creation with a leading '\|'/) - end + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation" do + cmd = "|echo ok" + -> { + IO.read(cmd) + }.should complain(/IO process creation with a leading '\|'/) end end end @@ -322,11 +302,9 @@ -> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError) end - ruby_bug "", ""..."3.3" do - it "raise FrozenError if the output buffer is frozen (2)" do - @io.read - -> { @io.read(1, ''.freeze) }.should raise_error(FrozenError) - end + it "raise FrozenError if the output buffer is frozen (2)" do + @io.read + -> { @io.read(1, ''.freeze) }.should raise_error(FrozenError) end it "consumes zero bytes when reading zero bytes" do diff --git a/core/io/readlines_spec.rb b/core/io/readlines_spec.rb index b4770775d1..07d29ea531 100644 --- a/core/io/readlines_spec.rb +++ b/core/io/readlines_spec.rb @@ -207,14 +207,12 @@ end end - ruby_version_is "3.3" do - # https://bugs.ruby-lang.org/issues/19630 - it "warns about deprecation given a path with a pipe" do - cmd = "|echo ok" - -> { - IO.readlines(cmd) - }.should complain(/IO process creation with a leading '\|'/) - end + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + IO.readlines(cmd) + }.should complain(/IO process creation with a leading '\|'/) end end diff --git a/core/io/shared/readlines.rb b/core/io/shared/readlines.rb index 6c1fa11a59..77eb9cbd65 100644 --- a/core/io/shared/readlines.rb +++ b/core/io/shared/readlines.rb @@ -83,11 +83,9 @@ -> { IO.send(@method, @name, 2**128, &@object) }.should raise_error(RangeError) end - ruby_bug "#18767", ""..."3.3" do - describe "when passed limit" do - it "raises ArgumentError when passed 0 as a limit" do - -> { IO.send(@method, @name, 0, &@object) }.should raise_error(ArgumentError) - end + describe "when passed limit" do + it "raises ArgumentError when passed 0 as a limit" do + -> { IO.send(@method, @name, 0, &@object) }.should raise_error(ArgumentError) end end end diff --git a/core/io/write_spec.rb b/core/io/write_spec.rb index b1cad8fb67..95e6371985 100644 --- a/core/io/write_spec.rb +++ b/core/io/write_spec.rb @@ -227,7 +227,7 @@ end end - ruby_version_is "3.3"..."4.0" do + ruby_version_is ""..."4.0" do # https://bugs.ruby-lang.org/issues/19630 it "warns about deprecation given a path with a pipe" do -> { diff --git a/core/kernel/Integer_spec.rb b/core/kernel/Integer_spec.rb index 74dd3e0dd2..c62b8b0801 100644 --- a/core/kernel/Integer_spec.rb +++ b/core/kernel/Integer_spec.rb @@ -586,19 +586,10 @@ Integer("777", obj).should == 0777 end - # https://bugs.ruby-lang.org/issues/19349 - ruby_version_is ''...'3.3' do - it "ignores the base if it is not an integer and does not respond to #to_i" do - Integer("777", "8").should == 777 - end - end - - ruby_version_is '3.3' do - it "raises a TypeError if it is not an integer and does not respond to #to_i" do - -> { - Integer("777", "8") - }.should raise_error(TypeError, "no implicit conversion of String into Integer") - end + it "raises a TypeError if it is not an integer and does not respond to #to_i" do + -> { + Integer("777", "8") + }.should raise_error(TypeError, "no implicit conversion of String into Integer") end describe "when passed exception: false" do diff --git a/core/kernel/eval_spec.rb b/core/kernel/eval_spec.rb index e027294347..c1136efd69 100644 --- a/core/kernel/eval_spec.rb +++ b/core/kernel/eval_spec.rb @@ -159,22 +159,6 @@ class Object end end - ruby_version_is ""..."3.3" do - it "uses (eval) filename if none is provided" do - eval("__FILE__").should == "(eval)" - eval("__FILE__", binding).should == "(eval)" - eval("__FILE__", binding, "success").should == "success" - eval("eval '__FILE__', binding").should == "(eval)" - eval("eval '__FILE__', binding", binding).should == "(eval)" - eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' - eval("eval '__FILE__', binding, 'success'", binding).should == 'success' - end - - it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do - eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] - end - end - context "parameter forwarding" do it "allows anonymous rest parameter forwarding" do object = Object.new @@ -244,20 +228,18 @@ def foo(a, b:, &block) end end - ruby_version_is "3.3" do - it "uses (eval at __FILE__:__LINE__) if none is provided" do - eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" - eval("__FILE__", binding).should == "(eval at #{__FILE__}:#{__LINE__})" - eval("__FILE__", binding, "success").should == "success" - eval("eval '__FILE__', binding").should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" - eval("eval '__FILE__', binding", binding).should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" - eval("eval '__FILE__', binding", binding, 'success').should == "(eval at success:1)" - eval("eval '__FILE__', binding, 'success'", binding).should == 'success' - end + it "uses (eval at __FILE__:__LINE__) if none is provided" do + eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" + eval("__FILE__", binding).should == "(eval at #{__FILE__}:#{__LINE__})" + eval("__FILE__", binding, "success").should == "success" + eval("eval '__FILE__', binding").should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" + eval("eval '__FILE__', binding", binding).should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" + eval("eval '__FILE__', binding", binding, 'success').should == "(eval at success:1)" + eval("eval '__FILE__', binding, 'success'", binding).should == 'success' + end - it 'uses (eval at __FILE__:__LINE__) for __FILE__ and 1 for __LINE__ with a binding argument' do - eval("[__FILE__, __LINE__]", binding).should == ["(eval at #{__FILE__}:#{__LINE__})", 1] - end + it 'uses (eval at __FILE__:__LINE__) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval at #{__FILE__}:#{__LINE__})", 1] end # Found via Rubinius bug github:#149 it "does not alter the value of __FILE__ in the binding" do diff --git a/core/kernel/lambda_spec.rb b/core/kernel/lambda_spec.rb index 565536ac0d..fa0e17b748 100644 --- a/core/kernel/lambda_spec.rb +++ b/core/kernel/lambda_spec.rb @@ -26,46 +26,6 @@ l.lambda?.should be_true end - ruby_version_is ""..."3.3" do - it "creates a lambda-style Proc if given a literal block via Kernel.public_send" do - suppress_warning do - l = Kernel.public_send(:lambda) { 42 } - l.lambda?.should be_true - end - end - - it "returns the passed Proc if given an existing Proc" do - some_proc = proc {} - l = suppress_warning {lambda(&some_proc)} - l.should equal(some_proc) - l.lambda?.should be_false - end - - it "creates a lambda-style Proc when called with zsuper" do - suppress_warning do - l = KernelSpecs::LambdaSpecs::ForwardBlockWithZSuper.new.lambda { 42 } - l.lambda?.should be_true - l.call.should == 42 - - lambda { l.call(:extra) }.should raise_error(ArgumentError) - end - end - - it "returns the passed Proc if given an existing Proc through super" do - some_proc = proc { } - l = KernelSpecs::LambdaSpecs::SuperAmpersand.new.lambda(&some_proc) - l.should equal(some_proc) - l.lambda?.should be_false - end - - it "does not create lambda-style Procs when captured with #method" do - kernel_lambda = method(:lambda) - l = suppress_warning {kernel_lambda.call { 42 }} - l.lambda?.should be_false - l.call(:extra).should == 42 - end - end - it "checks the arity of the call when no args are specified" do l = lambda { :called } l.call.should == :called @@ -139,16 +99,8 @@ def ret end context "when called without a literal block" do - ruby_version_is ""..."3.3" do - it "warns when proc isn't a lambda" do - -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") - end - end - - ruby_version_is "3.3" do - it "raises when proc isn't a lambda" do - -> { lambda(&proc{}) }.should raise_error(ArgumentError, /the lambda method requires a literal block/) - end + it "raises when proc isn't a lambda" do + -> { lambda(&proc{}) }.should raise_error(ArgumentError, /the lambda method requires a literal block/) end it "doesn't warn when proc is lambda" do diff --git a/core/kernel/open_spec.rb b/core/kernel/open_spec.rb index b967d5044b..9d3f3760b9 100644 --- a/core/kernel/open_spec.rb +++ b/core/kernel/open_spec.rb @@ -79,14 +79,12 @@ end end - ruby_version_is "3.3" do - # https://bugs.ruby-lang.org/issues/19630 - it "warns about deprecation given a path with a pipe" do - cmd = "|echo ok" - -> { - open(cmd) { |f| f.read } - }.should complain(/Kernel#open with a leading '\|'/) - end + # https://bugs.ruby-lang.org/issues/19630 + it "warns about deprecation given a path with a pipe" do + cmd = "|echo ok" + -> { + open(cmd) { |f| f.read } + }.should complain(/Kernel#open with a leading '\|'/) end end diff --git a/core/kernel/shared/require.rb b/core/kernel/shared/require.rb index 52f86f73e5..ef5b9486c6 100644 --- a/core/kernel/shared/require.rb +++ b/core/kernel/shared/require.rb @@ -266,15 +266,13 @@ ScratchPad.recorded.should == [:loaded] end - ruby_bug "#17340", ''...'3.3' do - it "loads a file concurrently" do - path = File.expand_path "concurrent_require_fixture.rb", CODE_LOADING_DIR - ScratchPad.record(@object) - -> { - @object.require(path) - }.should_not complain(/circular require considered harmful/, verbose: true) - ScratchPad.recorded.join - end + it "loads a file concurrently" do + path = File.expand_path "concurrent_require_fixture.rb", CODE_LOADING_DIR + ScratchPad.record(@object) + -> { + @object.require(path) + }.should_not complain(/circular require considered harmful/, verbose: true) + ScratchPad.recorded.join end end diff --git a/core/kernel/sleep_spec.rb b/core/kernel/sleep_spec.rb index e9c600aac4..0b003ad189 100644 --- a/core/kernel/sleep_spec.rb +++ b/core/kernel/sleep_spec.rb @@ -63,27 +63,19 @@ def o.divmod(*); [0, 0.001]; end actual_duration.should > 0.01 # 100 * 0.0001 => 0.01 end - ruby_version_is ""..."3.3" do - it "raises a TypeError when passed nil" do - -> { sleep(nil) }.should raise_error(TypeError) + it "accepts a nil duration" do + running = false + t = Thread.new do + running = true + sleep(nil) + 5 end - end - - ruby_version_is "3.3" do - it "accepts a nil duration" do - running = false - t = Thread.new do - running = true - sleep(nil) - 5 - end - Thread.pass until running - Thread.pass while t.status and t.status != "sleep" + Thread.pass until running + Thread.pass while t.status and t.status != "sleep" - t.wakeup - t.value.should == 5 - end + t.wakeup + t.value.should == 5 end context "Kernel.sleep with Fiber scheduler" do diff --git a/core/marshal/shared/load.rb b/core/marshal/shared/load.rb index 204a4d34e3..692c14cfa1 100644 --- a/core/marshal/shared/load.rb +++ b/core/marshal/shared/load.rb @@ -127,36 +127,32 @@ Object.should_not.frozen? end - ruby_bug "#19427", ""..."3.3" do - it "does freeze extended objects" do - object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", freeze: true) - object.should.frozen? - end + it "does freeze extended objects" do + object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", freeze: true) + object.should.frozen? + end - it "does freeze extended objects with instance variables" do - object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x06:\n@ivarT", freeze: true) - object.should.frozen? - end + it "does freeze extended objects with instance variables" do + object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x06:\n@ivarT", freeze: true) + object.should.frozen? end - ruby_bug "#19427", ""..."3.3" do - it "returns frozen object having #_dump method" do - object = Marshal.send(@method, Marshal.dump(UserDefined.new), freeze: true) - object.should.frozen? - end + it "returns frozen object having #_dump method" do + object = Marshal.send(@method, Marshal.dump(UserDefined.new), freeze: true) + object.should.frozen? + end - it "returns frozen object responding to #marshal_dump and #marshal_load" do - object = Marshal.send(@method, Marshal.dump(UserMarshal.new), freeze: true) - object.should.frozen? - end + it "returns frozen object responding to #marshal_dump and #marshal_load" do + object = Marshal.send(@method, Marshal.dump(UserMarshal.new), freeze: true) + object.should.frozen? + end - it "returns frozen object extended by a module" do - object = Object.new - object.extend(MarshalSpec::ModuleToExtendBy) + it "returns frozen object extended by a module" do + object = Object.new + object.extend(MarshalSpec::ModuleToExtendBy) - object = Marshal.send(@method, Marshal.dump(object), freeze: true) - object.should.frozen? - end + object = Marshal.send(@method, Marshal.dump(object), freeze: true) + object.should.frozen? end it "does not call freeze method" do @@ -239,12 +235,10 @@ string.should.frozen? end - ruby_bug "#19427", ""..."3.3" do - it "call the proc with extended objects" do - objs = [] - obj = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", Proc.new { |o| objs << o; o }) - objs.should == [obj] - end + it "call the proc with extended objects" do + objs = [] + obj = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", Proc.new { |o| objs << o; o }) + objs.should == [obj] end it "returns the value of the proc" do @@ -930,15 +924,13 @@ def io.binmode; raise "binmode"; end [Meths, UserRegexp, Regexp] end - ruby_bug "#19439", ""..."3.3" do - it "restore the regexp instance variables" do - obj = Regexp.new("hello") - obj.instance_variable_set(:@regexp_ivar, [42]) + it "restore the regexp instance variables" do + obj = Regexp.new("hello") + obj.instance_variable_set(:@regexp_ivar, [42]) - new_obj = Marshal.send(@method, "\x04\bI/\nhello\x00\a:\x06EF:\x11@regexp_ivar[\x06i/") - new_obj.instance_variables.should == [:@regexp_ivar] - new_obj.instance_variable_get(:@regexp_ivar).should == [42] - end + new_obj = Marshal.send(@method, "\x04\bI/\nhello\x00\a:\x06EF:\x11@regexp_ivar[\x06i/") + new_obj.instance_variables.should == [:@regexp_ivar] + new_obj.instance_variable_get(:@regexp_ivar).should == [42] end it "preserves Regexp encoding" do diff --git a/core/matchdata/named_captures_spec.rb b/core/matchdata/named_captures_spec.rb index 5e4693d62d..10b1f884d6 100644 --- a/core/matchdata/named_captures_spec.rb +++ b/core/matchdata/named_captures_spec.rb @@ -13,15 +13,13 @@ /\A(?.)(?.)(?.)(?.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' } end - ruby_version_is "3.3" do - it 'returns a Hash with Symbol keys when symbolize_names is provided a true value' do - /(?.)(?.)?/.match('0').named_captures(symbolize_names: true).should == { a: '0', b: nil } - /(?.)(?.)?/.match('0').named_captures(symbolize_names: "truly").should == { a: '0', b: nil } - end + it 'returns a Hash with Symbol keys when symbolize_names is provided a true value' do + /(?.)(?.)?/.match('0').named_captures(symbolize_names: true).should == { a: '0', b: nil } + /(?.)(?.)?/.match('0').named_captures(symbolize_names: "truly").should == { a: '0', b: nil } + end - it 'returns a Hash with String keys when symbolize_names is provided a false value' do - /(?.)(?.)?/.match('02').named_captures(symbolize_names: false).should == { 'a' => '0', 'b' => '2' } - /(?.)(?.)?/.match('02').named_captures(symbolize_names: nil).should == { 'a' => '0', 'b' => '2' } - end + it 'returns a Hash with String keys when symbolize_names is provided a false value' do + /(?.)(?.)?/.match('02').named_captures(symbolize_names: false).should == { 'a' => '0', 'b' => '2' } + /(?.)(?.)?/.match('02').named_captures(symbolize_names: nil).should == { 'a' => '0', 'b' => '2' } end end diff --git a/core/module/set_temporary_name_spec.rb b/core/module/set_temporary_name_spec.rb index 46605ed675..0b96b869c9 100644 --- a/core/module/set_temporary_name_spec.rb +++ b/core/module/set_temporary_name_spec.rb @@ -1,147 +1,145 @@ require_relative '../../spec_helper' require_relative 'fixtures/set_temporary_name' -ruby_version_is "3.3" do - describe "Module#set_temporary_name" do - it "can assign a temporary name" do - m = Module.new - m.name.should be_nil +describe "Module#set_temporary_name" do + it "can assign a temporary name" do + m = Module.new + m.name.should be_nil - m.set_temporary_name("fake_name") - m.name.should == "fake_name" + m.set_temporary_name("fake_name") + m.name.should == "fake_name" - m.set_temporary_name(nil) - m.name.should be_nil - end + m.set_temporary_name(nil) + m.name.should be_nil + end - it "returns self" do - m = Module.new - m.set_temporary_name("fake_name").should.equal? m - end + it "returns self" do + m = Module.new + m.set_temporary_name("fake_name").should.equal? m + end - it "can assign a temporary name which is not a valid constant path" do - m = Module.new + it "can assign a temporary name which is not a valid constant path" do + m = Module.new - m.set_temporary_name("name") - m.name.should == "name" + m.set_temporary_name("name") + m.name.should == "name" - m.set_temporary_name("Template['foo.rb']") - m.name.should == "Template['foo.rb']" + m.set_temporary_name("Template['foo.rb']") + m.name.should == "Template['foo.rb']" - m.set_temporary_name("a::B") - m.name.should == "a::B" + m.set_temporary_name("a::B") + m.name.should == "a::B" - m.set_temporary_name("A::b") - m.name.should == "A::b" + m.set_temporary_name("A::b") + m.name.should == "A::b" - m.set_temporary_name("A::B::") - m.name.should == "A::B::" + m.set_temporary_name("A::B::") + m.name.should == "A::B::" - m.set_temporary_name("A::::B") - m.name.should == "A::::B" + m.set_temporary_name("A::::B") + m.name.should == "A::::B" - m.set_temporary_name("A=") - m.name.should == "A=" - end + m.set_temporary_name("A=") + m.name.should == "A=" + end - it "can't assign empty string as name" do - m = Module.new - -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") - end + it "can't assign empty string as name" do + m = Module.new + -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") + end - it "can't assign a constant name as a temporary name" do - m = Module.new - -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") - end + it "can't assign a constant name as a temporary name" do + m = Module.new + -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + end - it "can't assign a constant path as a temporary name" do - m = Module.new - -> { m.set_temporary_name("A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") - -> { m.set_temporary_name("::A") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") - -> { m.set_temporary_name("::A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") - end + it "can't assign a constant path as a temporary name" do + m = Module.new + -> { m.set_temporary_name("A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + -> { m.set_temporary_name("::A") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + -> { m.set_temporary_name("::A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + end - it "can't assign name to permanent module" do - -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") - end + it "can't assign name to permanent module" do + -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") + end - it "can assign a temporary name to a module nested into an anonymous module" do - m = Module.new - module m::N; end - m::N.name.should =~ /\A#::N\z/ + it "can assign a temporary name to a module nested into an anonymous module" do + m = Module.new + module m::N; end + m::N.name.should =~ /\A#::N\z/ - m::N.set_temporary_name("fake_name") - m::N.name.should == "fake_name" + m::N.set_temporary_name("fake_name") + m::N.name.should == "fake_name" - m::N.set_temporary_name(nil) - m::N.name.should be_nil - end + m::N.set_temporary_name(nil) + m::N.name.should be_nil + end - it "discards a temporary name when an outer anonymous module gets a permanent name" do - m = Module.new - module m::N; end + it "discards a temporary name when an outer anonymous module gets a permanent name" do + m = Module.new + module m::N; end - m::N.set_temporary_name("fake_name") - m::N.name.should == "fake_name" + m::N.set_temporary_name("fake_name") + m::N.name.should == "fake_name" - ModuleSpecs::SetTemporaryNameSpec::M = m - m::N.name.should == "ModuleSpecs::SetTemporaryNameSpec::M::N" - ModuleSpecs::SetTemporaryNameSpec.send :remove_const, :M - end + ModuleSpecs::SetTemporaryNameSpec::M = m + m::N.name.should == "ModuleSpecs::SetTemporaryNameSpec::M::N" + ModuleSpecs::SetTemporaryNameSpec.send :remove_const, :M + end - it "can update the name when assigned to a constant" do - m = Module.new - m::N = Module.new - m::N.name.should =~ /\A#::N\z/ - m::N.set_temporary_name(nil) + it "can update the name when assigned to a constant" do + m = Module.new + m::N = Module.new + m::N.name.should =~ /\A#::N\z/ + m::N.set_temporary_name(nil) - m::M = m::N - m::M.name.should =~ /\A#::M\z/m - end + m::M = m::N + m::M.name.should =~ /\A#::M\z/m + end - it "can reassign a temporary name repeatedly" do - m = Module.new + it "can reassign a temporary name repeatedly" do + m = Module.new - m.set_temporary_name("fake_name") - m.name.should == "fake_name" + m.set_temporary_name("fake_name") + m.name.should == "fake_name" - m.set_temporary_name("fake_name_2") - m.name.should == "fake_name_2" - end + m.set_temporary_name("fake_name_2") + m.name.should == "fake_name_2" + end - ruby_bug "#21094", ""..."4.0" do - it "also updates a name of a nested module" do - m = Module.new - m::N = Module.new - m::N.name.should =~ /\A#::N\z/ + ruby_bug "#21094", ""..."4.0" do + it "also updates a name of a nested module" do + m = Module.new + m::N = Module.new + m::N.name.should =~ /\A#::N\z/ - m.set_temporary_name "m" - m::N.name.should == "m::N" + m.set_temporary_name "m" + m::N.name.should == "m::N" - m.set_temporary_name nil - m::N.name.should == nil - end + m.set_temporary_name nil + m::N.name.should == nil end + end - it "keeps temporary name when assigned in an anonymous module" do - outer = Module.new - m = Module.new - m.set_temporary_name "m" - m.name.should == "m" - outer::M = m - m.name.should == "m" - m.inspect.should == "m" - end + it "keeps temporary name when assigned in an anonymous module" do + outer = Module.new + m = Module.new + m.set_temporary_name "m" + m.name.should == "m" + outer::M = m + m.name.should == "m" + m.inspect.should == "m" + end - it "keeps temporary name when assigned in an anonymous module and nested before" do - outer = Module.new - m = Module.new - outer::A = m - m.set_temporary_name "m" - m.name.should == "m" - outer::M = m - m.name.should == "m" - m.inspect.should == "m" - end + it "keeps temporary name when assigned in an anonymous module and nested before" do + outer = Module.new + m = Module.new + outer::A = m + m.set_temporary_name "m" + m.name.should == "m" + outer::M = m + m.name.should == "m" + m.inspect.should == "m" end end diff --git a/core/module/shared/class_eval.rb b/core/module/shared/class_eval.rb index b1d5cb3814..526d0a2036 100644 --- a/core/module/shared/class_eval.rb +++ b/core/module/shared/class_eval.rb @@ -52,10 +52,8 @@ def foo ModuleSpecs.send(@method, "[__FILE__, __LINE__]", "test", 102).should == ["test", 102] end - ruby_version_is "3.3" do - it "uses the caller location as default filename" do - ModuleSpecs.send(@method, "[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] - end + it "uses the caller location as default filename" do + ModuleSpecs.send(@method, "[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] end it "converts a non-string filename to a string using to_str" do diff --git a/core/nil/singleton_method_spec.rb b/core/nil/singleton_method_spec.rb index 8d898b1cc9..fb47af0c3e 100644 --- a/core/nil/singleton_method_spec.rb +++ b/core/nil/singleton_method_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' describe "NilClass#singleton_method" do - ruby_version_is '3.3' do - it "raises regardless of whether NilClass defines the method" do + it "raises regardless of whether NilClass defines the method" do + -> { nil.singleton_method(:foo) }.should raise_error(NameError) + begin + def (nil).foo; end -> { nil.singleton_method(:foo) }.should raise_error(NameError) - begin - def (nil).foo; end - -> { nil.singleton_method(:foo) }.should raise_error(NameError) - ensure - NilClass.send(:remove_method, :foo) - end + ensure + NilClass.send(:remove_method, :foo) end end end diff --git a/core/numeric/remainder_spec.rb b/core/numeric/remainder_spec.rb index 674fa22d8e..29654310d2 100644 --- a/core/numeric/remainder_spec.rb +++ b/core/numeric/remainder_spec.rb @@ -6,9 +6,7 @@ @obj = NumericSpecs::Subclass.new @result = mock("Numeric#% result") @other = mock("Passed Object") - ruby_version_is "3.3" do - @other.should_receive(:coerce).with(@obj).and_return([@obj, @other]) - end + @other.should_receive(:coerce).with(@obj).and_return([@obj, @other]) end it "returns the result of calling self#% with other if self is 0" do diff --git a/core/objectspace/weakkeymap/clear_spec.rb b/core/objectspace/weakkeymap/clear_spec.rb index 8050e2c307..b1804ec9b0 100644 --- a/core/objectspace/weakkeymap/clear_spec.rb +++ b/core/objectspace/weakkeymap/clear_spec.rb @@ -1,27 +1,25 @@ require_relative '../../../spec_helper' -ruby_version_is '3.3' do - describe "ObjectSpace::WeakKeyMap#clear" do - it "removes all the entries" do - m = ObjectSpace::WeakKeyMap.new +describe "ObjectSpace::WeakKeyMap#clear" do + it "removes all the entries" do + m = ObjectSpace::WeakKeyMap.new - key = Object.new - value = Object.new - m[key] = value + key = Object.new + value = Object.new + m[key] = value - key2 = Object.new - value2 = Object.new - m[key2] = value2 + key2 = Object.new + value2 = Object.new + m[key2] = value2 - m.clear + m.clear - m.key?(key).should == false - m.key?(key2).should == false - end + m.key?(key).should == false + m.key?(key2).should == false + end - it "returns self" do - m = ObjectSpace::WeakKeyMap.new - m.clear.should.equal?(m) - end + it "returns self" do + m = ObjectSpace::WeakKeyMap.new + m.clear.should.equal?(m) end end diff --git a/core/objectspace/weakkeymap/delete_spec.rb b/core/objectspace/weakkeymap/delete_spec.rb index 3cd61355d6..ad32c2c75e 100644 --- a/core/objectspace/weakkeymap/delete_spec.rb +++ b/core/objectspace/weakkeymap/delete_spec.rb @@ -1,51 +1,49 @@ require_relative '../../../spec_helper' -ruby_version_is '3.3' do - describe "ObjectSpace::WeakKeyMap#delete" do - it "removes the entry and returns the deleted value" do - m = ObjectSpace::WeakKeyMap.new - key = Object.new - value = Object.new - m[key] = value - - m.delete(key).should == value - m.key?(key).should == false - end +describe "ObjectSpace::WeakKeyMap#delete" do + it "removes the entry and returns the deleted value" do + m = ObjectSpace::WeakKeyMap.new + key = Object.new + value = Object.new + m[key] = value + + m.delete(key).should == value + m.key?(key).should == false + end - it "uses equality semantic" do - m = ObjectSpace::WeakKeyMap.new - key = "foo".upcase - value = Object.new - m[key] = value + it "uses equality semantic" do + m = ObjectSpace::WeakKeyMap.new + key = "foo".upcase + value = Object.new + m[key] = value - m.delete("foo".upcase).should == value - m.key?(key).should == false - end + m.delete("foo".upcase).should == value + m.key?(key).should == false + end - it "calls supplied block if the key is not found" do - key = Object.new - m = ObjectSpace::WeakKeyMap.new - return_value = m.delete(key) do |yielded_key| - yielded_key.should == key - 5 - end - return_value.should == 5 + it "calls supplied block if the key is not found" do + key = Object.new + m = ObjectSpace::WeakKeyMap.new + return_value = m.delete(key) do |yielded_key| + yielded_key.should == key + 5 end + return_value.should == 5 + end - it "returns nil if the key is not found when no block is given" do - m = ObjectSpace::WeakKeyMap.new - m.delete(Object.new).should == nil - end + it "returns nil if the key is not found when no block is given" do + m = ObjectSpace::WeakKeyMap.new + m.delete(Object.new).should == nil + end - it "returns nil when a key cannot be garbage collected" do - map = ObjectSpace::WeakKeyMap.new + it "returns nil when a key cannot be garbage collected" do + map = ObjectSpace::WeakKeyMap.new - map.delete(1).should == nil - map.delete(1.0).should == nil - map.delete(:a).should == nil - map.delete(true).should == nil - map.delete(false).should == nil - map.delete(nil).should == nil - end + map.delete(1).should == nil + map.delete(1.0).should == nil + map.delete(:a).should == nil + map.delete(true).should == nil + map.delete(false).should == nil + map.delete(nil).should == nil end end diff --git a/core/objectspace/weakkeymap/element_reference_spec.rb b/core/objectspace/weakkeymap/element_reference_spec.rb index 51368e8d3b..53eff79c40 100644 --- a/core/objectspace/weakkeymap/element_reference_spec.rb +++ b/core/objectspace/weakkeymap/element_reference_spec.rb @@ -1,107 +1,105 @@ require_relative '../../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "3.3" do - describe "ObjectSpace::WeakKeyMap#[]" do - it "is faithful to the map's content" do - map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a b].map(&:upcase) - ref1, ref2 = %w[x y] - map[key1] = ref1 - map[key1].should == ref1 - map[key1] = ref1 - map[key1].should == ref1 - map[key2] = ref2 - map[key1].should == ref1 - map[key2].should == ref2 - end - - it "compares keys with #eql? semantics" do - map = ObjectSpace::WeakKeyMap.new - key = [1.0] - map[key] = "x" - map[[1]].should == nil - map[[1.0]].should == "x" - key.should == [1.0] # keep the key alive until here to keep the map entry - - map = ObjectSpace::WeakKeyMap.new - key = [1] - map[key] = "x" - map[[1.0]].should == nil - map[[1]].should == "x" - key.should == [1] # keep the key alive until here to keep the map entry - - map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a a].map(&:upcase) - ref = "x" - map[key1] = ref - map[key2].should == ref - end - - it "compares key via #hash first" do - x = mock('0') - x.should_receive(:hash).and_return(0) - - map = ObjectSpace::WeakKeyMap.new - key = 'foo' - map[key] = :bar - map[x].should == nil - end - - it "does not compare keys with different #hash values via #eql?" do - x = mock('x') - x.should_not_receive(:eql?) - x.stub!(:hash).and_return(0) - - y = mock('y') - y.should_not_receive(:eql?) - y.stub!(:hash).and_return(1) - - map = ObjectSpace::WeakKeyMap.new - map[y] = 1 - map[x].should == nil - end - - it "compares keys with the same #hash value via #eql?" do - x = mock('x') - x.should_receive(:eql?).and_return(true) - x.stub!(:hash).and_return(42) - - y = mock('y') - y.should_not_receive(:eql?) - y.stub!(:hash).and_return(42) - - map = ObjectSpace::WeakKeyMap.new - map[y] = 1 - map[x].should == 1 - end - - it "finds a value via an identical key even when its #eql? isn't reflexive" do - x = mock('x') - x.should_receive(:hash).at_least(1).and_return(42) - x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI. - - map = ObjectSpace::WeakKeyMap.new - map[x] = :x - map[x].should == :x - end - - it "supports keys with private #hash method" do - key = WeakKeyMapSpecs::KeyWithPrivateHash.new - map = ObjectSpace::WeakKeyMap.new - map[key] = 42 - map[key].should == 42 - end - - it "returns nil and does not raise error when a key cannot be garbage collected" do - map = ObjectSpace::WeakKeyMap.new - - map[1].should == nil - map[1.0].should == nil - map[:a].should == nil - map[true].should == nil - map[false].should == nil - map[nil].should == nil - end +describe "ObjectSpace::WeakKeyMap#[]" do + it "is faithful to the map's content" do + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + map[key1] = ref1 + map[key1].should == ref1 + map[key1] = ref1 + map[key1].should == ref1 + map[key2] = ref2 + map[key1].should == ref1 + map[key2].should == ref2 + end + + it "compares keys with #eql? semantics" do + map = ObjectSpace::WeakKeyMap.new + key = [1.0] + map[key] = "x" + map[[1]].should == nil + map[[1.0]].should == "x" + key.should == [1.0] # keep the key alive until here to keep the map entry + + map = ObjectSpace::WeakKeyMap.new + key = [1] + map[key] = "x" + map[[1.0]].should == nil + map[[1]].should == "x" + key.should == [1] # keep the key alive until here to keep the map entry + + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a a].map(&:upcase) + ref = "x" + map[key1] = ref + map[key2].should == ref + end + + it "compares key via #hash first" do + x = mock('0') + x.should_receive(:hash).and_return(0) + + map = ObjectSpace::WeakKeyMap.new + key = 'foo' + map[key] = :bar + map[x].should == nil + end + + it "does not compare keys with different #hash values via #eql?" do + x = mock('x') + x.should_not_receive(:eql?) + x.stub!(:hash).and_return(0) + + y = mock('y') + y.should_not_receive(:eql?) + y.stub!(:hash).and_return(1) + + map = ObjectSpace::WeakKeyMap.new + map[y] = 1 + map[x].should == nil + end + + it "compares keys with the same #hash value via #eql?" do + x = mock('x') + x.should_receive(:eql?).and_return(true) + x.stub!(:hash).and_return(42) + + y = mock('y') + y.should_not_receive(:eql?) + y.stub!(:hash).and_return(42) + + map = ObjectSpace::WeakKeyMap.new + map[y] = 1 + map[x].should == 1 + end + + it "finds a value via an identical key even when its #eql? isn't reflexive" do + x = mock('x') + x.should_receive(:hash).at_least(1).and_return(42) + x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI. + + map = ObjectSpace::WeakKeyMap.new + map[x] = :x + map[x].should == :x + end + + it "supports keys with private #hash method" do + key = WeakKeyMapSpecs::KeyWithPrivateHash.new + map = ObjectSpace::WeakKeyMap.new + map[key] = 42 + map[key].should == 42 + end + + it "returns nil and does not raise error when a key cannot be garbage collected" do + map = ObjectSpace::WeakKeyMap.new + + map[1].should == nil + map[1.0].should == nil + map[:a].should == nil + map[true].should == nil + map[false].should == nil + map[nil].should == nil end end diff --git a/core/objectspace/weakkeymap/element_set_spec.rb b/core/objectspace/weakkeymap/element_set_spec.rb index 8db8d780c7..c480aa661a 100644 --- a/core/objectspace/weakkeymap/element_set_spec.rb +++ b/core/objectspace/weakkeymap/element_set_spec.rb @@ -1,82 +1,80 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "ObjectSpace::WeakKeyMap#[]=" do - def should_accept(map, key, value) - (map[key] = value).should == value - map.should.key?(key) - map[key].should == value - end +describe "ObjectSpace::WeakKeyMap#[]=" do + def should_accept(map, key, value) + (map[key] = value).should == value + map.should.key?(key) + map[key].should == value + end + + it "is correct" do + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + should_accept(map, key1, ref1) + should_accept(map, key1, ref1) + should_accept(map, key2, ref2) + map[key1].should == ref1 + end + + it "requires the keys to implement #hash" do + map = ObjectSpace::WeakKeyMap.new + -> { map[BasicObject.new] = 1 }.should raise_error(NoMethodError, /undefined method [`']hash' for an instance of BasicObject/) + end - it "is correct" do + it "accepts frozen keys or values" do + map = ObjectSpace::WeakKeyMap.new + x = Object.new + should_accept(map, x, true) + should_accept(map, x, false) + should_accept(map, x, 42) + should_accept(map, x, :foo) + + y = Object.new.freeze + should_accept(map, x, y) + should_accept(map, y, x) + end + + it "does not duplicate and freeze String keys (like Hash#[]= does)" do + map = ObjectSpace::WeakKeyMap.new + key = +"a" + map[key] = 1 + + map.getkey("a").should.equal? key + map.getkey("a").should_not.frozen? + + key.should == "a" # keep the key alive until here to keep the map entry + end + + context "a key cannot be garbage collected" do + it "raises ArgumentError when Integer is used as a key" do map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a b].map(&:upcase) - ref1, ref2 = %w[x y] - should_accept(map, key1, ref1) - should_accept(map, key1, ref1) - should_accept(map, key2, ref2) - map[key1].should == ref1 + -> { map[1] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) end - it "requires the keys to implement #hash" do + it "raises ArgumentError when Float is used as a key" do map = ObjectSpace::WeakKeyMap.new - -> { map[BasicObject.new] = 1 }.should raise_error(NoMethodError, /undefined method [`']hash' for an instance of BasicObject/) + -> { map[1.0] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) end - it "accepts frozen keys or values" do + it "raises ArgumentError when Symbol is used as a key" do map = ObjectSpace::WeakKeyMap.new - x = Object.new - should_accept(map, x, true) - should_accept(map, x, false) - should_accept(map, x, 42) - should_accept(map, x, :foo) - - y = Object.new.freeze - should_accept(map, x, y) - should_accept(map, y, x) + -> { map[:a] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) end - it "does not duplicate and freeze String keys (like Hash#[]= does)" do + it "raises ArgumentError when true is used as a key" do map = ObjectSpace::WeakKeyMap.new - key = +"a" - map[key] = 1 - - map.getkey("a").should.equal? key - map.getkey("a").should_not.frozen? - - key.should == "a" # keep the key alive until here to keep the map entry + -> { map[true] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) end - context "a key cannot be garbage collected" do - it "raises ArgumentError when Integer is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[1] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end - - it "raises ArgumentError when Float is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[1.0] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end - - it "raises ArgumentError when Symbol is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[:a] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end - - it "raises ArgumentError when true is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[true] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end - - it "raises ArgumentError when false is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[false] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end + it "raises ArgumentError when false is used as a key" do + map = ObjectSpace::WeakKeyMap.new + -> { map[false] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) + end - it "raises ArgumentError when nil is used as a key" do - map = ObjectSpace::WeakKeyMap.new - -> { map[nil] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) - end + it "raises ArgumentError when nil is used as a key" do + map = ObjectSpace::WeakKeyMap.new + -> { map[nil] = "x" }.should raise_error(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/) end end end diff --git a/core/objectspace/weakkeymap/getkey_spec.rb b/core/objectspace/weakkeymap/getkey_spec.rb index 8a2dbf809d..0c8dec8aea 100644 --- a/core/objectspace/weakkeymap/getkey_spec.rb +++ b/core/objectspace/weakkeymap/getkey_spec.rb @@ -1,28 +1,26 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "ObjectSpace::WeakKeyMap#getkey" do - it "returns the existing equal key" do - map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a a].map(&:upcase) +describe "ObjectSpace::WeakKeyMap#getkey" do + it "returns the existing equal key" do + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a a].map(&:upcase) - map[key1] = true - map.getkey(key2).should equal(key1) - map.getkey("X").should == nil + map[key1] = true + map.getkey(key2).should equal(key1) + map.getkey("X").should == nil - key1.should == "A" # keep the key alive until here to keep the map entry - key2.should == "A" # keep the key alive until here to keep the map entry - end + key1.should == "A" # keep the key alive until here to keep the map entry + key2.should == "A" # keep the key alive until here to keep the map entry + end - it "returns nil when a key cannot be garbage collected" do - map = ObjectSpace::WeakKeyMap.new + it "returns nil when a key cannot be garbage collected" do + map = ObjectSpace::WeakKeyMap.new - map.getkey(1).should == nil - map.getkey(1.0).should == nil - map.getkey(:a).should == nil - map.getkey(true).should == nil - map.getkey(false).should == nil - map.getkey(nil).should == nil - end + map.getkey(1).should == nil + map.getkey(1.0).should == nil + map.getkey(:a).should == nil + map.getkey(true).should == nil + map.getkey(false).should == nil + map.getkey(nil).should == nil end end diff --git a/core/objectspace/weakkeymap/inspect_spec.rb b/core/objectspace/weakkeymap/inspect_spec.rb index 319f050970..b6bb469158 100644 --- a/core/objectspace/weakkeymap/inspect_spec.rb +++ b/core/objectspace/weakkeymap/inspect_spec.rb @@ -1,21 +1,19 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "ObjectSpace::WeakKeyMap#inspect" do - it "only displays size in output" do - map = ObjectSpace::WeakKeyMap.new - key1, key2, key3 = "foo", "bar", "bar" - map.inspect.should =~ /\A\#\z/ - map[key1] = 1 - map.inspect.should =~ /\A\#\z/ - map[key2] = 2 - map.inspect.should =~ /\A\#\z/ - map[key3] = 3 - map.inspect.should =~ /\A\#\z/ +describe "ObjectSpace::WeakKeyMap#inspect" do + it "only displays size in output" do + map = ObjectSpace::WeakKeyMap.new + key1, key2, key3 = "foo", "bar", "bar" + map.inspect.should =~ /\A\#\z/ + map[key1] = 1 + map.inspect.should =~ /\A\#\z/ + map[key2] = 2 + map.inspect.should =~ /\A\#\z/ + map[key3] = 3 + map.inspect.should =~ /\A\#\z/ - key1.should == "foo" # keep the key alive until here to keep the map entry - key2.should == "bar" # keep the key alive until here to keep the map entry - key3.should == "bar" # keep the key alive until here to keep the map entry - end + key1.should == "foo" # keep the key alive until here to keep the map entry + key2.should == "bar" # keep the key alive until here to keep the map entry + key3.should == "bar" # keep the key alive until here to keep the map entry end end diff --git a/core/objectspace/weakkeymap/key_spec.rb b/core/objectspace/weakkeymap/key_spec.rb index a9a2e12432..e0b6866671 100644 --- a/core/objectspace/weakkeymap/key_spec.rb +++ b/core/objectspace/weakkeymap/key_spec.rb @@ -1,44 +1,42 @@ require_relative '../../../spec_helper' -ruby_version_is "3.3" do - describe "ObjectSpace::WeakKeyMap#key?" do - it "recognizes keys in use" do - map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a b].map(&:upcase) - ref1, ref2 = %w[x y] +describe "ObjectSpace::WeakKeyMap#key?" do + it "recognizes keys in use" do + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] - map[key1] = ref1 - map.key?(key1).should == true - map[key1] = ref1 - map.key?(key1).should == true - map[key2] = ref2 - map.key?(key2).should == true - end + map[key1] = ref1 + map.key?(key1).should == true + map[key1] = ref1 + map.key?(key1).should == true + map[key2] = ref2 + map.key?(key2).should == true + end - it "matches using equality semantics" do - map = ObjectSpace::WeakKeyMap.new - key1, key2 = %w[a a].map(&:upcase) - ref = "x" - map[key1] = ref - map.key?(key2).should == true - end + it "matches using equality semantics" do + map = ObjectSpace::WeakKeyMap.new + key1, key2 = %w[a a].map(&:upcase) + ref = "x" + map[key1] = ref + map.key?(key2).should == true + end - it "reports true if the pair exists and the value is nil" do - map = ObjectSpace::WeakKeyMap.new - key = Object.new - map[key] = nil - map.key?(key).should == true - end + it "reports true if the pair exists and the value is nil" do + map = ObjectSpace::WeakKeyMap.new + key = Object.new + map[key] = nil + map.key?(key).should == true + end - it "returns false when a key cannot be garbage collected" do - map = ObjectSpace::WeakKeyMap.new + it "returns false when a key cannot be garbage collected" do + map = ObjectSpace::WeakKeyMap.new - map.key?(1).should == false - map.key?(1.0).should == false - map.key?(:a).should == false - map.key?(true).should == false - map.key?(false).should == false - map.key?(nil).should == false - end + map.key?(1).should == false + map.key?(1.0).should == false + map.key?(:a).should == false + map.key?(true).should == false + map.key?(false).should == false + map.key?(nil).should == false end end diff --git a/core/objectspace/weakmap/delete_spec.rb b/core/objectspace/weakmap/delete_spec.rb index 302de264fb..03beebbb83 100644 --- a/core/objectspace/weakmap/delete_spec.rb +++ b/core/objectspace/weakmap/delete_spec.rb @@ -1,30 +1,28 @@ require_relative '../../../spec_helper' -ruby_version_is '3.3' do - describe "ObjectSpace::WeakMap#delete" do - it "removes the entry and returns the deleted value" do - m = ObjectSpace::WeakMap.new - key = Object.new - value = Object.new - m[key] = value +describe "ObjectSpace::WeakMap#delete" do + it "removes the entry and returns the deleted value" do + m = ObjectSpace::WeakMap.new + key = Object.new + value = Object.new + m[key] = value - m.delete(key).should == value - m.key?(key).should == false - end + m.delete(key).should == value + m.key?(key).should == false + end - it "calls supplied block if the key is not found" do - key = Object.new - m = ObjectSpace::WeakMap.new - return_value = m.delete(key) do |yielded_key| - yielded_key.should == key - 5 - end - return_value.should == 5 + it "calls supplied block if the key is not found" do + key = Object.new + m = ObjectSpace::WeakMap.new + return_value = m.delete(key) do |yielded_key| + yielded_key.should == key + 5 end + return_value.should == 5 + end - it "returns nil if the key is not found when no block is given" do - m = ObjectSpace::WeakMap.new - m.delete(Object.new).should == nil - end + it "returns nil if the key is not found when no block is given" do + m = ObjectSpace::WeakMap.new + m.delete(Object.new).should == nil end end diff --git a/core/proc/clone_spec.rb b/core/proc/clone_spec.rb index 730dc421a8..7d47f2cde5 100644 --- a/core/proc/clone_spec.rb +++ b/core/proc/clone_spec.rb @@ -5,7 +5,7 @@ describe "Proc#clone" do it_behaves_like :proc_dup, :clone - ruby_bug "cloning a frozen proc is broken on Ruby 3.3", "3.3"..."3.4" do + ruby_bug "cloning a frozen proc is broken on Ruby 3.3", ""..."3.4" do it "preserves frozen status" do proc = Proc.new { } proc.freeze @@ -14,17 +14,15 @@ end end - ruby_version_is "3.3" do - it "calls #initialize_clone on subclass" do - obj = ProcSpecs::MyProc2.new(:a, 2) { } - dup = obj.clone + it "calls #initialize_clone on subclass" do + obj = ProcSpecs::MyProc2.new(:a, 2) { } + dup = obj.clone - dup.should_not equal(obj) - dup.class.should == ProcSpecs::MyProc2 + dup.should_not equal(obj) + dup.class.should == ProcSpecs::MyProc2 - dup.first.should == :a - dup.second.should == 2 - dup.initializer.should == :clone - end + dup.first.should == :a + dup.second.should == 2 + dup.initializer.should == :clone end end diff --git a/core/proc/dup_spec.rb b/core/proc/dup_spec.rb index 716357d1f0..bdb7d8ab5a 100644 --- a/core/proc/dup_spec.rb +++ b/core/proc/dup_spec.rb @@ -12,17 +12,15 @@ proc.dup.frozen?.should == false end - ruby_version_is "3.3" do - it "calls #initialize_dup on subclass" do - obj = ProcSpecs::MyProc2.new(:a, 2) { } - dup = obj.dup + it "calls #initialize_dup on subclass" do + obj = ProcSpecs::MyProc2.new(:a, 2) { } + dup = obj.dup - dup.should_not equal(obj) - dup.class.should == ProcSpecs::MyProc2 + dup.should_not equal(obj) + dup.class.should == ProcSpecs::MyProc2 - dup.first.should == :a - dup.second.should == 2 - dup.initializer.should == :dup - end + dup.first.should == :a + dup.second.should == 2 + dup.initializer.should == :dup end end diff --git a/core/proc/lambda_spec.rb b/core/proc/lambda_spec.rb index 5c3c38fc2a..67ee4645cd 100644 --- a/core/proc/lambda_spec.rb +++ b/core/proc/lambda_spec.rb @@ -14,13 +14,6 @@ Proc.new {}.lambda?.should be_false end - ruby_version_is ""..."3.3" do - it "is preserved when passing a Proc with & to the lambda keyword" do - suppress_warning {lambda(&->{})}.lambda?.should be_true - suppress_warning {lambda(&proc{})}.lambda?.should be_false - end - end - it "is preserved when passing a Proc with & to the proc keyword" do proc(&->{}).lambda?.should be_true proc(&proc{}).lambda?.should be_false diff --git a/core/process/argv0_spec.rb b/core/process/argv0_spec.rb index f5aba719e9..9cba382c00 100644 --- a/core/process/argv0_spec.rb +++ b/core/process/argv0_spec.rb @@ -13,10 +13,8 @@ end end - ruby_bug "#19597", ""..."3.3" do - it "returns a frozen object" do - Process.argv0.should.frozen? - end + it "returns a frozen object" do + Process.argv0.should.frozen? end it "returns every time the same object" do diff --git a/core/process/status/bit_and_spec.rb b/core/process/status/bit_and_spec.rb index a805364629..9fd1425a97 100644 --- a/core/process/status/bit_and_spec.rb +++ b/core/process/status/bit_and_spec.rb @@ -17,7 +17,7 @@ end end - ruby_version_is "3.3"..."4.0" do + ruby_version_is ""..."4.0" do it "raises an ArgumentError if mask is negative" do suppress_warning do ruby_exe("exit(0)") diff --git a/core/process/status/right_shift_spec.rb b/core/process/status/right_shift_spec.rb index 355aaf4c95..3eaedf5055 100644 --- a/core/process/status/right_shift_spec.rb +++ b/core/process/status/right_shift_spec.rb @@ -16,7 +16,7 @@ end end - ruby_version_is "3.3"..."4.0" do + ruby_version_is ""..."4.0" do it "raises an ArgumentError if shift value is negative" do suppress_warning do ruby_exe("exit(0)") diff --git a/core/process/warmup_spec.rb b/core/process/warmup_spec.rb index b562d52d22..4530ae222c 100644 --- a/core/process/warmup_spec.rb +++ b/core/process/warmup_spec.rb @@ -1,11 +1,9 @@ require_relative '../../spec_helper' describe "Process.warmup" do - ruby_version_is "3.3" do - # The behavior is entirely implementation specific. - # Other implementations are free to just make it a noop - it "is implemented" do - Process.warmup.should == true - end + # The behavior is entirely implementation specific. + # Other implementations are free to just make it a noop + it "is implemented" do + Process.warmup.should == true end end diff --git a/core/range/case_compare_spec.rb b/core/range/case_compare_spec.rb index c9b253f0a5..7a76487d68 100644 --- a/core/range/case_compare_spec.rb +++ b/core/range/case_compare_spec.rb @@ -11,9 +11,7 @@ it_behaves_like :range_cover_and_include, :=== it_behaves_like :range_cover, :=== - ruby_bug "#19533", ""..."3.3" do - it "returns true on any value if begin and end are both nil" do - (nil..nil).should === 1 - end + it "returns true on any value if begin and end are both nil" do + (nil..nil).should === 1 end end diff --git a/core/range/overlap_spec.rb b/core/range/overlap_spec.rb index 9b6fc13493..3e7d2bdda8 100644 --- a/core/range/overlap_spec.rb +++ b/core/range/overlap_spec.rb @@ -1,89 +1,87 @@ require_relative '../../spec_helper' -ruby_version_is '3.3' do - describe "Range#overlap?" do - it "returns true if other Range overlaps self" do - (0..2).overlap?(1..3).should == true - (1..3).overlap?(0..2).should == true - (0..2).overlap?(0..2).should == true - (0..3).overlap?(1..2).should == true - (1..2).overlap?(0..3).should == true - - ('a'..'c').overlap?('b'..'d').should == true - end - - it "returns false if other Range does not overlap self" do - (0..2).overlap?(3..4).should == false - (0..2).overlap?(-4..-1).should == false - - ('a'..'c').overlap?('d'..'f').should == false - end - - it "raises TypeError when called with non-Range argument" do - -> { - (0..2).overlap?(1) - }.should raise_error(TypeError, "wrong argument type Integer (expected Range)") - end - - it "returns true when beginningless and endless Ranges overlap" do - (0..2).overlap?(..3).should == true - (0..2).overlap?(..1).should == true - (0..2).overlap?(..0).should == true - - (..3).overlap?(0..2).should == true - (..1).overlap?(0..2).should == true - (..0).overlap?(0..2).should == true - - (0..2).overlap?(-1..).should == true - (0..2).overlap?(1..).should == true - (0..2).overlap?(2..).should == true - - (-1..).overlap?(0..2).should == true - (1..).overlap?(0..2).should == true - (2..).overlap?(0..2).should == true - - (0..).overlap?(2..).should == true - (..0).overlap?(..2).should == true - end - - it "returns false when beginningless and endless Ranges do not overlap" do - (0..2).overlap?(..-1).should == false - (0..2).overlap?(3..).should == false - - (..-1).overlap?(0..2).should == false - (3..).overlap?(0..2).should == false - end - - it "returns false when Ranges are not compatible" do - (0..2).overlap?('a'..'d').should == false - end - - it "return false when self is empty" do - (2..0).overlap?(1..3).should == false - (2...2).overlap?(1..3).should == false - (1...1).overlap?(1...1).should == false - (2..0).overlap?(2..0).should == false - - ('c'..'a').overlap?('b'..'d').should == false - ('a'...'a').overlap?('b'..'d').should == false - ('b'...'b').overlap?('b'...'b').should == false - ('c'...'a').overlap?('c'...'a').should == false - end - - it "return false when other Range is empty" do - (1..3).overlap?(2..0).should == false - (1..3).overlap?(2...2).should == false - - ('b'..'d').overlap?('c'..'a').should == false - ('b'..'d').overlap?('c'...'c').should == false - end - - it "takes into account exclusive end" do - (0...2).overlap?(2..4).should == false - (2..4).overlap?(0...2).should == false - - ('a'...'c').overlap?('c'..'e').should == false - ('c'..'e').overlap?('a'...'c').should == false - end +describe "Range#overlap?" do + it "returns true if other Range overlaps self" do + (0..2).overlap?(1..3).should == true + (1..3).overlap?(0..2).should == true + (0..2).overlap?(0..2).should == true + (0..3).overlap?(1..2).should == true + (1..2).overlap?(0..3).should == true + + ('a'..'c').overlap?('b'..'d').should == true + end + + it "returns false if other Range does not overlap self" do + (0..2).overlap?(3..4).should == false + (0..2).overlap?(-4..-1).should == false + + ('a'..'c').overlap?('d'..'f').should == false + end + + it "raises TypeError when called with non-Range argument" do + -> { + (0..2).overlap?(1) + }.should raise_error(TypeError, "wrong argument type Integer (expected Range)") + end + + it "returns true when beginningless and endless Ranges overlap" do + (0..2).overlap?(..3).should == true + (0..2).overlap?(..1).should == true + (0..2).overlap?(..0).should == true + + (..3).overlap?(0..2).should == true + (..1).overlap?(0..2).should == true + (..0).overlap?(0..2).should == true + + (0..2).overlap?(-1..).should == true + (0..2).overlap?(1..).should == true + (0..2).overlap?(2..).should == true + + (-1..).overlap?(0..2).should == true + (1..).overlap?(0..2).should == true + (2..).overlap?(0..2).should == true + + (0..).overlap?(2..).should == true + (..0).overlap?(..2).should == true + end + + it "returns false when beginningless and endless Ranges do not overlap" do + (0..2).overlap?(..-1).should == false + (0..2).overlap?(3..).should == false + + (..-1).overlap?(0..2).should == false + (3..).overlap?(0..2).should == false + end + + it "returns false when Ranges are not compatible" do + (0..2).overlap?('a'..'d').should == false + end + + it "return false when self is empty" do + (2..0).overlap?(1..3).should == false + (2...2).overlap?(1..3).should == false + (1...1).overlap?(1...1).should == false + (2..0).overlap?(2..0).should == false + + ('c'..'a').overlap?('b'..'d').should == false + ('a'...'a').overlap?('b'..'d').should == false + ('b'...'b').overlap?('b'...'b').should == false + ('c'...'a').overlap?('c'...'a').should == false + end + + it "return false when other Range is empty" do + (1..3).overlap?(2..0).should == false + (1..3).overlap?(2...2).should == false + + ('b'..'d').overlap?('c'..'a').should == false + ('b'..'d').overlap?('c'...'c').should == false + end + + it "takes into account exclusive end" do + (0...2).overlap?(2..4).should == false + (2..4).overlap?(0...2).should == false + + ('a'...'c').overlap?('c'..'e').should == false + ('c'..'e').overlap?('a'...'c').should == false end end diff --git a/core/range/reverse_each_spec.rb b/core/range/reverse_each_spec.rb index bf199cdde9..16aaace6af 100644 --- a/core/range/reverse_each_spec.rb +++ b/core/range/reverse_each_spec.rb @@ -1,126 +1,124 @@ require_relative '../../spec_helper' -ruby_version_is "3.3" do - describe "Range#reverse_each" do - it "traverses the Range in reverse order and passes each element to block" do - a = [] - (1..3).reverse_each { |i| a << i } - a.should == [3, 2, 1] - - a = [] - (1...3).reverse_each { |i| a << i } - a.should == [2, 1] - end +describe "Range#reverse_each" do + it "traverses the Range in reverse order and passes each element to block" do + a = [] + (1..3).reverse_each { |i| a << i } + a.should == [3, 2, 1] + + a = [] + (1...3).reverse_each { |i| a << i } + a.should == [2, 1] + end - it "returns self" do - r = (1..3) - r.reverse_each { |x| }.should equal(r) - end + it "returns self" do + r = (1..3) + r.reverse_each { |x| }.should equal(r) + end - it "returns an Enumerator if no block given" do - enum = (1..3).reverse_each - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == [3, 2, 1] - end + it "returns an Enumerator if no block given" do + enum = (1..3).reverse_each + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == [3, 2, 1] + end - it "raises a TypeError for endless Ranges of Integers" do - -> { - (1..).reverse_each.take(3) - }.should raise_error(TypeError, "can't iterate from NilClass") - end + it "raises a TypeError for endless Ranges of Integers" do + -> { + (1..).reverse_each.take(3) + }.should raise_error(TypeError, "can't iterate from NilClass") + end - it "raises a TypeError for endless Ranges of non-Integers" do - -> { - ("a"..).reverse_each.take(3) - }.should raise_error(TypeError, "can't iterate from NilClass") - end + it "raises a TypeError for endless Ranges of non-Integers" do + -> { + ("a"..).reverse_each.take(3) + }.should raise_error(TypeError, "can't iterate from NilClass") + end - context "Integer boundaries" do - it "supports beginningless Ranges" do - (..5).reverse_each.take(3).should == [5, 4, 3] - end + context "Integer boundaries" do + it "supports beginningless Ranges" do + (..5).reverse_each.take(3).should == [5, 4, 3] end + end - context "non-Integer boundaries" do - it "uses #succ to iterate a Range of non-Integer elements" do - y = mock('y') - x = mock('x') + context "non-Integer boundaries" do + it "uses #succ to iterate a Range of non-Integer elements" do + y = mock('y') + x = mock('x') - x.should_receive(:succ).any_number_of_times.and_return(y) - x.should_receive(:<=>).with(y).any_number_of_times.and_return(-1) - x.should_receive(:<=>).with(x).any_number_of_times.and_return(0) - y.should_receive(:<=>).with(x).any_number_of_times.and_return(1) - y.should_receive(:<=>).with(y).any_number_of_times.and_return(0) + x.should_receive(:succ).any_number_of_times.and_return(y) + x.should_receive(:<=>).with(y).any_number_of_times.and_return(-1) + x.should_receive(:<=>).with(x).any_number_of_times.and_return(0) + y.should_receive(:<=>).with(x).any_number_of_times.and_return(1) + y.should_receive(:<=>).with(y).any_number_of_times.and_return(0) - a = [] - (x..y).each { |i| a << i } - a.should == [x, y] - end + a = [] + (x..y).each { |i| a << i } + a.should == [x, y] + end - it "uses #succ to iterate a Range of Strings" do - a = [] - ('A'..'D').reverse_each { |i| a << i } - a.should == ['D','C','B','A'] - end + it "uses #succ to iterate a Range of Strings" do + a = [] + ('A'..'D').reverse_each { |i| a << i } + a.should == ['D','C','B','A'] + end - it "uses #succ to iterate a Range of Symbols" do - a = [] - (:A..:D).reverse_each { |i| a << i } - a.should == [:D, :C, :B, :A] - end + it "uses #succ to iterate a Range of Symbols" do + a = [] + (:A..:D).reverse_each { |i| a << i } + a.should == [:D, :C, :B, :A] + end - it "raises a TypeError when `begin` value does not respond to #succ" do - -> { (Time.now..Time.now).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Time/) - -> { (//..//).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Regexp/) - -> { ([]..[]).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Array/) - end + it "raises a TypeError when `begin` value does not respond to #succ" do + -> { (Time.now..Time.now).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Time/) + -> { (//..//).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Regexp/) + -> { ([]..[]).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Array/) + end - it "does not support beginningless Ranges" do - -> { - (..'a').reverse_each { |x| x } - }.should raise_error(TypeError, /can't iterate from NilClass/) - end + it "does not support beginningless Ranges" do + -> { + (..'a').reverse_each { |x| x } + }.should raise_error(TypeError, /can't iterate from NilClass/) end + end - context "when no block is given" do - describe "returned Enumerator size" do - it "returns the Range size when Range size is finite" do - (1..3).reverse_each.size.should == 3 - (1...3).reverse_each.size.should == 2 + context "when no block is given" do + describe "returned Enumerator size" do + it "returns the Range size when Range size is finite" do + (1..3).reverse_each.size.should == 3 + (1...3).reverse_each.size.should == 2 - (1..3.3).reverse_each.size.should == 3 - (1...3.3).reverse_each.size.should == 3 - end + (1..3.3).reverse_each.size.should == 3 + (1...3.3).reverse_each.size.should == 3 + end - ruby_version_is "3.3"..."3.4" do - it "returns a size when it is not iterable" do - (1.1..3).reverse_each.size.should == 2 - (1.1..3.3).reverse_each.size.should == 3 - (1.1..nil).reverse_each.size.should == Float::INFINITY - (nil..3.3).reverse_each.size.should == Float::INFINITY - (nil..nil).reverse_each.size.should == nil - end + ruby_version_is ""..."3.4" do + it "returns a size when it is not iterable" do + (1.1..3).reverse_each.size.should == 2 + (1.1..3.3).reverse_each.size.should == 3 + (1.1..nil).reverse_each.size.should == Float::INFINITY + (nil..3.3).reverse_each.size.should == Float::INFINITY + (nil..nil).reverse_each.size.should == nil end + end - ruby_version_is "3.4" do - it "raises TypeError when the range is not iterable" do - -> { (1.1..3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Integer/) - -> { (1.1..3.3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Float/) - -> { (1.1..nil).reverse_each.size }.should raise_error(TypeError, /can't iterate from NilClass/) - -> { (nil..3.3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Float/) - -> { (nil..nil).reverse_each.size }.should raise_error(TypeError, /can't iterate from NilClass/) - end + ruby_version_is "3.4" do + it "raises TypeError when the range is not iterable" do + -> { (1.1..3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Integer/) + -> { (1.1..3.3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Float/) + -> { (1.1..nil).reverse_each.size }.should raise_error(TypeError, /can't iterate from NilClass/) + -> { (nil..3.3).reverse_each.size }.should raise_error(TypeError, /can't iterate from Float/) + -> { (nil..nil).reverse_each.size }.should raise_error(TypeError, /can't iterate from NilClass/) end + end - ruby_bug "#20936", "3.4"..."4.0" do - it "returns Infinity when Range size is infinite" do - (..3).reverse_each.size.should == Float::INFINITY - end + ruby_bug "#20936", "3.4"..."4.0" do + it "returns Infinity when Range size is infinite" do + (..3).reverse_each.size.should == Float::INFINITY end + end - it "returns nil when Range size is unknown" do - ('a'..'z').reverse_each.size.should == nil - end + it "returns nil when Range size is unknown" do + ('a'..'z').reverse_each.size.should == nil end end end diff --git a/core/refinement/refined_class_spec.rb b/core/refinement/refined_class_spec.rb index 60a58380cc..b532d9a773 100644 --- a/core/refinement/refined_class_spec.rb +++ b/core/refinement/refined_class_spec.rb @@ -2,11 +2,7 @@ require_relative 'shared/target' describe "Refinement#refined_class" do - ruby_version_is ""..."3.3" do - it_behaves_like :refinement_target, :refined_class - end - - ruby_version_is "3.3"..."3.4" do + ruby_version_is ""..."3.4" do it "has been deprecated in favour of Refinement#target" do refinement_int = nil diff --git a/core/refinement/target_spec.rb b/core/refinement/target_spec.rb index fee9588a96..8bd816aea6 100644 --- a/core/refinement/target_spec.rb +++ b/core/refinement/target_spec.rb @@ -2,7 +2,5 @@ require_relative 'shared/target' describe "Refinement#target" do - ruby_version_is "3.3" do - it_behaves_like :refinement_target, :target - end + it_behaves_like :refinement_target, :target end diff --git a/core/regexp/linear_time_spec.rb b/core/regexp/linear_time_spec.rb index cf9e73c37c..2f3f81ed20 100644 --- a/core/regexp/linear_time_spec.rb +++ b/core/regexp/linear_time_spec.rb @@ -25,9 +25,7 @@ }.should complain(/warning: flags ignored/) end - ruby_version_is "3.3" do - it "returns true for positive lookarounds" do - Regexp.linear_time?(/(?:(?=a*)a)*/).should == true - end + it "returns true for positive lookarounds" do + Regexp.linear_time?(/(?:(?=a*)a)*/).should == true end end diff --git a/core/set/flatten_spec.rb b/core/set/flatten_spec.rb index f2cb3dfa52..b26bc8481a 100644 --- a/core/set/flatten_spec.rb +++ b/core/set/flatten_spec.rb @@ -46,14 +46,4 @@ (set = Set[]) << set -> { set.flatten! }.should raise_error(ArgumentError) end - - version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do - ruby_version_is ""..."4.0" do - context "when Set contains a Set-like object" do - it "flattens self, including Set-like objects" do - Set[SetSpecs::SetLike.new([1])].flatten!.should == Set[1] - end - end - end - end end diff --git a/core/set/merge_spec.rb b/core/set/merge_spec.rb index 0c6ed27670..bf945cdcc0 100644 --- a/core/set/merge_spec.rb +++ b/core/set/merge_spec.rb @@ -23,15 +23,7 @@ end end - ruby_version_is ""..."3.3" do - it "accepts only a single argument" do - -> { Set[].merge([], []) }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)") - end - end - - ruby_version_is "3.3" do - it "accepts multiple arguments" do - Set[:a, :b].merge(Set[:b, :c], [:d]).should == Set[:a, :b, :c, :d] - end + it "accepts multiple arguments" do + Set[:a, :b].merge(Set[:b, :c], [:d]).should == Set[:a, :b, :c, :d] end end diff --git a/core/set/proper_subset_spec.rb b/core/set/proper_subset_spec.rb index fb7848c001..6f99447019 100644 --- a/core/set/proper_subset_spec.rb +++ b/core/set/proper_subset_spec.rb @@ -32,14 +32,4 @@ -> { Set[].proper_subset?("test") }.should raise_error(ArgumentError) -> { Set[].proper_subset?(Object.new) }.should raise_error(ArgumentError) end - - version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do - ruby_version_is ""..."4.0" do - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a proper subset of" do - Set[1, 2, 3].proper_subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true - end - end - end - end end diff --git a/core/set/subset_spec.rb b/core/set/subset_spec.rb index 112bd9b38a..da80d174da 100644 --- a/core/set/subset_spec.rb +++ b/core/set/subset_spec.rb @@ -32,14 +32,4 @@ -> { Set[].subset?("test") }.should raise_error(ArgumentError) -> { Set[].subset?(Object.new) }.should raise_error(ArgumentError) end - - version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do - ruby_version_is ""..."4.0" do - context "when comparing to a Set-like object" do - it "returns true if passed a Set-like object that self is a subset of" do - Set[1, 2, 3].subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true - end - end - end - end end diff --git a/core/string/bytesplice_spec.rb b/core/string/bytesplice_spec.rb index 2c770e340a..cfd9e3ea9a 100644 --- a/core/string/bytesplice_spec.rb +++ b/core/string/bytesplice_spec.rb @@ -57,77 +57,75 @@ -> { s.bytesplice(2, 1, "xxx") }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"") end - ruby_version_is "3.3" do - it "raises IndexError when str_index is less than -bytesize" do - -> { "hello".bytesplice(2, 1, "HELLO", -6, 0) }.should raise_error(IndexError, "index -6 out of string") - end - - it "raises IndexError when str_index is greater than bytesize" do - -> { "hello".bytesplice(2, 1, "HELLO", 6, 0) }.should raise_error(IndexError, "index 6 out of string") - end - - it "raises IndexError for negative str length" do - -> { "abc".bytesplice(0, 1, "", 0, -2) }.should raise_error(IndexError, "negative length -2") - end - - it "replaces with integer str indices" do - "hello".bytesplice(1, 2, "HELLO", -5, 0).should == "hlo" - "hello".bytesplice(1, 2, "HELLO", 0, 0).should == "hlo" - "hello".bytesplice(1, 2, "HELLO", 0, 1).should == "hHlo" - "hello".bytesplice(1, 2, "HELLO", 0, 5).should == "hHELLOlo" - "hello".bytesplice(1, 2, "HELLO", 0, 6).should == "hHELLOlo" - end - - it "raises RangeError when str range left boundary is less than -bytesize" do - -> { "hello".bytesplice(0..1, "HELLO", -6...-6) }.should raise_error(RangeError, "-6...-6 out of range") - end - - it "replaces with str ranges" do - "hello".bytesplice(1..2, "HELLO", -5...-5).should == "hlo" - "hello".bytesplice(1..2, "HELLO", 0...0).should == "hlo" - "hello".bytesplice(1..2, "HELLO", 0..0).should == "hHlo" - "hello".bytesplice(1..2, "HELLO", 0...1).should == "hHlo" - "hello".bytesplice(1..2, "HELLO", 0..1).should == "hHElo" - "hello".bytesplice(1..2, "HELLO", 0..-1).should == "hHELLOlo" - "hello".bytesplice(1..2, "HELLO", 0...5).should == "hHELLOlo" - "hello".bytesplice(1..2, "HELLO", 0...6).should == "hHELLOlo" - end - - it "raises ArgumentError when integer str index is provided without str length argument" do - -> { "hello".bytesplice(0, 1, "xxx", 0) }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2, 3, or 5)") - end - - it "replaces on an empty string with str index/length" do - "".bytesplice(0, 0, "", 0, 0).should == "" - "".bytesplice(0, 0, "xxx", 0, 1).should == "x" - end - - it "mutates self with substring and str index/length" do - s = "hello" - s.bytesplice(2, 1, "xxx", 1, 2).should.equal?(s) - s.should.eql?("hexxlo") - end - - it "raises when string is frozen and str index/length" do - s = "hello".freeze - -> { s.bytesplice(2, 1, "xxx", 0, 1) }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"") - end - - it "replaces on an empty string with str range" do - "".bytesplice(0..0, "", 0..0).should == "" - "".bytesplice(0..0, "xyz", 0..1).should == "xy" - end - - it "mutates self with substring and str range" do - s = "hello" - s.bytesplice(2..2, "xyz", 1..2).should.equal?(s) - s.should.eql?("heyzlo") - end - - it "raises when string is frozen and str range" do - s = "hello".freeze - -> { s.bytesplice(2..2, "yzx", 0..1) }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"") - end + it "raises IndexError when str_index is less than -bytesize" do + -> { "hello".bytesplice(2, 1, "HELLO", -6, 0) }.should raise_error(IndexError, "index -6 out of string") + end + + it "raises IndexError when str_index is greater than bytesize" do + -> { "hello".bytesplice(2, 1, "HELLO", 6, 0) }.should raise_error(IndexError, "index 6 out of string") + end + + it "raises IndexError for negative str length" do + -> { "abc".bytesplice(0, 1, "", 0, -2) }.should raise_error(IndexError, "negative length -2") + end + + it "replaces with integer str indices" do + "hello".bytesplice(1, 2, "HELLO", -5, 0).should == "hlo" + "hello".bytesplice(1, 2, "HELLO", 0, 0).should == "hlo" + "hello".bytesplice(1, 2, "HELLO", 0, 1).should == "hHlo" + "hello".bytesplice(1, 2, "HELLO", 0, 5).should == "hHELLOlo" + "hello".bytesplice(1, 2, "HELLO", 0, 6).should == "hHELLOlo" + end + + it "raises RangeError when str range left boundary is less than -bytesize" do + -> { "hello".bytesplice(0..1, "HELLO", -6...-6) }.should raise_error(RangeError, "-6...-6 out of range") + end + + it "replaces with str ranges" do + "hello".bytesplice(1..2, "HELLO", -5...-5).should == "hlo" + "hello".bytesplice(1..2, "HELLO", 0...0).should == "hlo" + "hello".bytesplice(1..2, "HELLO", 0..0).should == "hHlo" + "hello".bytesplice(1..2, "HELLO", 0...1).should == "hHlo" + "hello".bytesplice(1..2, "HELLO", 0..1).should == "hHElo" + "hello".bytesplice(1..2, "HELLO", 0..-1).should == "hHELLOlo" + "hello".bytesplice(1..2, "HELLO", 0...5).should == "hHELLOlo" + "hello".bytesplice(1..2, "HELLO", 0...6).should == "hHELLOlo" + end + + it "raises ArgumentError when integer str index is provided without str length argument" do + -> { "hello".bytesplice(0, 1, "xxx", 0) }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2, 3, or 5)") + end + + it "replaces on an empty string with str index/length" do + "".bytesplice(0, 0, "", 0, 0).should == "" + "".bytesplice(0, 0, "xxx", 0, 1).should == "x" + end + + it "mutates self with substring and str index/length" do + s = "hello" + s.bytesplice(2, 1, "xxx", 1, 2).should.equal?(s) + s.should.eql?("hexxlo") + end + + it "raises when string is frozen and str index/length" do + s = "hello".freeze + -> { s.bytesplice(2, 1, "xxx", 0, 1) }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"") + end + + it "replaces on an empty string with str range" do + "".bytesplice(0..0, "", 0..0).should == "" + "".bytesplice(0..0, "xyz", 0..1).should == "xy" + end + + it "mutates self with substring and str range" do + s = "hello" + s.bytesplice(2..2, "xyz", 1..2).should.equal?(s) + s.should.eql?("heyzlo") + end + + it "raises when string is frozen and str range" do + s = "hello".freeze + -> { s.bytesplice(2..2, "yzx", 0..1) }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"") end end @@ -201,94 +199,92 @@ result.encoding.should == Encoding::UTF_8 end - ruby_version_is "3.3" do - it "raises IndexError when str_index is out of byte size boundary" do - -> { "こんにちは".bytesplice(3, 3, "こんにちは", -16, 0) }.should raise_error(IndexError, "index -16 out of string") - end - - it "raises IndexError when str_index is not on a codepoint boundary" do - -> { "こんにちは".bytesplice(3, 3, "こんにちは", 1, 0) }.should raise_error(IndexError, "offset 1 does not land on character boundary") - end - - it "raises IndexError when str_length is not matching the codepoint boundary" do - -> { "こんにちは".bytesplice(3, 3, "こんにちは", 0, 1) }.should raise_error(IndexError, "offset 1 does not land on character boundary") - -> { "こんにちは".bytesplice(3, 3, "こんにちは", 0, 2) }.should raise_error(IndexError, "offset 2 does not land on character boundary") - end - - it "replaces with integer str indices" do - "こんにちは".bytesplice(3, 3, "こんにちは", -15, 0).should == "こにちは" - "こんにちは".bytesplice(3, 3, "こんにちは", 0, 0).should == "こにちは" - "こんにちは".bytesplice(3, 3, "こんにちは", 0, 3).should == "ここにちは" - "こんにちは".bytesplice(3, 3, "はは", 3, 3).should == "こはにちは" - "こんにちは".bytesplice(3, 3, "こんにちは", 15, 0).should == "こにちは" - end - - it "replaces with str range" do - "こんにちは".bytesplice(0..2, "こんにちは", -15...-16).should == "んにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 0...0).should == "んにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 3..5).should == "んんにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 3...6).should == "んんにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 3..8).should == "んにんにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 0..-1).should == "こんにちはんにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 0...15).should == "こんにちはんにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 0...18).should == "こんにちはんにちは" - end - - it "treats negative length for str range as 0" do - "こんにちは".bytesplice(0..2, "こんにちは", 0...-100).should == "んにちは" - "こんにちは".bytesplice(0..2, "こんにちは", 3...-100).should == "んにちは" - "こんにちは".bytesplice(0..2, "こんにちは", -15...-100).should == "んにちは" - end - - it "raises when ranges not match codepoint boundaries in str" do - -> { "こんにちは".bytesplice(3...3, "こ", 0..0) }.should raise_error(IndexError, "offset 1 does not land on character boundary") - -> { "こんにちは".bytesplice(3...3, "こ", 0..1) }.should raise_error(IndexError, "offset 2 does not land on character boundary") - # Begin is incorrect - -> { "こんにちは".bytesplice(3...3, "こんにちは", -4..-1) }.should raise_error(IndexError, "offset 11 does not land on character boundary") - -> { "こんにちは".bytesplice(3...3, "こんにちは", -5..-1) }.should raise_error(IndexError, "offset 10 does not land on character boundary") - # End is incorrect - -> { "こんにちは".bytesplice(3...3, "こんにちは", -3..-2) }.should raise_error(IndexError, "offset 14 does not land on character boundary") - -> { "こんにちは".bytesplice(3...3, "こんにちは", -3..-3) }.should raise_error(IndexError, "offset 13 does not land on character boundary") - end - - it "deals with a different encoded argument with str index/length" do - s = "こんにちは" - s.encoding.should == Encoding::UTF_8 - sub = "goodbye" - sub.force_encoding(Encoding::US_ASCII) - - result = s.bytesplice(3, 3, sub, 0, 3) - result.should == "こgooにちは" - result.encoding.should == Encoding::UTF_8 - - s = "hello" - s.force_encoding(Encoding::US_ASCII) - sub = "こんにちは" - sub.encoding.should == Encoding::UTF_8 - - result = s.bytesplice(1, 2, sub, 3, 3) - result.should == "hんlo" - result.encoding.should == Encoding::UTF_8 - end - - it "deals with a different encoded argument with str range" do - s = "こんにちは" - s.encoding.should == Encoding::UTF_8 - sub = "goodbye" - sub.force_encoding(Encoding::US_ASCII) - - result = s.bytesplice(3..5, sub, 0..2) - result.should == "こgooにちは" - result.encoding.should == Encoding::UTF_8 - - s = "hello" - s.force_encoding(Encoding::US_ASCII) - sub = "こんにちは" - sub.encoding.should == Encoding::UTF_8 - - result = s.bytesplice(1..2, sub, 3..5) - result.should == "hんlo" - result.encoding.should == Encoding::UTF_8 - end + it "raises IndexError when str_index is out of byte size boundary" do + -> { "こんにちは".bytesplice(3, 3, "こんにちは", -16, 0) }.should raise_error(IndexError, "index -16 out of string") + end + + it "raises IndexError when str_index is not on a codepoint boundary" do + -> { "こんにちは".bytesplice(3, 3, "こんにちは", 1, 0) }.should raise_error(IndexError, "offset 1 does not land on character boundary") + end + + it "raises IndexError when str_length is not matching the codepoint boundary" do + -> { "こんにちは".bytesplice(3, 3, "こんにちは", 0, 1) }.should raise_error(IndexError, "offset 1 does not land on character boundary") + -> { "こんにちは".bytesplice(3, 3, "こんにちは", 0, 2) }.should raise_error(IndexError, "offset 2 does not land on character boundary") + end + + it "replaces with integer str indices" do + "こんにちは".bytesplice(3, 3, "こんにちは", -15, 0).should == "こにちは" + "こんにちは".bytesplice(3, 3, "こんにちは", 0, 0).should == "こにちは" + "こんにちは".bytesplice(3, 3, "こんにちは", 0, 3).should == "ここにちは" + "こんにちは".bytesplice(3, 3, "はは", 3, 3).should == "こはにちは" + "こんにちは".bytesplice(3, 3, "こんにちは", 15, 0).should == "こにちは" + end + + it "replaces with str range" do + "こんにちは".bytesplice(0..2, "こんにちは", -15...-16).should == "んにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 0...0).should == "んにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 3..5).should == "んんにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 3...6).should == "んんにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 3..8).should == "んにんにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 0..-1).should == "こんにちはんにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 0...15).should == "こんにちはんにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 0...18).should == "こんにちはんにちは" + end + + it "treats negative length for str range as 0" do + "こんにちは".bytesplice(0..2, "こんにちは", 0...-100).should == "んにちは" + "こんにちは".bytesplice(0..2, "こんにちは", 3...-100).should == "んにちは" + "こんにちは".bytesplice(0..2, "こんにちは", -15...-100).should == "んにちは" + end + + it "raises when ranges not match codepoint boundaries in str" do + -> { "こんにちは".bytesplice(3...3, "こ", 0..0) }.should raise_error(IndexError, "offset 1 does not land on character boundary") + -> { "こんにちは".bytesplice(3...3, "こ", 0..1) }.should raise_error(IndexError, "offset 2 does not land on character boundary") + # Begin is incorrect + -> { "こんにちは".bytesplice(3...3, "こんにちは", -4..-1) }.should raise_error(IndexError, "offset 11 does not land on character boundary") + -> { "こんにちは".bytesplice(3...3, "こんにちは", -5..-1) }.should raise_error(IndexError, "offset 10 does not land on character boundary") + # End is incorrect + -> { "こんにちは".bytesplice(3...3, "こんにちは", -3..-2) }.should raise_error(IndexError, "offset 14 does not land on character boundary") + -> { "こんにちは".bytesplice(3...3, "こんにちは", -3..-3) }.should raise_error(IndexError, "offset 13 does not land on character boundary") + end + + it "deals with a different encoded argument with str index/length" do + s = "こんにちは" + s.encoding.should == Encoding::UTF_8 + sub = "goodbye" + sub.force_encoding(Encoding::US_ASCII) + + result = s.bytesplice(3, 3, sub, 0, 3) + result.should == "こgooにちは" + result.encoding.should == Encoding::UTF_8 + + s = "hello" + s.force_encoding(Encoding::US_ASCII) + sub = "こんにちは" + sub.encoding.should == Encoding::UTF_8 + + result = s.bytesplice(1, 2, sub, 3, 3) + result.should == "hんlo" + result.encoding.should == Encoding::UTF_8 + end + + it "deals with a different encoded argument with str range" do + s = "こんにちは" + s.encoding.should == Encoding::UTF_8 + sub = "goodbye" + sub.force_encoding(Encoding::US_ASCII) + + result = s.bytesplice(3..5, sub, 0..2) + result.should == "こgooにちは" + result.encoding.should == Encoding::UTF_8 + + s = "hello" + s.force_encoding(Encoding::US_ASCII) + sub = "こんにちは" + sub.encoding.should == Encoding::UTF_8 + + result = s.bytesplice(1..2, sub, 3..5) + result.should == "hんlo" + result.encoding.should == Encoding::UTF_8 end end diff --git a/core/string/index_spec.rb b/core/string/index_spec.rb index 835263a2cd..01e6a6a400 100644 --- a/core/string/index_spec.rb +++ b/core/string/index_spec.rb @@ -231,15 +231,13 @@ $~.should == nil end - ruby_bug "#20421", ""..."3.3" do - it "always clear $~" do - "a".index(/a/) - $~.should_not == nil - - string = "blablabla" - string.index(/bla/, string.length + 1) - $~.should == nil - end + it "always clear $~" do + "a".index(/a/) + $~.should_not == nil + + string = "blablabla" + string.index(/bla/, string.length + 1) + $~.should == nil end it "starts the search at the given offset" do @@ -330,21 +328,10 @@ "われわわれ".index(/わ/, 3).should == 3 end - ruby_bug "#19763", ""..."3.3.0" do - it "raises an Encoding::CompatibilityError if the encodings are incompatible" do - re = Regexp.new "れ".encode(Encoding::EUC_JP) - -> do - "あれ".index re - end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") - end - end - - # The exception message was incorrectly "incompatible character encodings: UTF-8 and EUC-JP" before 3.3.0 - # Still test that the right exception class is used before that. it "raises an Encoding::CompatibilityError if the encodings are incompatible" do re = Regexp.new "れ".encode(Encoding::EUC_JP) -> do "あれ".index re - end.should raise_error(Encoding::CompatibilityError) + end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") end end diff --git a/core/string/start_with_spec.rb b/core/string/start_with_spec.rb index 35e33b46a6..8b0ba6b5a7 100644 --- a/core/string/start_with_spec.rb +++ b/core/string/start_with_spec.rb @@ -11,17 +11,8 @@ "\xA9".should.start_with?("\xA9") # A9 is not a character head for UTF-8 end - ruby_version_is ""..."3.3" do - it "does not check we are matching only part of a character" do - "\xe3\x81\x82".size.should == 1 - "\xe3\x81\x82".should.start_with?("\xe3") - end - end - - ruby_version_is "3.3" do # #19784 - it "checks we are matching only part of a character" do - "\xe3\x81\x82".size.should == 1 - "\xe3\x81\x82".should_not.start_with?("\xe3") - end + it "checks we are matching only part of a character" do + "\xe3\x81\x82".size.should == 1 + "\xe3\x81\x82".should_not.start_with?("\xe3") end end diff --git a/core/string/tr_s_spec.rb b/core/string/tr_s_spec.rb index dd72da440c..693ff8ace2 100644 --- a/core/string/tr_s_spec.rb +++ b/core/string/tr_s_spec.rb @@ -18,13 +18,11 @@ "hello ^--^".tr_s("---", "_").should == "hello ^_^" end - ruby_bug "#19769", ""..."3.3" do - it "accepts c1-c1 notation to denote range of one character" do - "hello".tr_s('e-e', 'x').should == "hxllo" - "123456789".tr_s("2-23","xy").should == "1xy456789" - "hello ^-^".tr_s("e-", "a-a_").should == "hallo ^_^" - "hello ^-^".tr_s("---o", "_a").should == "hella ^_^" - end + it "accepts c1-c1 notation to denote range of one character" do + "hello".tr_s('e-e', 'x').should == "hxllo" + "123456789".tr_s("2-23","xy").should == "1xy456789" + "hello ^-^".tr_s("e-", "a-a_").should == "hallo ^_^" + "hello ^-^".tr_s("---o", "_a").should == "hella ^_^" end it "pads to_str with its last char if it is shorter than from_string" do diff --git a/core/string/tr_spec.rb b/core/string/tr_spec.rb index 75841a974f..8478ccc9d2 100644 --- a/core/string/tr_spec.rb +++ b/core/string/tr_spec.rb @@ -17,13 +17,11 @@ "hello ^-^".tr("---", "_").should == "hello ^_^" end - ruby_bug "#19769", ""..."3.3" do - it "accepts c1-c1 notation to denote range of one character" do - "hello".tr('e-e', 'x').should == "hxllo" - "123456789".tr("2-23","xy").should == "1xy456789" - "hello ^-^".tr("e-", "a-a_").should == "hallo ^_^" - "hello ^-^".tr("---o", "_a").should == "hella ^_^" - end + it "accepts c1-c1 notation to denote range of one character" do + "hello".tr('e-e', 'x').should == "hxllo" + "123456789".tr("2-23","xy").should == "1xy456789" + "hello ^-^".tr("e-", "a-a_").should == "hallo ^_^" + "hello ^-^".tr("---o", "_a").should == "hella ^_^" end it "pads to_str with its last char if it is shorter than from_string" do diff --git a/core/string/unpack/b_spec.rb b/core/string/unpack/b_spec.rb index b088f901fc..70ea1cb6ad 100644 --- a/core/string/unpack/b_spec.rb +++ b/core/string/unpack/b_spec.rb @@ -86,20 +86,10 @@ ].should be_computed_by(:unpack, "BBB") end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x80\x00".unpack("B\x00B").should == ["1", "0"] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x80\x00".unpack("B\x00B") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x80\x00".unpack("B\x00B") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -194,20 +184,10 @@ ].should be_computed_by(:unpack, "bbb") end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x01\x00".unpack("b\x00b").should == ["1", "0"] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x01\x00".unpack("b\x00b") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x00".unpack("b\x00b") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/c_spec.rb b/core/string/unpack/c_spec.rb index 1e9548fb82..e42b027c7b 100644 --- a/core/string/unpack/c_spec.rb +++ b/core/string/unpack/c_spec.rb @@ -35,20 +35,10 @@ ].should be_computed_by(:unpack, unpack_format(3)) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "abc".unpack(unpack_format("\000", 2)).should == [97, 98] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "abc".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "abc".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/h_spec.rb b/core/string/unpack/h_spec.rb index 535836087d..130b36401a 100644 --- a/core/string/unpack/h_spec.rb +++ b/core/string/unpack/h_spec.rb @@ -56,20 +56,10 @@ ].should be_computed_by(:unpack, "HHH") end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x01\x10".unpack("H\x00H").should == ["0", "1"] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x01\x10".unpack("H\x00H") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x10".unpack("H\x00H") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -133,20 +123,10 @@ ].should be_computed_by(:unpack, "hhh") end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x01\x10".unpack("h\x00h").should == ["1", "0"] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x01\x10".unpack("h\x00h") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x10".unpack("h\x00h") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/shared/basic.rb b/core/string/unpack/shared/basic.rb index 734630bda0..132c4ef08a 100644 --- a/core/string/unpack/shared/basic.rb +++ b/core/string/unpack/shared/basic.rb @@ -9,20 +9,10 @@ "abc".unpack(d).should be_an_instance_of(Array) end - ruby_version_is ""..."3.3" do - it "warns about using an unknown directive" do - -> { "abcdefgh".unpack("a R" + unpack_format) }.should complain(/unknown unpack directive 'R' in 'a R#{unpack_format}'/) - -> { "abcdefgh".unpack("a 0" + unpack_format) }.should complain(/unknown unpack directive '0' in 'a 0#{unpack_format}'/) - -> { "abcdefgh".unpack("a :" + unpack_format) }.should complain(/unknown unpack directive ':' in 'a :#{unpack_format}'/) - end - end - - ruby_version_is "3.3" do - it "raises ArgumentError when a directive is unknown" do - -> { "abcdefgh".unpack("a K" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'") - -> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'") - -> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'") - end + it "raises ArgumentError when a directive is unknown" do + -> { "abcdefgh".unpack("a K" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'") + -> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'") + -> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'") end end diff --git a/core/string/unpack/shared/float.rb b/core/string/unpack/shared/float.rb index b31c2c8bdc..0133be2ecb 100644 --- a/core/string/unpack/shared/float.rb +++ b/core/string/unpack/shared/float.rb @@ -56,21 +56,10 @@ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -135,21 +124,10 @@ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -217,20 +195,10 @@ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -297,20 +265,10 @@ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/shared/integer.rb b/core/string/unpack/shared/integer.rb index d3934753ba..eb99456225 100644 --- a/core/string/unpack/shared/integer.rb +++ b/core/string/unpack/shared/integer.rb @@ -32,20 +32,10 @@ ].should be_computed_by(:unpack, unpack_format(3)) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "abcd".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "abcd".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -97,20 +87,10 @@ ].should be_computed_by(:unpack, unpack_format(3)) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "badc".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "badc".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -163,20 +143,10 @@ ].should be_computed_by(:unpack, unpack_format(3)) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "abcdefgh".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "abcdefgh".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -229,20 +199,10 @@ ].should be_computed_by(:unpack, unpack_format(3)) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "dcbahgfe".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "dcbahgfe".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -291,21 +251,10 @@ "abc".unpack(unpack_format('*')).should == [] end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - array = "abcdefghabghefcd".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "badc".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "badc".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -365,21 +314,10 @@ "abc".unpack(unpack_format('*')).should == [] end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/shared/unicode.rb b/core/string/unpack/shared/unicode.rb index 9fe07f53ae..b056aaed0b 100644 --- a/core/string/unpack/shared/unicode.rb +++ b/core/string/unpack/shared/unicode.rb @@ -50,20 +50,10 @@ "\xc2\x80".unpack("UUUU").should == [0x80] end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x01\x02".unpack("U\x00U").should == [1, 2] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x01\x02".unpack("U\x00U") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x02".unpack("U\x00U") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/string/unpack/w_spec.rb b/core/string/unpack/w_spec.rb index 7d3533ccae..d2ad657b09 100644 --- a/core/string/unpack/w_spec.rb +++ b/core/string/unpack/w_spec.rb @@ -15,20 +15,10 @@ ].should be_computed_by(:unpack, "w") end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - "\x01\x02\x03".unpack("w\x00w").should == [1, 2] - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - "\x01\x02\x03".unpack("w\x00w") - }.should raise_error(ArgumentError, /unknown unpack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x02\x03".unpack("w\x00w") + }.should raise_error(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/core/struct/new_spec.rb b/core/struct/new_spec.rb index 1d35de7b87..741d6889af 100644 --- a/core/struct/new_spec.rb +++ b/core/struct/new_spec.rb @@ -77,18 +77,10 @@ def obj.to_str() "Foo" end -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError) end - ruby_version_is ""..."3.3" do - it "raises ArgumentError if not provided any arguments" do - -> { Struct.new }.should raise_error(ArgumentError) - end - end - - ruby_version_is "3.3" do - it "works when not provided any arguments" do - c = Struct.new - c.should be_kind_of(Class) - c.superclass.should == Struct - end + it "works when not provided any arguments" do + c = Struct.new + c.should be_kind_of(Class) + c.superclass.should == Struct end it "raises ArgumentError when there is a duplicate member" do diff --git a/core/symbol/inspect_spec.rb b/core/symbol/inspect_spec.rb index 3b14959bfb..f2269996af 100644 --- a/core/symbol/inspect_spec.rb +++ b/core/symbol/inspect_spec.rb @@ -115,12 +115,10 @@ sym.inspect.should == ':"foo\xA4"' end - ruby_version_is "3.3" do # Ruby 3.2 has Encoding#replicate which can break this - it "quotes symbols in non-ASCII-compatible encodings" do - Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |encoding| - sym = "foo".encode(encoding).to_sym - sym.inspect.should == ':"foo"' - end + it "quotes symbols in non-ASCII-compatible encodings" do + Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |encoding| + sym = "foo".encode(encoding).to_sym + sym.inspect.should == ':"foo"' end end diff --git a/core/thread/native_thread_id_spec.rb b/core/thread/native_thread_id_spec.rb index 374cc59279..65d1b5b318 100644 --- a/core/thread/native_thread_id_spec.rb +++ b/core/thread/native_thread_id_spec.rb @@ -18,12 +18,8 @@ main_thread_id = Thread.current.native_thread_id t_thread_id = t.native_thread_id - if ruby_version_is "3.3" - # native_thread_id can be nil on a M:N scheduler - t_thread_id.should be_kind_of(Integer) if t_thread_id != nil - else - t_thread_id.should be_kind_of(Integer) - end + # native_thread_id can be nil on a M:N scheduler + t_thread_id.should be_kind_of(Integer) if t_thread_id != nil main_thread_id.should_not == t_thread_id diff --git a/core/time/new_spec.rb b/core/time/new_spec.rb index dc3ccbdc00..f3b5d01420 100644 --- a/core/time/new_spec.rb +++ b/core/time/new_spec.rb @@ -554,20 +554,10 @@ def obj.to_int; 3; end Time.new("2020-12-25T00:56:17.123456789876 +09:00").subsec.should == 0.123456789 end - ruby_version_is ""..."3.3" do - it "raise TypeError is can't convert precision keyword argument into Integer" do - -> { - Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "") - }.should raise_error(TypeError, "no implicit conversion from string") - end - end - - ruby_version_is "3.3" do - it "raise TypeError is can't convert precision keyword argument into Integer" do - -> { - Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "") - }.should raise_error(TypeError, "no implicit conversion of String into Integer") - end + it "raise TypeError is can't convert precision keyword argument into Integer" do + -> { + Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "") + }.should raise_error(TypeError, "no implicit conversion of String into Integer") end it "raises ArgumentError if part of time string is missing" do diff --git a/core/tracepoint/path_spec.rb b/core/tracepoint/path_spec.rb index dc2ca840b8..aa6868ead2 100644 --- a/core/tracepoint/path_spec.rb +++ b/core/tracepoint/path_spec.rb @@ -13,29 +13,14 @@ path.should == "#{__FILE__}" end - ruby_version_is ""..."3.3" do - it 'equals (eval) inside an eval for :end event' do - path = nil - TracePoint.new(:end) { |tp| - next unless TracePointSpec.target_thread? - path = tp.path - }.enable do - eval("module TracePointSpec; end") - end - path.should == '(eval)' - end - end - - ruby_version_is "3.3" do - it 'equals "(eval at __FILE__:__LINE__)" inside an eval for :end event' do - path = nil - TracePoint.new(:end) { |tp| - next unless TracePointSpec.target_thread? - path = tp.path - }.enable do - eval("module TracePointSpec; end") - end - path.should == "(eval at #{__FILE__}:#{__LINE__ - 2})" + it 'equals "(eval at __FILE__:__LINE__)" inside an eval for :end event' do + path = nil + TracePoint.new(:end) { |tp| + next unless TracePointSpec.target_thread? + path = tp.path + }.enable do + eval("module TracePointSpec; end") end + path.should == "(eval at #{__FILE__}:#{__LINE__ - 2})" end end diff --git a/core/tracepoint/raised_exception_spec.rb b/core/tracepoint/raised_exception_spec.rb index 5ac8531840..e74afa9abc 100644 --- a/core/tracepoint/raised_exception_spec.rb +++ b/core/tracepoint/raised_exception_spec.rb @@ -18,21 +18,19 @@ end end - ruby_version_is "3.3" do - it 'returns value from exception rescued on the :rescue event' do - raised_exception, error_result = nil - trace = TracePoint.new(:rescue) { |tp| - next unless TracePointSpec.target_thread? - raised_exception = tp.raised_exception - } - trace.enable do - begin - raise StandardError - rescue => e - error_result = e - end - raised_exception.should equal(error_result) + it 'returns value from exception rescued on the :rescue event' do + raised_exception, error_result = nil + trace = TracePoint.new(:rescue) { |tp| + next unless TracePointSpec.target_thread? + raised_exception = tp.raised_exception + } + trace.enable do + begin + raise StandardError + rescue => e + error_result = e end + raised_exception.should equal(error_result) end end end diff --git a/core/true/singleton_method_spec.rb b/core/true/singleton_method_spec.rb index c06793850f..575c504b72 100644 --- a/core/true/singleton_method_spec.rb +++ b/core/true/singleton_method_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' describe "TrueClass#singleton_method" do - ruby_version_is '3.3' do - it "raises regardless of whether TrueClass defines the method" do + it "raises regardless of whether TrueClass defines the method" do + -> { true.singleton_method(:foo) }.should raise_error(NameError) + begin + def (true).foo; end -> { true.singleton_method(:foo) }.should raise_error(NameError) - begin - def (true).foo; end - -> { true.singleton_method(:foo) }.should raise_error(NameError) - ensure - TrueClass.send(:remove_method, :foo) - end + ensure + TrueClass.send(:remove_method, :foo) end end end diff --git a/core/warning/element_reference_spec.rb b/core/warning/element_reference_spec.rb index c0ed37ef13..6179c57864 100644 --- a/core/warning/element_reference_spec.rb +++ b/core/warning/element_reference_spec.rb @@ -10,11 +10,9 @@ ruby_exe('p [Warning[:deprecated], Warning[:experimental]]', options: "-w").chomp.should == "[true, true]" end - ruby_version_is '3.3' do - it "returns default values for :performance category" do - ruby_exe('p Warning[:performance]').chomp.should == "false" - ruby_exe('p Warning[:performance]', options: "-w").chomp.should == "false" - end + it "returns default values for :performance category" do + ruby_exe('p Warning[:performance]').chomp.should == "false" + ruby_exe('p Warning[:performance]', options: "-w").chomp.should == "false" end it "raises for unknown category" do diff --git a/core/warning/element_set_spec.rb b/core/warning/element_set_spec.rb index d59a7d4c9e..1dbc66ce26 100644 --- a/core/warning/element_set_spec.rb +++ b/core/warning/element_set_spec.rb @@ -17,15 +17,13 @@ end end - ruby_version_is '3.3' do - it "enables or disables performance warnings" do - original = Warning[:performance] - begin - Warning[:performance] = !original - Warning[:performance].should == !original - ensure - Warning[:performance] = original - end + it "enables or disables performance warnings" do + original = Warning[:performance] + begin + Warning[:performance] = !original + Warning[:performance].should == !original + ensure + Warning[:performance] = original end end diff --git a/language/assignments_spec.rb b/language/assignments_spec.rb index c4adf73c1c..58a244b7c2 100644 --- a/language/assignments_spec.rb +++ b/language/assignments_spec.rb @@ -219,15 +219,7 @@ def []=(*args, **kw) end end - ruby_version_is ""..."3.3" do - it "supports keyword arguments in index assignments" do - a = @klass.new - eval "a[1, 2, 3, b: 4] += 5" - a.x.should == [[1, 2, 3, {b: 4}, 105], {}] - end - end - - ruby_version_is "3.3"..."3.4" do + ruby_version_is ""..."3.4" do it "supports keyword arguments in index assignments" do a = @klass.new eval "a[1, 2, 3, b: 4] += 5" diff --git a/language/block_spec.rb b/language/block_spec.rb index ed3d6056bb..67aad76c57 100644 --- a/language/block_spec.rb +++ b/language/block_spec.rb @@ -1058,7 +1058,7 @@ def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, ** end describe "`it` calls without arguments in a block" do - ruby_version_is "3.3"..."3.4" do + ruby_version_is ""..."3.4" do it "emits a deprecation warning" do -> { eval "proc { it }" diff --git a/language/delegation_spec.rb b/language/delegation_spec.rb index 37dd3abdca..cd44956f5d 100644 --- a/language/delegation_spec.rb +++ b/language/delegation_spec.rb @@ -109,13 +109,11 @@ def delegate(*) a.new.delegate(0, 1).should == [[0, 1], {}, nil] end - ruby_version_is "3.3" do - context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do - it "does not allow delegating rest" do - -> { - eval "def m(*); proc { |*| n(*) } end" - }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/) - end + context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do + it "does not allow delegating rest" do + -> { + eval "def m(*); proc { |*| n(*) } end" + }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/) end end end @@ -132,13 +130,11 @@ def delegate(**) a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil] end - ruby_version_is "3.3" do - context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do - it "does not allow delegating kwargs" do - -> { - eval "def m(**); proc { |**| n(**) } end" - }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/) - end + context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do + it "does not allow delegating kwargs" do + -> { + eval "def m(**); proc { |**| n(**) } end" + }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/) end end end @@ -156,13 +152,11 @@ def delegate(&) a.new.delegate(&block).should == [[], {}, block] end - ruby_version_is "3.3" do - context "within a block that accepts anonymous block within a method that accepts anonymous block" do - it "does not allow delegating a block" do - -> { - eval "def m(&); proc { |&| n(&) } end" - }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/) - end + context "within a block that accepts anonymous block within a method that accepts anonymous block" do + it "does not allow delegating a block" do + -> { + eval "def m(&); proc { |&| n(&) } end" + }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/) end end end diff --git a/language/file_spec.rb b/language/file_spec.rb index 59563d9642..36fd329bf6 100644 --- a/language/file_spec.rb +++ b/language/file_spec.rb @@ -7,16 +7,8 @@ -> { eval("__FILE__ = 1") }.should raise_error(SyntaxError) end - ruby_version_is ""..."3.3" do - it "equals (eval) inside an eval" do - eval("__FILE__").should == "(eval)" - end - end - - ruby_version_is "3.3" do - it "equals (eval at __FILE__:__LINE__) inside an eval" do - eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" - end + it "equals (eval at __FILE__:__LINE__) inside an eval" do + eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" end end diff --git a/language/for_spec.rb b/language/for_spec.rb index b8ddfe5f0d..7fc6751d07 100644 --- a/language/for_spec.rb +++ b/language/for_spec.rb @@ -129,37 +129,34 @@ class OFor n.should == 3 end - # Segfault in MRI 3.3 and lower: https://bugs.ruby-lang.org/issues/20468 - ruby_bug "#20468", ""..."3.4" do - it "allows an attribute with safe navigation as an iterator name" do - class OFor - attr_accessor :target - end - - ofor = OFor.new - m = [1,2,3] - n = 0 - eval <<~RUBY - for ofor&.target in m - n += 1 - end - RUBY - ofor.target.should == 3 - n.should == 3 + it "allows an attribute with safe navigation as an iterator name" do + class OFor + attr_accessor :target end - it "allows an attribute with safe navigation on a nil base as an iterator name" do - ofor = nil - m = [1,2,3] - n = 0 - eval <<~RUBY - for ofor&.target in m - n += 1 - end - RUBY - ofor.should be_nil - n.should == 3 - end + ofor = OFor.new + m = [1,2,3] + n = 0 + eval <<~RUBY + for ofor&.target in m + n += 1 + end + RUBY + ofor.target.should == 3 + n.should == 3 + end + + it "allows an attribute with safe navigation on a nil base as an iterator name" do + ofor = nil + m = [1,2,3] + n = 0 + eval <<~RUBY + for ofor&.target in m + n += 1 + end + RUBY + ofor.should be_nil + n.should == 3 end it "allows an array index writer as an iterator name" do diff --git a/language/hash_spec.rb b/language/hash_spec.rb index d155a0c2ec..c7e1bf2d88 100644 --- a/language/hash_spec.rb +++ b/language/hash_spec.rb @@ -275,17 +275,15 @@ def m(**h) h.should == { one: 1, two: 2 } end - ruby_bug "#20012", ""..."3.3" do - it "makes a copy when calling a method taking a positional Hash" do - def m(h) - h.delete(:one); h - end - - h = { one: 1, two: 2 } - m(**h).should == { two: 2 } - m(**h).should_not.equal?(h) - h.should == { one: 1, two: 2 } + it "makes a copy when calling a method taking a positional Hash" do + def m(h) + h.delete(:one); h end + + h = { one: 1, two: 2 } + m(**h).should == { two: 2 } + m(**h).should_not.equal?(h) + h.should == { one: 1, two: 2 } end describe "hash with omitted value" do diff --git a/language/it_parameter_spec.rb b/language/it_parameter_spec.rb index c27e8344ab..58ec3a6faf 100644 --- a/language/it_parameter_spec.rb +++ b/language/it_parameter_spec.rb @@ -1,6 +1,7 @@ require_relative '../spec_helper' ruby_version_is "3.4" do + eval <<-RUBY # use eval to avoid warnings on Ruby 3.3 describe "The `it` parameter" do it "provides it in a block" do -> { it }.call("a").should == "a" @@ -103,4 +104,5 @@ def obj.foo; it; end end end end + RUBY end diff --git a/language/keyword_arguments_spec.rb b/language/keyword_arguments_spec.rb index 4f6370d419..c51c3bc656 100644 --- a/language/keyword_arguments_spec.rb +++ b/language/keyword_arguments_spec.rb @@ -87,16 +87,14 @@ def m(*a) end context "**" do - ruby_version_is "3.3" do - it "copies a non-empty Hash for a method taking (*args)" do - def m(*args) - args[0] - end - - h = {a: 1} - m(**h).should_not.equal?(h) - h.should == {a: 1} + it "copies a non-empty Hash for a method taking (*args)" do + def m(*args) + args[0] end + + h = {a: 1} + m(**h).should_not.equal?(h) + h.should == {a: 1} end it "copies the given Hash for a method taking (**kwargs)" do diff --git a/language/method_spec.rb b/language/method_spec.rb index 8f72bd45ed..8f9f094fd8 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -1234,10 +1234,8 @@ def n(value, &block) args.should == [true] end - ruby_version_is "3.3" do - it "supports multiple statements" do - eval("m (1; 2)").should == [2] - end + it "supports multiple statements" do + eval("m (1; 2)").should == [2] end end diff --git a/library/English/English_spec.rb b/library/English/English_spec.rb index 4d615d1e25..166785f066 100644 --- a/library/English/English_spec.rb +++ b/library/English/English_spec.rb @@ -130,18 +130,6 @@ $LAST_MATCH_INFO.should == $~ end - ruby_version_is ""..."3.3" do - it "aliases $IGNORECASE to $=" do - $VERBOSE, verbose = nil, $VERBOSE - begin - $IGNORECASE.should_not be_nil - $IGNORECASE.should == $= - ensure - $VERBOSE = verbose - end - end - end - it "aliases $ARGV to $*" do $ARGV.should_not be_nil $ARGV.should == $* diff --git a/library/bigdecimal/remainder_spec.rb b/library/bigdecimal/remainder_spec.rb index 0eb06f7ef1..b31967e76b 100644 --- a/library/bigdecimal/remainder_spec.rb +++ b/library/bigdecimal/remainder_spec.rb @@ -56,25 +56,6 @@ @nan.remainder(@infinity).should.nan? end - 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? - @infinity.remainder(@mixed).should.nan? - @infinity.remainder(@one_minus).should.nan? - @infinity.remainder(@frac_1).should.nan? - @one.remainder(@infinity).should.nan? - - @infinity_minus.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@one).should.nan? - @one.remainder(@infinity_minus).should.nan? - @frac_2.remainder(@infinity_minus).should.nan? - - @infinity.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@infinity).should.nan? - end - end - it "coerces arguments to BigDecimal if possible" do @three.remainder(2).should == @one end diff --git a/library/bigdecimal/to_s_spec.rb b/library/bigdecimal/to_s_spec.rb index ba9f960eb3..025057b4d7 100644 --- a/library/bigdecimal/to_s_spec.rb +++ b/library/bigdecimal/to_s_spec.rb @@ -52,10 +52,8 @@ 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 + 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 it "can return a leading space for values > 0" do diff --git a/library/random/formatter/alphanumeric_spec.rb b/library/random/formatter/alphanumeric_spec.rb index 9bd325e1d0..ce45b96dc2 100644 --- a/library/random/formatter/alphanumeric_spec.rb +++ b/library/random/formatter/alphanumeric_spec.rb @@ -41,16 +41,14 @@ }.should raise_error(ArgumentError) end - ruby_version_is "3.3" do - it "accepts a 'chars' argument with the output alphabet" do - @object.alphanumeric(chars: ['a', 'b']).should =~ /\A[ab]+\z/ - end + it "accepts a 'chars' argument with the output alphabet" do + @object.alphanumeric(chars: ['a', 'b']).should =~ /\A[ab]+\z/ + end - it "converts the elements of chars using #to_s" do - to_s = mock("to_s") - to_s.should_receive(:to_s).and_return("[mock to_s]") - # Using 1 value in chars results in an infinite loop - @object.alphanumeric(1, chars: [to_s, to_s]).should == "[mock to_s]" - end + it "converts the elements of chars using #to_s" do + to_s = mock("to_s") + to_s.should_receive(:to_s).and_return("[mock to_s]") + # Using 1 value in chars results in an infinite loop + @object.alphanumeric(1, chars: [to_s, to_s]).should == "[mock to_s]" end end diff --git a/library/socket/basicsocket/recv_nonblock_spec.rb b/library/socket/basicsocket/recv_nonblock_spec.rb index f2a6682f12..f2383513f2 100644 --- a/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/library/socket/basicsocket/recv_nonblock_spec.rb @@ -112,60 +112,30 @@ @server.close unless @server.closed? end - ruby_version_is ""..."3.3" do - it "returns an empty String on a closed stream socket" do - ready = false - - t = Thread.new do - client = @server.accept - - Thread.pass while !ready - begin - client.recv_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + it "returns nil on a closed stream socket" do + ready = false - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true + t = Thread.new do + client = @server.accept - t.value.should == "" - end - end - - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - ready = false - - t = Thread.new do - client = @server.accept - - Thread.pass while !ready - begin - client.recv_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client + Thread.pass while !ready + begin + client.recv_nonblock(10) + rescue IO::EAGAINWaitReadable + retry end + ensure + client.close if client + end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true - t.value.should be_nil - end + t.value.should be_nil end end end diff --git a/library/socket/basicsocket/recv_spec.rb b/library/socket/basicsocket/recv_spec.rb index a51920f52a..7581f1bc15 100644 --- a/library/socket/basicsocket/recv_spec.rb +++ b/library/socket/basicsocket/recv_spec.rb @@ -184,42 +184,21 @@ @server.close unless @server.closed? end - ruby_version_is ""..."3.3" do - it "returns an empty String on a closed stream socket" do - t = Thread.new do - client = @server.accept - client.recv(10) - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - - t.value.should == "" + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recv(10) + ensure + client.close if client end - end - - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - t = Thread.new do - client = @server.accept - client.recv(10) - ensure - client.close if client - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close + socket = TCPSocket.new('127.0.0.1', @port) + socket.close - t.value.should be_nil - end + t.value.should be_nil end end diff --git a/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/library/socket/basicsocket/recvmsg_nonblock_spec.rb index b5fdd7c93b..d1cde4411b 100644 --- a/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -235,64 +235,31 @@ @server.close unless @server.closed? end - ruby_version_is ""..."3.3" do - platform_is_not :windows do # #recvmsg_nonblock() raises 'Errno::EINVAL: Invalid argument - recvmsg(2)' - it "returns an empty String as received data on a closed stream socket" do - ready = false + platform_is_not :windows do + it "returns nil on a closed stream socket" do + ready = false - t = Thread.new do - client = @server.accept + t = Thread.new do + client = @server.accept - Thread.pass while !ready - begin - client.recvmsg_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client + Thread.pass while !ready + begin + client.recvmsg_nonblock(10) + rescue IO::EAGAINWaitReadable + retry end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true - - t.value.should.is_a? Array - t.value[0].should == "" + ensure + client.close if client end - end - end - ruby_version_is "3.3" do - platform_is_not :windows do - it "returns nil on a closed stream socket" do - ready = false + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - t = Thread.new do - client = @server.accept + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + ready = true - Thread.pass while !ready - begin - client.recvmsg_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - ready = true - - t.value.should be_nil - end + t.value.should be_nil end end end diff --git a/library/socket/basicsocket/recvmsg_spec.rb b/library/socket/basicsocket/recvmsg_spec.rb index 04ba1d74c7..cfa0f4c61d 100644 --- a/library/socket/basicsocket/recvmsg_spec.rb +++ b/library/socket/basicsocket/recvmsg_spec.rb @@ -208,46 +208,22 @@ @server.close unless @server.closed? end - ruby_version_is ""..."3.3" do - platform_is_not :windows do - it "returns an empty String as received data on a closed stream socket" do - t = Thread.new do - client = @server.accept - client.recvmsg(10) - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.close - - t.value.should.is_a? Array - t.value[0].should == "" + platform_is_not :windows do + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + client.recvmsg(10) + ensure + client.close if client end - end - end - - ruby_version_is "3.3" do - platform_is_not :windows do - it "returns nil on a closed stream socket" do - t = Thread.new do - client = @server.accept - client.recvmsg(10) - ensure - client.close if client - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - socket = TCPSocket.new('127.0.0.1', @port) - socket.close + socket = TCPSocket.new('127.0.0.1', @port) + socket.close - t.value.should be_nil - end + t.value.should be_nil end end end diff --git a/library/socket/ipsocket/recvfrom_spec.rb b/library/socket/ipsocket/recvfrom_spec.rb index b58903df23..5e6a145c9b 100644 --- a/library/socket/ipsocket/recvfrom_spec.rb +++ b/library/socket/ipsocket/recvfrom_spec.rb @@ -83,43 +83,21 @@ @client.close unless @client.closed? end - ruby_version_is ""..."3.3" do - it "returns an empty String as received data on a closed stream socket" do - t = Thread.new do - client = @server.accept - message = client.recvfrom(10) - message - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - @client.close - - t.value.should.is_a? Array - t.value[0].should == "" + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + message = client.recvfrom(10) + message + ensure + client.close if client end - end - - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - t = Thread.new do - client = @server.accept - message = client.recvfrom(10) - message - ensure - client.close if client - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - @client.close + @client.close - t.value.should be_nil - end + t.value.should be_nil end end diff --git a/library/socket/socket/getaddrinfo_spec.rb b/library/socket/socket/getaddrinfo_spec.rb index 6576af52ee..17ffeaccaf 100644 --- a/library/socket/socket/getaddrinfo_spec.rb +++ b/library/socket/socket/getaddrinfo_spec.rb @@ -107,22 +107,12 @@ res.each { |a| expected.should include(a) } end - ruby_version_is ""..."3.3" do - it "raises SocketError when fails to resolve address" do - -> { - Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") - }.should raise_error(SocketError) - end - end - - ruby_version_is "3.3" do - it "raises ResolutionError when fails to resolve address" do - -> { - Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") - }.should raise_error(Socket::ResolutionError) { |e| - [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) - } - end + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") + }.should raise_error(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } end end end diff --git a/library/socket/socket/getnameinfo_spec.rb b/library/socket/socket/getnameinfo_spec.rb index af4a10c9c2..48cc94bcd1 100644 --- a/library/socket/socket/getnameinfo_spec.rb +++ b/library/socket/socket/getnameinfo_spec.rb @@ -61,22 +61,12 @@ def should_be_valid_dns_name(name) name_info[1].should == 'discard' end - ruby_version_is ""..."3.3" do - it "raises SocketError when fails to resolve address" do - -> { - Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) - }.should raise_error(SocketError) - end - end - - ruby_version_is "3.3" do - it "raises ResolutionError when fails to resolve address" do - -> { - Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) - }.should raise_error(Socket::ResolutionError) { |e| - [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) - } - end + it "raises ResolutionError when fails to resolve address" do + -> { + Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) + }.should raise_error(Socket::ResolutionError) { |e| + [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code) + } end end diff --git a/library/socket/socket/recvfrom_nonblock_spec.rb b/library/socket/socket/recvfrom_nonblock_spec.rb index 01b42bcc52..38a9f5ff5b 100644 --- a/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/library/socket/socket/recvfrom_nonblock_spec.rb @@ -158,61 +158,30 @@ @client.close unless @client.closed? end - ruby_version_is ""..."3.3" do - it "returns an empty String as received data on a closed stream socket" do - ready = false - - t = Thread.new do - client, _ = @server.accept - - Thread.pass while !ready - begin - client.recvfrom_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + it "returns nil on a closed stream socket" do + ready = false - @client.connect(@server_addr) - @client.close - ready = true - - t.value.should.is_a? Array - t.value[0].should == "" - end - end + t = Thread.new do + client, _ = @server.accept - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - ready = false - - t = Thread.new do - client, _ = @server.accept - - Thread.pass while !ready - begin - client.recvfrom_nonblock(10) - rescue IO::EAGAINWaitReadable - retry - end - ensure - client.close if client + Thread.pass while !ready + begin + client.recvfrom_nonblock(10) + rescue IO::EAGAINWaitReadable + retry end + ensure + client.close if client + end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - @client.connect(@server_addr) - @client.close - ready = true + @client.connect(@server_addr) + @client.close + ready = true - t.value.should be_nil - end + t.value.should be_nil end end end diff --git a/library/socket/socket/recvfrom_spec.rb b/library/socket/socket/recvfrom_spec.rb index 6ba39ffcaf..cbbc162f6b 100644 --- a/library/socket/socket/recvfrom_spec.rb +++ b/library/socket/socket/recvfrom_spec.rb @@ -111,43 +111,21 @@ @client.close unless @client.closed? end - ruby_version_is ""..."3.3" do - it "returns an empty String as received data on a closed stream socket" do - t = Thread.new do - client, _ = @server.accept - client.recvfrom(10) - ensure - client.close if client - end - - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - @client.connect(@server_addr) - @client.close - - t.value.should.is_a? Array - t.value[0].should == "" + it "returns nil on a closed stream socket" do + t = Thread.new do + client, _ = @server.accept + client.recvfrom(10) + ensure + client.close if client end - end - - ruby_version_is "3.3" do - it "returns nil on a closed stream socket" do - t = Thread.new do - client, _ = @server.accept - client.recvfrom(10) - ensure - client.close if client - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil - @client.connect(@server_addr) - @client.close + @client.connect(@server_addr) + @client.close - t.value.should be_nil - end + t.value.should be_nil end end diff --git a/library/stringscanner/named_captures_spec.rb b/library/stringscanner/named_captures_spec.rb index a68d66c216..927784a6c4 100644 --- a/library/stringscanner/named_captures_spec.rb +++ b/library/stringscanner/named_captures_spec.rb @@ -16,11 +16,9 @@ @s.named_captures.should == {} end - # https://github.com/ruby/strscan/issues/132 - ruby_bug "", ""..."3.3" do # fixed in strscan v3.0.7 - it "returns {} if there is no any matching done" do - @s.named_captures.should == {} - end + # https://github.com/ruby/strscan/issues/132 fixed in strscan v3.0.7 + it "returns {} if there is no any matching done" do + @s.named_captures.should == {} end it "returns nil for an optional named capturing group if it doesn't match" do diff --git a/optional/capi/encoding_spec.rb b/optional/capi/encoding_spec.rb index 079df32e80..734b5f1253 100644 --- a/optional/capi/encoding_spec.rb +++ b/optional/capi/encoding_spec.rb @@ -747,28 +747,26 @@ end describe "ONIGENC_IS_UNICODE" do - ruby_version_is "3.3" do # Ruby 3.2 has Encoding#replicate which can break this - it "is true only for select UTF-related encodings" do - unicode = [ - Encoding::UTF_8, - Encoding::UTF8_DOCOMO, - Encoding::UTF8_KDDI, - Encoding::UTF8_MAC, - Encoding::UTF8_SOFTBANK, - Encoding::CESU_8, - Encoding::UTF_16LE, - Encoding::UTF_16BE, - Encoding::UTF_32LE, - Encoding::UTF_32BE - ] - unicode.each do |enc| - @s.should.ONIGENC_IS_UNICODE(enc) - end - - (Encoding.list - unicode).each { |enc| - @s.should_not.ONIGENC_IS_UNICODE(enc) - } + it "is true only for select UTF-related encodings" do + unicode = [ + Encoding::UTF_8, + Encoding::UTF8_DOCOMO, + Encoding::UTF8_KDDI, + Encoding::UTF8_MAC, + Encoding::UTF8_SOFTBANK, + Encoding::CESU_8, + Encoding::UTF_16LE, + Encoding::UTF_16BE, + Encoding::UTF_32LE, + Encoding::UTF_32BE + ] + unicode.each do |enc| + @s.should.ONIGENC_IS_UNICODE(enc) end + + (Encoding.list - unicode).each { |enc| + @s.should_not.ONIGENC_IS_UNICODE(enc) + } end # Redundant with the above but more explicit diff --git a/optional/capi/io_spec.rb b/optional/capi/io_spec.rb index ab7a7fc8f6..dc4ac3e374 100644 --- a/optional/capi/io_spec.rb +++ b/optional/capi/io_spec.rb @@ -494,166 +494,164 @@ end end - ruby_version_is "3.3" do - describe "rb_io_mode" do - it "returns the mode" do - (@o.rb_io_mode(@r_io) & 0b11).should == 0b01 - (@o.rb_io_mode(@w_io) & 0b11).should == 0b10 - (@o.rb_io_mode(@rw_io) & 0b11).should == 0b11 - end + describe "rb_io_mode" do + it "returns the mode" do + (@o.rb_io_mode(@r_io) & 0b11).should == 0b01 + (@o.rb_io_mode(@w_io) & 0b11).should == 0b10 + (@o.rb_io_mode(@rw_io) & 0b11).should == 0b11 end + end - describe "rb_io_path" do - it "returns the IO#path" do - @o.rb_io_path(@r_io).should == @r_io.path - @o.rb_io_path(@rw_io).should == @rw_io.path - @o.rb_io_path(@rw_io).should == @name - end + describe "rb_io_path" do + it "returns the IO#path" do + @o.rb_io_path(@r_io).should == @r_io.path + @o.rb_io_path(@rw_io).should == @rw_io.path + @o.rb_io_path(@rw_io).should == @name end + end - describe "rb_io_closed_p" do - it "returns false when io is not closed" do - @o.rb_io_closed_p(@r_io).should == false - @r_io.closed?.should == false - end + describe "rb_io_closed_p" do + it "returns false when io is not closed" do + @o.rb_io_closed_p(@r_io).should == false + @r_io.closed?.should == false + end - it "returns true when io is closed" do - @r_io.close + it "returns true when io is closed" do + @r_io.close - @o.rb_io_closed_p(@r_io).should == true - @r_io.closed?.should == true - end + @o.rb_io_closed_p(@r_io).should == true + @r_io.closed?.should == true end + end - quarantine! do # "Errno::EBADF: Bad file descriptor" at closing @r_io, @rw_io etc in the after :each hook - describe "rb_io_open_descriptor" do - it "creates a new IO instance" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.should.is_a?(IO) - end - - it "return an instance of the specified class" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.class.should == File + quarantine! do # "Errno::EBADF: Bad file descriptor" at closing @r_io, @rw_io etc in the after :each hook + describe "rb_io_open_descriptor" do + it "creates a new IO instance" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.should.is_a?(IO) + end - io = @o.rb_io_open_descriptor(IO, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.class.should == IO - end + it "return an instance of the specified class" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.class.should == File - it "sets the specified file descriptor" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.fileno.should == @r_io.fileno - end + io = @o.rb_io_open_descriptor(IO, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.class.should == IO + end - it "sets the specified path" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.path.should == "a.txt" - end + it "sets the specified file descriptor" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.fileno.should == @r_io.fileno + end - it "sets the specified mode" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_BINMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.should.binmode? + it "sets the specified path" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.path.should == "a.txt" + end - io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_TEXTMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.should_not.binmode? - end + it "sets the specified mode" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_BINMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.should.binmode? - it "sets the specified timeout" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.timeout.should == 60 - end + io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_TEXTMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.should_not.binmode? + end - it "sets the specified internal encoding" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.internal_encoding.should == Encoding::US_ASCII - end + it "sets the specified timeout" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.timeout.should == 60 + end - it "sets the specified external encoding" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.external_encoding.should == Encoding::UTF_8 - end + it "sets the specified internal encoding" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.internal_encoding.should == Encoding::US_ASCII + end - it "does not apply the specified encoding flags" do - name = tmp("rb_io_open_descriptor_specs") - File.write(name, "123\r\n456\n89") - file = File.open(name, "r") + it "sets the specified external encoding" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.external_encoding.should == Encoding::UTF_8 + end - io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {}) - io.read_nonblock(20).should == "123\r\n456\n89" - ensure - file.close - rm_r name - end + it "does not apply the specified encoding flags" do + name = tmp("rb_io_open_descriptor_specs") + File.write(name, "123\r\n456\n89") + file = File.open(name, "r") - it "ignores the IO open options" do - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {external_encoding: "windows-1251"}) - io.external_encoding.should == Encoding::UTF_8 + io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {}) + io.read_nonblock(20).should == "123\r\n456\n89" + ensure + file.close + rm_r name + end - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {internal_encoding: "windows-1251"}) - io.internal_encoding.should == Encoding::US_ASCII + it "ignores the IO open options" do + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {external_encoding: "windows-1251"}) + io.external_encoding.should == Encoding::UTF_8 - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {encoding: "windows-1251:binary"}) - io.external_encoding.should == Encoding::UTF_8 - io.internal_encoding.should == Encoding::US_ASCII + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {internal_encoding: "windows-1251"}) + io.internal_encoding.should == Encoding::US_ASCII - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {textmode: false}) - io.should_not.binmode? + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {encoding: "windows-1251:binary"}) + io.external_encoding.should == Encoding::UTF_8 + io.internal_encoding.should == Encoding::US_ASCII - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {binmode: true}) - io.should_not.binmode? + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {textmode: false}) + io.should_not.binmode? - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {autoclose: false}) - io.should.autoclose? + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {binmode: true}) + io.should_not.binmode? - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {path: "a.txt"}) - io.path.should == "a.txt" - end + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {autoclose: false}) + io.should.autoclose? - it "ignores the IO encoding options" do - io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_WRITABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {crlf_newline: true}) + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {path: "a.txt"}) + io.path.should == "a.txt" + end - io.write("123\r\n456\n89") - io.flush + it "ignores the IO encoding options" do + io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_WRITABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {crlf_newline: true}) - @r_io.read_nonblock(20).should == "123\r\n456\n89" - end + io.write("123\r\n456\n89") + io.flush - it "allows wrong mode" do - io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) - io.should.is_a?(File) + @r_io.read_nonblock(20).should == "123\r\n456\n89" + end - platform_is_not :windows do - -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) - end + it "allows wrong mode" do + io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) + io.should.is_a?(File) - platform_is :windows do - -> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable) - end + platform_is_not :windows do + -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) end - it "tolerates NULL as rb_io_encoding *encoding parameter" do - io = @o.rb_io_open_descriptor_without_encoding(File, @r_io.fileno, 0, "a.txt", 60) - io.should.is_a?(File) + platform_is :windows do + -> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable) end + end - it "deduplicates path String" do - path = "a.txt".dup - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) - io.path.should_not equal(path) + it "tolerates NULL as rb_io_encoding *encoding parameter" do + io = @o.rb_io_open_descriptor_without_encoding(File, @r_io.fileno, 0, "a.txt", 60) + io.should.is_a?(File) + end - path = "a.txt".freeze - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) - io.path.should_not equal(path) - end + it "deduplicates path String" do + path = "a.txt".dup + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) + io.path.should_not equal(path) + + path = "a.txt".freeze + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) + io.path.should_not equal(path) + end - it "calls #to_str to convert a path to a String" do - path = Object.new - def path.to_str; "a.txt"; end + it "calls #to_str to convert a path to a String" do + path = Object.new + def path.to_str; "a.txt"; end - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) - io.path.should == "a.txt" - end + io.path.should == "a.txt" end end end diff --git a/optional/capi/object_spec.rb b/optional/capi/object_spec.rb index 8b4d8a9bba..6716fd9e33 100644 --- a/optional/capi/object_spec.rb +++ b/optional/capi/object_spec.rb @@ -1004,7 +1004,6 @@ def reach it "calls the callback function for each cvar and ivar on a class" do exp = [:@@cvar, :foo, :@@cvar2, :bar, :@ivar, :baz] - exp.unshift(:__classpath__, 'CApiObjectSpecs::CVars') if RUBY_VERSION < "3.3" ary = @o.rb_ivar_foreach(CApiObjectSpecs::CVars) ary.should == exp @@ -1012,7 +1011,6 @@ def reach it "calls the callback function for each cvar and ivar on a module" do exp = [:@@mvar, :foo, :@@mvar2, :bar, :@ivar, :baz] - exp.unshift(:__classpath__, 'CApiObjectSpecs::MVars') if RUBY_VERSION < "3.3" ary = @o.rb_ivar_foreach(CApiObjectSpecs::MVars) ary.should == exp diff --git a/optional/capi/struct_spec.rb b/optional/capi/struct_spec.rb index cc8d7f932e..3f9eff52bc 100644 --- a/optional/capi/struct_spec.rb +++ b/optional/capi/struct_spec.rb @@ -239,78 +239,76 @@ end end -ruby_version_is "3.3" do - describe "C-API Data function" do - before :all do - @s = CApiStructSpecs.new - @klass = @s.rb_data_define(nil, "a", "b", "c") - end - - describe "rb_data_define" do - it "returns a subclass of Data class when passed nil as the first argument" do - @klass.should.is_a? Class - @klass.superclass.should == Data - end - - it "returns a subclass of a class when passed as the first argument" do - superclass = Class.new(Data) - klass = @s.rb_data_define(superclass, "a", "b", "c") - - klass.should.is_a? Class - klass.superclass.should == superclass - end - - it "creates readers for the members" do - obj = @klass.new(1, 2, 3) - - obj.a.should == 1 - obj.b.should == 2 - obj.c.should == 3 - end - - it "returns the member names as Symbols" do - obj = @klass.new(0, 0, 0) - - obj.members.should == [:a, :b, :c] - end - - it "raises an ArgumentError if arguments contain duplicate member name" do - -> { @s.rb_data_define(nil, "a", "b", "a") }.should raise_error(ArgumentError) - end - - it "raises when first argument is not a class" do - -> { @s.rb_data_define([], "a", "b", "c") }.should raise_error(TypeError, "wrong argument type Array (expected Class)") - end - end - - describe "rb_struct_initialize" do - it "sets all members for a Data instance" do - data = @klass.allocate - @s.rb_struct_initialize(data, [1, 2, 3]).should == nil - data.a.should == 1 - data.b.should == 2 - data.c.should == 3 - end - - it "freezes the Data instance" do - data = @klass.allocate - @s.rb_struct_initialize(data, [1, 2, 3]).should == nil - data.should.frozen? - -> { @s.rb_struct_initialize(data, [1, 2, 3]) }.should raise_error(FrozenError) - end - - it "raises ArgumentError if too many values" do - data = @klass.allocate - -> { @s.rb_struct_initialize(data, [1, 2, 3, 4]) }.should raise_error(ArgumentError, "struct size differs") - end - - it "treats missing values as nil" do - data = @klass.allocate - @s.rb_struct_initialize(data, [1, 2]).should == nil - data.a.should == 1 - data.b.should == 2 - data.c.should == nil - end +describe "C-API Data function" do + before :all do + @s = CApiStructSpecs.new + @klass = @s.rb_data_define(nil, "a", "b", "c") + end + + describe "rb_data_define" do + it "returns a subclass of Data class when passed nil as the first argument" do + @klass.should.is_a? Class + @klass.superclass.should == Data + end + + it "returns a subclass of a class when passed as the first argument" do + superclass = Class.new(Data) + klass = @s.rb_data_define(superclass, "a", "b", "c") + + klass.should.is_a? Class + klass.superclass.should == superclass + end + + it "creates readers for the members" do + obj = @klass.new(1, 2, 3) + + obj.a.should == 1 + obj.b.should == 2 + obj.c.should == 3 + end + + it "returns the member names as Symbols" do + obj = @klass.new(0, 0, 0) + + obj.members.should == [:a, :b, :c] + end + + it "raises an ArgumentError if arguments contain duplicate member name" do + -> { @s.rb_data_define(nil, "a", "b", "a") }.should raise_error(ArgumentError) + end + + it "raises when first argument is not a class" do + -> { @s.rb_data_define([], "a", "b", "c") }.should raise_error(TypeError, "wrong argument type Array (expected Class)") + end + end + + describe "rb_struct_initialize" do + it "sets all members for a Data instance" do + data = @klass.allocate + @s.rb_struct_initialize(data, [1, 2, 3]).should == nil + data.a.should == 1 + data.b.should == 2 + data.c.should == 3 + end + + it "freezes the Data instance" do + data = @klass.allocate + @s.rb_struct_initialize(data, [1, 2, 3]).should == nil + data.should.frozen? + -> { @s.rb_struct_initialize(data, [1, 2, 3]) }.should raise_error(FrozenError) + end + + it "raises ArgumentError if too many values" do + data = @klass.allocate + -> { @s.rb_struct_initialize(data, [1, 2, 3, 4]) }.should raise_error(ArgumentError, "struct size differs") + end + + it "treats missing values as nil" do + data = @klass.allocate + @s.rb_struct_initialize(data, [1, 2]).should == nil + data.a.should == 1 + data.b.should == 2 + data.c.should == nil end end end diff --git a/security/cve_2020_10663_spec.rb b/security/cve_2020_10663_spec.rb index 34db004208..7f42c40742 100644 --- a/security/cve_2020_10663_spec.rb +++ b/security/cve_2020_10663_spec.rb @@ -21,7 +21,7 @@ def to_json(*args) guard -> { JSON.const_defined?(:Pure) or - version_is(JSON::VERSION, '2.3.0'..'2.11.0') + version_is(JSON::VERSION, '2.3.0'...'2.11.0') } do describe "CVE-2020-10663 is resisted by" do it "only creating custom objects if passed create_additions: true or using JSON.load" do diff --git a/shared/queue/freeze.rb b/shared/queue/freeze.rb index 4c506a4235..5dedd005df 100644 --- a/shared/queue/freeze.rb +++ b/shared/queue/freeze.rb @@ -1,18 +1,8 @@ describe :queue_freeze, shared: true do - ruby_version_is ""..."3.3" do - it "can be frozen" do - queue = @object.call + it "raises an exception when freezing" do + queue = @object.call + -> { queue.freeze - queue.should.frozen? - end - end - - ruby_version_is "3.3" do - it "raises an exception when freezing" do - queue = @object.call - -> { - queue.freeze - }.should raise_error(TypeError, "cannot freeze #{queue}") - end + }.should raise_error(TypeError, "cannot freeze #{queue}") end end diff --git a/shared/string/start_with.rb b/shared/string/start_with.rb index 4b947a3bbf..9592eda4d4 100644 --- a/shared/string/start_with.rb +++ b/shared/string/start_with.rb @@ -70,15 +70,7 @@ $1.should be_nil end - ruby_version_is ""..."3.3" do - it "does not check that we are not matching part of a character" do - "\xC3\xA9".send(@method).should.start_with?("\xC3") - end - end - - ruby_version_is "3.3" do # #19784 - it "checks that we are not matching part of a character" do - "\xC3\xA9".send(@method).should_not.start_with?("\xC3") - end + it "checks that we are not matching part of a character" do + "\xC3\xA9".send(@method).should_not.start_with?("\xC3") end end