diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d3234d979..c01a54319c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu, macos, windows ] - ruby: [ 3.0.6, 3.1.4, 3.2.2, 3.3.0, 3.4.1 ] + ruby: [ 3.1.6, 3.2.6, 3.3.7, 3.4.1 ] rubyopt: [""] include: - os: ubuntu diff --git a/README.md b/README.md index 42d116206e..ee1015c24c 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ ruby/spec is known to be tested in these implementations for every commit: * [Opal](https://github.com/opal/opal/tree/master/spec) * [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor) -ruby/spec describes the behavior of Ruby 3.0 and more recent Ruby versions. -More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.0.x, 3.1.x, 3.2.x, etc), and those are tested in CI. +ruby/spec describes the behavior of Ruby 3.1 and more recent Ruby versions. +More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.1.x, 3.2.x, etc), and those are tested in CI. ### Synchronization with Ruby Implementations @@ -62,6 +62,7 @@ For older specs try these commits: * Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041) * Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661) * 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) ### Running the specs diff --git a/core/array/intersect_spec.rb b/core/array/intersect_spec.rb index 62ac157278..456aa26c6e 100644 --- a/core/array/intersect_spec.rb +++ b/core/array/intersect_spec.rb @@ -2,65 +2,63 @@ require_relative 'fixtures/classes' describe 'Array#intersect?' do - ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198 - describe 'when at least one element in two Arrays is the same' do - it 'returns true' do - [1, 2].intersect?([2, 3, 4]).should == true - [2, 3, 4].intersect?([1, 2]).should == true - end + describe 'when at least one element in two Arrays is the same' do + it 'returns true' do + [1, 2].intersect?([2, 3, 4]).should == true + [2, 3, 4].intersect?([1, 2]).should == true end + end - describe 'when there are no elements in common between two Arrays' do - it 'returns false' do - [0, 1, 2].intersect?([3, 4]).should == false - [3, 4].intersect?([0, 1, 2]).should == false - [3, 4].intersect?([]).should == false - [].intersect?([0, 1, 2]).should == false - end + describe 'when there are no elements in common between two Arrays' do + it 'returns false' do + [0, 1, 2].intersect?([3, 4]).should == false + [3, 4].intersect?([0, 1, 2]).should == false + [3, 4].intersect?([]).should == false + [].intersect?([0, 1, 2]).should == false end + end - it "tries to convert the passed argument to an Array using #to_ary" do - obj = mock('[1,2,3]') - obj.should_receive(:to_ary).and_return([1, 2, 3]) + it "tries to convert the passed argument to an Array using #to_ary" do + obj = mock('[1,2,3]') + obj.should_receive(:to_ary).and_return([1, 2, 3]) - [1, 2].intersect?(obj).should == true - end + [1, 2].intersect?(obj).should == true + end - it "determines equivalence between elements in the sense of eql?" do - obj1 = mock('1') - obj2 = mock('2') - obj1.stub!(:hash).and_return(0) - obj2.stub!(:hash).and_return(0) - obj1.stub!(:eql?).and_return(true) - obj2.stub!(:eql?).and_return(true) + it "determines equivalence between elements in the sense of eql?" do + obj1 = mock('1') + obj2 = mock('2') + obj1.stub!(:hash).and_return(0) + obj2.stub!(:hash).and_return(0) + obj1.stub!(:eql?).and_return(true) + obj2.stub!(:eql?).and_return(true) - [obj1].intersect?([obj2]).should == true + [obj1].intersect?([obj2]).should == true - obj1 = mock('3') - obj2 = mock('4') - obj1.stub!(:hash).and_return(0) - obj2.stub!(:hash).and_return(0) - obj1.stub!(:eql?).and_return(false) - obj2.stub!(:eql?).and_return(false) + obj1 = mock('3') + obj2 = mock('4') + obj1.stub!(:hash).and_return(0) + obj2.stub!(:hash).and_return(0) + obj1.stub!(:eql?).and_return(false) + obj2.stub!(:eql?).and_return(false) - [obj1].intersect?([obj2]).should == false - end + [obj1].intersect?([obj2]).should == false + end - it "does not call to_ary on array subclasses" do - [5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true - end + it "does not call to_ary on array subclasses" do + [5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true + end - it "properly handles an identical item even when its #eql? isn't reflexive" do - x = mock('x') - x.stub!(:hash).and_return(42) - x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI. + it "properly handles an identical item even when its #eql? isn't reflexive" do + x = mock('x') + x.stub!(:hash).and_return(42) + x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI. - [x].intersect?([x]).should == true - end + [x].intersect?([x]).should == true + end - it "has semantic of !(a & b).empty?" do - [].intersect?([]).should == false - [nil].intersect?([nil]).should == true - end + it "has semantic of !(a & b).empty?" do + [].intersect?([]).should == false + [nil].intersect?([nil]).should == true end end diff --git a/core/basicobject/instance_eval_spec.rb b/core/basicobject/instance_eval_spec.rb index 1f3a43f341..633b5c2cb1 100644 --- a/core/basicobject/instance_eval_spec.rb +++ b/core/basicobject/instance_eval_spec.rb @@ -141,22 +141,11 @@ class B; end caller.get_constant_with_string(receiver).should == :singleton_class end - ruby_version_is ""..."3.1" do - it "looks in the caller scope next" do - receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new - caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new + it "looks in the receiver class next" do + receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new + caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new - caller.get_constant_with_string(receiver).should == :Caller - end - end - - ruby_version_is "3.1" do - it "looks in the receiver class next" do - receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new - caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new - - caller.get_constant_with_string(receiver).should == :Receiver - end + caller.get_constant_with_string(receiver).should == :Receiver end it "looks in the caller class next" do diff --git a/core/class/subclasses_spec.rb b/core/class/subclasses_spec.rb index 50eb5358d9..f692152787 100644 --- a/core/class/subclasses_spec.rb +++ b/core/class/subclasses_spec.rb @@ -1,87 +1,85 @@ require_relative '../../spec_helper' require_relative '../module/fixtures/classes' -ruby_version_is '3.1' do - describe "Class#subclasses" do - it "returns a list of classes directly inheriting from self" do - assert_subclasses(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2]) - end +describe "Class#subclasses" do + it "returns a list of classes directly inheriting from self" do + assert_subclasses(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2]) + end - it "does not return included modules from the parent" do - parent = Class.new - child = Class.new(parent) - mod = Module.new - parent.include(mod) + it "does not return included modules from the parent" do + parent = Class.new + child = Class.new(parent) + mod = Module.new + parent.include(mod) - assert_subclasses(parent, [child]) - end - - it "does not return included modules from the child" do - parent = Class.new - child = Class.new(parent) - mod = Module.new - parent.include(mod) + assert_subclasses(parent, [child]) + end - assert_subclasses(parent, [child]) - end + it "does not return included modules from the child" do + parent = Class.new + child = Class.new(parent) + mod = Module.new + parent.include(mod) - it "does not return prepended modules from the parent" do - parent = Class.new - child = Class.new(parent) - mod = Module.new - parent.prepend(mod) + assert_subclasses(parent, [child]) + end - assert_subclasses(parent, [child]) - end + it "does not return prepended modules from the parent" do + parent = Class.new + child = Class.new(parent) + mod = Module.new + parent.prepend(mod) - it "does not return prepended modules from the child" do - parent = Class.new - child = Class.new(parent) - mod = Module.new - child.prepend(mod) + assert_subclasses(parent, [child]) + end - assert_subclasses(parent, [child]) - end + it "does not return prepended modules from the child" do + parent = Class.new + child = Class.new(parent) + mod = Module.new + child.prepend(mod) - it "does not return singleton classes" do - a = Class.new + assert_subclasses(parent, [child]) + end - a_obj = a.new - def a_obj.force_singleton_class - 42 - end + it "does not return singleton classes" do + a = Class.new - a.subclasses.should_not include(a_obj.singleton_class) + a_obj = a.new + def a_obj.force_singleton_class + 42 end - it "has 1 entry per module or class" do - ModuleSpecs::Parent.subclasses.should == ModuleSpecs::Parent.subclasses.uniq - end + a.subclasses.should_not include(a_obj.singleton_class) + end + + it "has 1 entry per module or class" do + ModuleSpecs::Parent.subclasses.should == ModuleSpecs::Parent.subclasses.uniq + end - it "works when creating subclasses concurrently" do - t = 16 - n = 1000 - go = false - superclass = Class.new - - threads = t.times.map do - Thread.new do - Thread.pass until go - n.times.map do - Class.new(superclass) - end + it "works when creating subclasses concurrently" do + t = 16 + n = 1000 + go = false + superclass = Class.new + + threads = t.times.map do + Thread.new do + Thread.pass until go + n.times.map do + Class.new(superclass) end end + end - go = true - classes = threads.map(&:value) + go = true + classes = threads.map(&:value) - superclass.subclasses.size.should == t * n - superclass.subclasses.each { |c| c.should be_kind_of(Class) } - end + superclass.subclasses.size.should == t * n + superclass.subclasses.each { |c| c.should be_kind_of(Class) } + end - def assert_subclasses(mod,subclasses) - mod.subclasses.sort_by(&:inspect).should == subclasses.sort_by(&:inspect) - end + def assert_subclasses(mod,subclasses) + mod.subclasses.sort_by(&:inspect).should == subclasses.sort_by(&:inspect) end end diff --git a/core/dir/glob_spec.rb b/core/dir/glob_spec.rb index 32f515c81d..a60b233bc0 100644 --- a/core/dir/glob_spec.rb +++ b/core/dir/glob_spec.rb @@ -89,31 +89,15 @@ Dir.glob('**/', File::FNM_DOTMATCH).sort.should == expected end - ruby_version_is ''...'3.1' do - it "recursively matches files and directories in nested dot subdirectory with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do - expected = %w[ - nested/. - nested/.dotsubir - nested/.dotsubir/. - nested/.dotsubir/.dotfile - nested/.dotsubir/nondotfile - ] - - Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort - end - end - - ruby_version_is '3.1' do - it "recursively matches files and directories in nested dot subdirectory except . with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do - expected = %w[ - nested/. - nested/.dotsubir - nested/.dotsubir/.dotfile - nested/.dotsubir/nondotfile - ] + it "recursively matches files and directories in nested dot subdirectory except . with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do + expected = %w[ + nested/. + nested/.dotsubir + nested/.dotsubir/.dotfile + nested/.dotsubir/nondotfile + ] - Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort - end + Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort end # This is a separate case to check **/ coming after a constant @@ -260,34 +244,31 @@ Dir.glob('**/.*', base: "deeply/nested").sort.should == expected end - # < 3.1 include a "." entry for every dir: ["directory/.", "directory/structure/.", ...] - ruby_version_is '3.1' do - it "handles **/.* with base keyword argument and FNM_DOTMATCH" do - expected = %w[ - . - .dotfile.ext - directory/structure/.ext - ].sort + it "handles **/.* with base keyword argument and FNM_DOTMATCH" do + expected = %w[ + . + .dotfile.ext + directory/structure/.ext + ].sort - Dir.glob('**/.*', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected - end + Dir.glob('**/.*', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected + end - it "handles **/** with base keyword argument and FNM_DOTMATCH" do - expected = %w[ - . - .dotfile.ext - directory - directory/structure - directory/structure/.ext - directory/structure/bar - directory/structure/baz - directory/structure/file_one - directory/structure/file_one.ext - directory/structure/foo - ].sort - - Dir.glob('**/**', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected - end + it "handles **/** with base keyword argument and FNM_DOTMATCH" do + expected = %w[ + . + .dotfile.ext + directory + directory/structure + directory/structure/.ext + directory/structure/bar + directory/structure/baz + directory/structure/file_one + directory/structure/file_one.ext + directory/structure/foo + ].sort + + Dir.glob('**/**', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected end it "handles **/*pattern* with base keyword argument and FNM_DOTMATCH" do diff --git a/core/dir/shared/glob.rb b/core/dir/shared/glob.rb index 8db74881ba..b1fc924f08 100644 --- a/core/dir/shared/glob.rb +++ b/core/dir/shared/glob.rb @@ -42,25 +42,10 @@ result.sort.should == Dir.send(@method, '*').sort end - ruby_version_is ""..."3.1" do - it "result is sorted with any non false value of sort:" do - result = Dir.send(@method, '*', sort: 0) - result.should == result.sort - - result = Dir.send(@method, '*', sort: nil) - result.should == result.sort - - result = Dir.send(@method, '*', sort: 'false') - result.should == result.sort - end - end - - ruby_version_is "3.1" do - it "raises an ArgumentError if sort: is not true or false" do - -> { Dir.send(@method, '*', sort: 0) }.should raise_error ArgumentError, /expected true or false/ - -> { Dir.send(@method, '*', sort: nil) }.should raise_error ArgumentError, /expected true or false/ - -> { Dir.send(@method, '*', sort: 'false') }.should raise_error ArgumentError, /expected true or false/ - end + it "raises an ArgumentError if sort: is not true or false" do + -> { Dir.send(@method, '*', sort: 0) }.should raise_error ArgumentError, /expected true or false/ + -> { Dir.send(@method, '*', sort: nil) }.should raise_error ArgumentError, /expected true or false/ + -> { Dir.send(@method, '*', sort: 'false') }.should raise_error ArgumentError, /expected true or false/ end it "matches non-dotfiles with '*'" do @@ -151,16 +136,8 @@ Dir.send(@method, 'special/test\{1\}/*').should == ['special/test{1}/file[1]'] end - ruby_version_is ''...'3.1' do - it "matches dotfiles with '.*'" do - Dir.send(@method, '.*').sort.should == %w|. .. .dotfile .dotsubdir|.sort - end - end - - ruby_version_is '3.1' do - it "matches dotfiles except .. with '.*'" do - Dir.send(@method, '.*').sort.should == %w|. .dotfile .dotsubdir|.sort - end + it "matches dotfiles except .. with '.*'" do + Dir.send(@method, '.*').sort.should == %w|. .dotfile .dotsubdir|.sort end it "matches non-dotfiles with '*'" do @@ -205,16 +182,8 @@ Dir.send(@method, '**').sort.should == expected end - ruby_version_is ''...'3.1' do - it "matches dotfiles in the current directory with '.**'" do - Dir.send(@method, '.**').sort.should == %w|. .. .dotsubdir .dotfile|.sort - end - end - - ruby_version_is '3.1' do - it "matches dotfiles in the current directory except .. with '.**'" do - Dir.send(@method, '.**').sort.should == %w|. .dotsubdir .dotfile|.sort - end + it "matches dotfiles in the current directory except .. with '.**'" do + Dir.send(@method, '.**').sort.should == %w|. .dotsubdir .dotfile|.sort end it "recursively matches any nondot subdirectories with '**/'" do @@ -245,19 +214,9 @@ Dir.send(@method, '**/*ory', base: 'deeply').sort.should == expected end - ruby_version_is ''...'3.1' do - it "recursively matches any subdirectories including ./ and ../ with '.**/'" do - Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do - Dir.send(@method, '.**/').sort.should == %w|./ ../|.sort - end - end - end - - ruby_version_is '3.1' do - it "recursively matches any subdirectories including ./ with '.**/'" do - Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do - Dir.send(@method, '.**/').should == ['./'] - end + it "recursively matches any subdirectories including ./ with '.**/'" do + Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do + Dir.send(@method, '.**/').should == ['./'] end end diff --git a/core/enumerable/compact_spec.rb b/core/enumerable/compact_spec.rb index 86e95dce08..1895430c4e 100644 --- a/core/enumerable/compact_spec.rb +++ b/core/enumerable/compact_spec.rb @@ -1,11 +1,9 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is '3.1' do - describe "Enumerable#compact" do - it 'returns array without nil elements' do - arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true) - arr.compact.should == [1, 2, true] - end +describe "Enumerable#compact" do + it 'returns array without nil elements' do + arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true) + arr.compact.should == [1, 2, true] end end diff --git a/core/enumerable/each_cons_spec.rb b/core/enumerable/each_cons_spec.rb index 8fb31fb925..ed77741862 100644 --- a/core/enumerable/each_cons_spec.rb +++ b/core/enumerable/each_cons_spec.rb @@ -56,10 +56,8 @@ multi.each_cons(2).to_a.should == [[[1, 2], [3, 4, 5]], [[3, 4, 5], [6, 7, 8, 9]]] end - ruby_version_is "3.1" do - it "returns self when a block is given" do - @enum.each_cons(3){}.should == @enum - end + it "returns self when a block is given" do + @enum.each_cons(3){}.should == @enum end describe "when no block is given" do diff --git a/core/enumerable/each_slice_spec.rb b/core/enumerable/each_slice_spec.rb index a57a1dba81..47b8c9ba33 100644 --- a/core/enumerable/each_slice_spec.rb +++ b/core/enumerable/each_slice_spec.rb @@ -57,10 +57,8 @@ e.to_a.should == @sliced end - ruby_version_is "3.1" do - it "returns self when a block is given" do - @enum.each_slice(3){}.should == @enum - end + it "returns self when a block is given" do + @enum.each_slice(3){}.should == @enum end it "gathers whole arrays as elements when each yields multiple" do diff --git a/core/enumerable/tally_spec.rb b/core/enumerable/tally_spec.rb index e0edc8dc75..95c64c1294 100644 --- a/core/enumerable/tally_spec.rb +++ b/core/enumerable/tally_spec.rb @@ -32,62 +32,60 @@ end end -ruby_version_is "3.1" do - describe "Enumerable#tally with a hash" do - before :each do - ScratchPad.record [] - end - - it "returns a hash with counts according to the value" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - enum.tally({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} - end - - it "returns the given hash" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - hash = { 'foo' => 1 } - enum.tally(hash).should equal(hash) - end - - it "calls #to_hash to convert argument to Hash implicitly if passed not a Hash" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - object = Object.new - def object.to_hash; { 'foo' => 1 }; end - enum.tally(object).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} - end - - it "raises a FrozenError and does not update the given hash when the hash is frozen" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - hash = { 'foo' => 1 }.freeze - -> { enum.tally(hash) }.should raise_error(FrozenError) - hash.should == { 'foo' => 1 } - end - - it "raises a FrozenError even if enumerable is empty" do - enum = EnumerableSpecs::Numerous.new() - hash = { 'foo' => 1 }.freeze - -> { enum.tally(hash) }.should raise_error(FrozenError) - end - - it "does not call given block" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - enum.tally({ 'foo' => 1 }) { |v| ScratchPad << v } - ScratchPad.recorded.should == [] - end - - it "ignores the default value" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} - end - - it "ignores the default proc" do - enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') - enum.tally(Hash.new {100}).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} - end - - it "needs the values counting each elements to be an integer" do - enum = EnumerableSpecs::Numerous.new('foo') - -> { enum.tally({ 'foo' => 'bar' }) }.should raise_error(TypeError) - end +describe "Enumerable#tally with a hash" do + before :each do + ScratchPad.record [] + end + + it "returns a hash with counts according to the value" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} + end + + it "returns the given hash" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + hash = { 'foo' => 1 } + enum.tally(hash).should equal(hash) + end + + it "calls #to_hash to convert argument to Hash implicitly if passed not a Hash" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + object = Object.new + def object.to_hash; { 'foo' => 1 }; end + enum.tally(object).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} + end + + it "raises a FrozenError and does not update the given hash when the hash is frozen" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + hash = { 'foo' => 1 }.freeze + -> { enum.tally(hash) }.should raise_error(FrozenError) + hash.should == { 'foo' => 1 } + end + + it "raises a FrozenError even if enumerable is empty" do + enum = EnumerableSpecs::Numerous.new() + hash = { 'foo' => 1 }.freeze + -> { enum.tally(hash) }.should raise_error(FrozenError) + end + + it "does not call given block" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally({ 'foo' => 1 }) { |v| ScratchPad << v } + ScratchPad.recorded.should == [] + end + + it "ignores the default value" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} + end + + it "ignores the default proc" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally(Hash.new {100}).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} + end + + it "needs the values counting each elements to be an integer" do + enum = EnumerableSpecs::Numerous.new('foo') + -> { enum.tally({ 'foo' => 'bar' }) }.should raise_error(TypeError) end end diff --git a/core/enumerator/lazy/compact_spec.rb b/core/enumerator/lazy/compact_spec.rb index e678bc71eb..65c544f062 100644 --- a/core/enumerator/lazy/compact_spec.rb +++ b/core/enumerator/lazy/compact_spec.rb @@ -1,16 +1,14 @@ require_relative '../../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is '3.1' do - describe "Enumerator::Lazy#compact" do - it 'returns array without nil elements' do - arr = [1, nil, 3, false, 5].to_enum.lazy.compact - arr.should be_an_instance_of(Enumerator::Lazy) - arr.force.should == [1, 3, false, 5] - end +describe "Enumerator::Lazy#compact" do + it 'returns array without nil elements' do + arr = [1, nil, 3, false, 5].to_enum.lazy.compact + arr.should be_an_instance_of(Enumerator::Lazy) + arr.force.should == [1, 3, false, 5] + end - it "sets #size to nil" do - Enumerator::Lazy.new(Object.new, 100) {}.compact.size.should == nil - end + it "sets #size to nil" do + Enumerator::Lazy.new(Object.new, 100) {}.compact.size.should == nil end end diff --git a/core/enumerator/lazy/lazy_spec.rb b/core/enumerator/lazy/lazy_spec.rb index 0fb104e25a..b43864b673 100644 --- a/core/enumerator/lazy/lazy_spec.rb +++ b/core/enumerator/lazy/lazy_spec.rb @@ -9,16 +9,11 @@ it "defines lazy versions of a whitelist of Enumerator methods" do lazy_methods = [ - :chunk, :collect, :collect_concat, :drop, :drop_while, :enum_for, + :chunk, :chunk_while, :collect, :collect_concat, :compact, :drop, :drop_while, :enum_for, :find_all, :flat_map, :force, :grep, :grep_v, :lazy, :map, :reject, :select, :slice_after, :slice_before, :slice_when, :take, :take_while, - :to_enum, :zip + :to_enum, :uniq, :zip ] - lazy_methods += [:chunk_while, :uniq] - - ruby_version_is '3.1' do - lazy_methods += [:compact] - end Enumerator::Lazy.instance_methods(false).should include(*lazy_methods) end diff --git a/core/env/dup_spec.rb b/core/env/dup_spec.rb index 46d125aca8..ac66b455cd 100644 --- a/core/env/dup_spec.rb +++ b/core/env/dup_spec.rb @@ -1,11 +1,9 @@ require_relative '../../spec_helper' describe "ENV#dup" do - ruby_version_is "3.1" do - it "raises TypeError" do - -> { - ENV.dup - }.should raise_error(TypeError, /Cannot dup ENV, use ENV.to_h to get a copy of ENV as a hash/) - end + it "raises TypeError" do + -> { + ENV.dup + }.should raise_error(TypeError, /Cannot dup ENV, use ENV.to_h to get a copy of ENV as a hash/) end end diff --git a/core/file/dirname_spec.rb b/core/file/dirname_spec.rb index 8dd6c4ca88..420b890550 100644 --- a/core/file/dirname_spec.rb +++ b/core/file/dirname_spec.rb @@ -11,34 +11,32 @@ File.dirname('/foo/foo').should == '/foo' end - ruby_version_is '3.1' do - context "when level is passed" do - it "returns all the components of filename except the last parts by the level" do - File.dirname('/home/jason', 2).should == '/' - File.dirname('/home/jason/poot.txt', 2).should == '/home' - end - - it "returns the same String if the level is 0" do - File.dirname('poot.txt', 0).should == 'poot.txt' - File.dirname('/', 0).should == '/' - end - - it "raises ArgumentError if the level is negative" do - -> { - File.dirname('/home/jason', -1) - }.should raise_error(ArgumentError, "negative level: -1") - end - - it "returns '/' when level exceeds the number of segments in the path" do - File.dirname("/home/jason", 100).should == '/' - end - - it "calls #to_int if passed not numeric value" do - object = Object.new - def object.to_int; 2; end - - File.dirname("/a/b/c/d", object).should == '/a/b' - end + context "when level is passed" do + it "returns all the components of filename except the last parts by the level" do + File.dirname('/home/jason', 2).should == '/' + File.dirname('/home/jason/poot.txt', 2).should == '/home' + end + + it "returns the same String if the level is 0" do + File.dirname('poot.txt', 0).should == 'poot.txt' + File.dirname('/', 0).should == '/' + end + + it "raises ArgumentError if the level is negative" do + -> { + File.dirname('/home/jason', -1) + }.should raise_error(ArgumentError, "negative level: -1") + end + + it "returns '/' when level exceeds the number of segments in the path" do + File.dirname("/home/jason", 100).should == '/' + end + + it "calls #to_int if passed not numeric value" do + object = Object.new + def object.to_int; 2; end + + File.dirname("/a/b/c/d", object).should == '/a/b' end end diff --git a/core/file/shared/path.rb b/core/file/shared/path.rb index aa2a64cf25..5a9fe1b0c5 100644 --- a/core/file/shared/path.rb +++ b/core/file/shared/path.rb @@ -77,18 +77,6 @@ after :each do rm_r @dir end - - ruby_version_is ""..."3.1" do - it "raises IOError if file was opened with File::TMPFILE" do - begin - File.open(@dir, File::RDWR | File::TMPFILE) do |f| - -> { f.send(@method) }.should raise_error(IOError) - end - rescue Errno::EOPNOTSUPP, Errno::EINVAL, Errno::EISDIR - skip "no support from the filesystem" - end - end - end end end end diff --git a/core/gc/measure_total_time_spec.rb b/core/gc/measure_total_time_spec.rb index 05d4598ebc..f5377c18fd 100644 --- a/core/gc/measure_total_time_spec.rb +++ b/core/gc/measure_total_time_spec.rb @@ -1,19 +1,17 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe "GC.measure_total_time" do - before :each do - @default = GC.measure_total_time - end +describe "GC.measure_total_time" do + before :each do + @default = GC.measure_total_time + end - after :each do - GC.measure_total_time = @default - end + after :each do + GC.measure_total_time = @default + end - it "can set and get a boolean value" do - original = GC.measure_total_time - GC.measure_total_time = !original - GC.measure_total_time.should == !original - end + it "can set and get a boolean value" do + original = GC.measure_total_time + GC.measure_total_time = !original + GC.measure_total_time.should == !original end end diff --git a/core/gc/total_time_spec.rb b/core/gc/total_time_spec.rb index fcc8f45a83..a8430fbe9a 100644 --- a/core/gc/total_time_spec.rb +++ b/core/gc/total_time_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe "GC.total_time" do - it "returns an Integer" do - GC.total_time.should be_kind_of(Integer) - end +describe "GC.total_time" do + it "returns an Integer" do + GC.total_time.should be_kind_of(Integer) + end - it "increases as collections are run" do - time_before = GC.total_time - GC.start - GC.total_time.should >= time_before - end + it "increases as collections are run" do + time_before = GC.total_time + GC.start + GC.total_time.should >= time_before end end diff --git a/core/hash/hash_spec.rb b/core/hash/hash_spec.rb index 9b47d4b2bf..cd67f7a652 100644 --- a/core/hash/hash_spec.rb +++ b/core/hash/hash_spec.rb @@ -42,12 +42,10 @@ # Like above, because h.eql?(x: [h]) end - ruby_version_is "3.1" do - it "allows omitting values" do - a = 1 - b = 2 + it "allows omitting values" do + a = 1 + b = 2 - eval('{a:, b:}.should == { a: 1, b: 2 }') - end + {a:, b:}.should == { a: 1, b: 2 } end end diff --git a/core/integer/try_convert_spec.rb b/core/integer/try_convert_spec.rb index 4bc7d3851a..8a0ca671a9 100644 --- a/core/integer/try_convert_spec.rb +++ b/core/integer/try_convert_spec.rb @@ -1,50 +1,48 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "3.1" do - describe "Integer.try_convert" do - it "returns the argument if it's an Integer" do - x = 42 - Integer.try_convert(x).should equal(x) - end +describe "Integer.try_convert" do + it "returns the argument if it's an Integer" do + x = 42 + Integer.try_convert(x).should equal(x) + end - it "returns nil when the argument does not respond to #to_int" do - Integer.try_convert(Object.new).should be_nil - end + it "returns nil when the argument does not respond to #to_int" do + Integer.try_convert(Object.new).should be_nil + end - it "sends #to_int to the argument and returns the result if it's nil" do - obj = mock("to_int") - obj.should_receive(:to_int).and_return(nil) - Integer.try_convert(obj).should be_nil - end + it "sends #to_int to the argument and returns the result if it's nil" do + obj = mock("to_int") + obj.should_receive(:to_int).and_return(nil) + Integer.try_convert(obj).should be_nil + end - it "sends #to_int to the argument and returns the result if it's an Integer" do - x = 234 - obj = mock("to_int") - obj.should_receive(:to_int).and_return(x) - Integer.try_convert(obj).should equal(x) - end + it "sends #to_int to the argument and returns the result if it's an Integer" do + x = 234 + obj = mock("to_int") + obj.should_receive(:to_int).and_return(x) + Integer.try_convert(obj).should equal(x) + end - it "sends #to_int to the argument and raises TypeError if it's not a kind of Integer" do - obj = mock("to_int") - obj.should_receive(:to_int).and_return(Object.new) - -> { - Integer.try_convert obj - }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives Object)") - end + it "sends #to_int to the argument and raises TypeError if it's not a kind of Integer" do + obj = mock("to_int") + obj.should_receive(:to_int).and_return(Object.new) + -> { + Integer.try_convert obj + }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives Object)") + end - it "responds with a different error message when it raises a TypeError, depending on the type of the non-Integer object :to_int returns" do - obj = mock("to_int") - obj.should_receive(:to_int).and_return("A String") - -> { - Integer.try_convert obj - }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives String)") - end + it "responds with a different error message when it raises a TypeError, depending on the type of the non-Integer object :to_int returns" do + obj = mock("to_int") + obj.should_receive(:to_int).and_return("A String") + -> { + Integer.try_convert obj + }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives String)") + end - it "does not rescue exceptions raised by #to_int" do - obj = mock("to_int") - obj.should_receive(:to_int).and_raise(RuntimeError) - -> { Integer.try_convert obj }.should raise_error(RuntimeError) - end + it "does not rescue exceptions raised by #to_int" do + obj = mock("to_int") + obj.should_receive(:to_int).and_raise(RuntimeError) + -> { Integer.try_convert obj }.should raise_error(RuntimeError) end end diff --git a/core/io/external_encoding_spec.rb b/core/io/external_encoding_spec.rb index 2fcf1c7218..7765c6c0f5 100644 --- a/core/io/external_encoding_spec.rb +++ b/core/io/external_encoding_spec.rb @@ -94,12 +94,10 @@ rm_r @name end - ruby_version_is '3.1' do - it "can be retrieved from a closed stream" do - io = IOSpecs.io_fixture("lines.txt", "r") - io.close - io.external_encoding.should equal(Encoding.default_external) - end + it "can be retrieved from a closed stream" do + io = IOSpecs.io_fixture("lines.txt", "r") + io.close + io.external_encoding.should equal(Encoding.default_external) end describe "with 'r' mode" do diff --git a/core/io/internal_encoding_spec.rb b/core/io/internal_encoding_spec.rb index 60afaf2ebd..7a583d4bcb 100644 --- a/core/io/internal_encoding_spec.rb +++ b/core/io/internal_encoding_spec.rb @@ -113,12 +113,10 @@ Encoding.default_internal = @internal end - ruby_version_is '3.1' do - it "can be retrieved from a closed stream" do - io = IOSpecs.io_fixture("lines.txt", "r") - io.close - io.internal_encoding.should equal(Encoding.default_internal) - end + it "can be retrieved from a closed stream" do + io = IOSpecs.io_fixture("lines.txt", "r") + io.close + io.internal_encoding.should equal(Encoding.default_internal) end describe "with 'r' mode" do diff --git a/core/kernel/require_spec.rb b/core/kernel/require_spec.rb index 4029e68725..e78e7176ec 100644 --- a/core/kernel/require_spec.rb +++ b/core/kernel/require_spec.rb @@ -16,10 +16,7 @@ Kernel.should have_private_instance_method(:require) end - provided = %w[complex enumerator rational thread ruby2_keywords] - ruby_version_is "3.1" do - provided << "fiber" - end + provided = %w[complex enumerator fiber rational thread ruby2_keywords] it "#{provided.join(', ')} are already required" do out = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems --disable-did-you-mean') diff --git a/core/kernel/shared/load.rb b/core/kernel/shared/load.rb index 0fe2d5ce16..62c5c7be9b 100644 --- a/core/kernel/shared/load.rb +++ b/core/kernel/shared/load.rb @@ -165,37 +165,35 @@ end describe "when passed a module for 'wrap'" do - ruby_version_is "3.1" do - it "sets the enclosing scope to the supplied module" do - path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR - mod = Module.new - @object.load(path, mod) + it "sets the enclosing scope to the supplied module" do + path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR + mod = Module.new + @object.load(path, mod) - Object.const_defined?(:LoadSpecWrap).should be_false - mod.const_defined?(:LoadSpecWrap).should be_true + Object.const_defined?(:LoadSpecWrap).should be_false + mod.const_defined?(:LoadSpecWrap).should be_true - wrap_module = ScratchPad.recorded[1] - wrap_module.should == mod - end + wrap_module = ScratchPad.recorded[1] + wrap_module.should == mod + end - it "makes constants and instance methods in the source file reachable with the supplied module" do - path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR - mod = Module.new - @object.load(path, mod) + it "makes constants and instance methods in the source file reachable with the supplied module" do + path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR + mod = Module.new + @object.load(path, mod) - mod::LOAD_WRAP_SPECS_TOP_LEVEL_CONSTANT.should == 1 - obj = Object.new - obj.extend(mod) - obj.send(:load_wrap_specs_top_level_method).should == :load_wrap_specs_top_level_method - end + mod::LOAD_WRAP_SPECS_TOP_LEVEL_CONSTANT.should == 1 + obj = Object.new + obj.extend(mod) + obj.send(:load_wrap_specs_top_level_method).should == :load_wrap_specs_top_level_method + end - it "makes instance methods in the source file private" do - path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR - mod = Module.new - @object.load(path, mod) + it "makes instance methods in the source file private" do + path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR + mod = Module.new + @object.load(path, mod) - mod.private_instance_methods.include?(:load_wrap_specs_top_level_method).should == true - end + mod.private_instance_methods.include?(:load_wrap_specs_top_level_method).should == true end end diff --git a/core/main/private_spec.rb b/core/main/private_spec.rb index e8c1f3f44c..76895fd649 100644 --- a/core/main/private_spec.rb +++ b/core/main/private_spec.rb @@ -30,16 +30,8 @@ end end - ruby_version_is ''...'3.1' do - it "returns Object" do - eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object) - end - end - - ruby_version_is '3.1' do - it "returns argument" do - eval("private :main_public_method", TOPLEVEL_BINDING).should equal(:main_public_method) - end + it "returns argument" do + eval("private :main_public_method", TOPLEVEL_BINDING).should equal(:main_public_method) end it "raises a NameError when at least one of given method names is undefined" do diff --git a/core/main/public_spec.rb b/core/main/public_spec.rb index 31baad4583..3c77798fbc 100644 --- a/core/main/public_spec.rb +++ b/core/main/public_spec.rb @@ -30,16 +30,8 @@ end end - ruby_version_is ''...'3.1' do - it "returns Object" do - eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object) - end - end - - ruby_version_is '3.1' do - it "returns argument" do - eval("public :main_private_method", TOPLEVEL_BINDING).should equal(:main_private_method) - end + it "returns argument" do + eval("public :main_private_method", TOPLEVEL_BINDING).should equal(:main_private_method) end diff --git a/core/marshal/dump_spec.rb b/core/marshal/dump_spec.rb index 716ba0e946..6f1b3bf42a 100644 --- a/core/marshal/dump_spec.rb +++ b/core/marshal/dump_spec.rb @@ -586,20 +586,18 @@ def _dump(level) Marshal.dump(Hash.new(1)).should == "\004\b}\000i\006" end - ruby_version_is "3.1" do - it "dumps a Hash with compare_by_identity" do - h = {} - h.compare_by_identity + it "dumps a Hash with compare_by_identity" do + h = {} + h.compare_by_identity - Marshal.dump(h).should == "\004\bC:\tHash{\x00" - end + Marshal.dump(h).should == "\004\bC:\tHash{\x00" + end - it "dumps a Hash subclass with compare_by_identity" do - h = UserHash.new - h.compare_by_identity + it "dumps a Hash subclass with compare_by_identity" do + h = UserHash.new + h.compare_by_identity - Marshal.dump(h).should == "\x04\bC:\rUserHashC:\tHash{\x00" - end + Marshal.dump(h).should == "\x04\bC:\rUserHashC:\tHash{\x00" end it "raises a TypeError with hash having default proc" do diff --git a/core/marshal/shared/load.rb b/core/marshal/shared/load.rb index fd6490153c..f73fa67e9a 100644 --- a/core/marshal/shared/load.rb +++ b/core/marshal/shared/load.rb @@ -23,250 +23,164 @@ -> { Marshal.send(@method, kaboom) }.should raise_error(ArgumentError) end - ruby_version_is "3.1" do - describe "when called with freeze: true" do - it "returns frozen strings" do - string = Marshal.send(@method, Marshal.dump("foo"), freeze: true) - string.should == "foo" - string.should.frozen? - - utf8_string = "foo".encode(Encoding::UTF_8) - string = Marshal.send(@method, Marshal.dump(utf8_string), freeze: true) - string.should == utf8_string - string.should.frozen? - end - - it "returns frozen arrays" do - array = Marshal.send(@method, Marshal.dump([1, 2, 3]), freeze: true) - array.should == [1, 2, 3] - array.should.frozen? - end - - it "returns frozen hashes" do - hash = Marshal.send(@method, Marshal.dump({foo: 42}), freeze: true) - hash.should == {foo: 42} - hash.should.frozen? - end - - it "returns frozen regexps" do - regexp = Marshal.send(@method, Marshal.dump(/foo/), freeze: true) - regexp.should == /foo/ - regexp.should.frozen? - end + describe "when called with freeze: true" do + it "returns frozen strings" do + string = Marshal.send(@method, Marshal.dump("foo"), freeze: true) + string.should == "foo" + string.should.frozen? - it "returns frozen structs" do - struct = Marshal.send(@method, Marshal.dump(MarshalSpec::StructToDump.new(1, 2)), freeze: true) - struct.should == MarshalSpec::StructToDump.new(1, 2) - struct.should.frozen? - end + utf8_string = "foo".encode(Encoding::UTF_8) + string = Marshal.send(@method, Marshal.dump(utf8_string), freeze: true) + string.should == utf8_string + string.should.frozen? + end - it "returns frozen objects" do - source_object = Object.new + it "returns frozen arrays" do + array = Marshal.send(@method, Marshal.dump([1, 2, 3]), freeze: true) + array.should == [1, 2, 3] + array.should.frozen? + end - object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - object.should.frozen? - end + it "returns frozen hashes" do + hash = Marshal.send(@method, Marshal.dump({foo: 42}), freeze: true) + hash.should == {foo: 42} + hash.should.frozen? + end - describe "deep freezing" do - it "returns hashes with frozen keys and values" do - key = Object.new - value = Object.new - source_object = {key => value} + it "returns frozen regexps" do + regexp = Marshal.send(@method, Marshal.dump(/foo/), freeze: true) + regexp.should == /foo/ + regexp.should.frozen? + end - hash = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - hash.size.should == 1 - hash.keys[0].should.frozen? - hash.values[0].should.frozen? - end + it "returns frozen structs" do + struct = Marshal.send(@method, Marshal.dump(MarshalSpec::StructToDump.new(1, 2)), freeze: true) + struct.should == MarshalSpec::StructToDump.new(1, 2) + struct.should.frozen? + end - it "returns arrays with frozen elements" do - object = Object.new - source_object = [object] + it "returns frozen objects" do + source_object = Object.new - array = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - array.size.should == 1 - array[0].should.frozen? - end + object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + object.should.frozen? + end - it "returns structs with frozen members" do - object1 = Object.new - object2 = Object.new - source_object = MarshalSpec::StructToDump.new(object1, object2) + describe "deep freezing" do + it "returns hashes with frozen keys and values" do + key = Object.new + value = Object.new + source_object = {key => value} - struct = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - struct.a.should.frozen? - struct.b.should.frozen? - end + hash = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + hash.size.should == 1 + hash.keys[0].should.frozen? + hash.values[0].should.frozen? + end - it "returns objects with frozen instance variables" do - source_object = Object.new - instance_variable = Object.new - source_object.instance_variable_set(:@a, instance_variable) + it "returns arrays with frozen elements" do + object = Object.new + source_object = [object] - object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - object.instance_variable_get(:@a).should != nil - object.instance_variable_get(:@a).should.frozen? - end + array = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + array.size.should == 1 + array[0].should.frozen? + end - it "deduplicates frozen strings" do - source_object = ["foo" + "bar", "foobar"] - object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + it "returns structs with frozen members" do + object1 = Object.new + object2 = Object.new + source_object = MarshalSpec::StructToDump.new(object1, object2) - object[0].should equal(object[1]) - end + struct = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + struct.a.should.frozen? + struct.b.should.frozen? end - it "does not freeze modules" do - object = Marshal.send(@method, Marshal.dump(Kernel), freeze: true) - object.should_not.frozen? - Kernel.should_not.frozen? - end + it "returns objects with frozen instance variables" do + source_object = Object.new + instance_variable = Object.new + source_object.instance_variable_set(:@a, instance_variable) - it "does not freeze classes" do - object = Marshal.send(@method, Marshal.dump(Object), freeze: true) - object.should_not.frozen? - Object.should_not.frozen? + object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + object.instance_variable_get(:@a).should != nil + object.instance_variable_get(:@a).should.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 "deduplicates frozen strings" do + source_object = ["foo" + "bar", "foobar"] + object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) - 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 + object[0].should equal(object[1]) end + end - ruby_bug "#19427", "3.1"..."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 responding to #marshal_dump and #marshal_load" do - object = Marshal.send(@method, Marshal.dump(UserMarshal.new), freeze: true) - object.should.frozen? - end + it "does not freeze modules" do + object = Marshal.send(@method, Marshal.dump(Kernel), freeze: true) + object.should_not.frozen? + Kernel.should_not.frozen? + end - it "returns frozen object extended by a module" do - object = Object.new - object.extend(MarshalSpec::ModuleToExtendBy) + it "does not freeze classes" do + object = Marshal.send(@method, Marshal.dump(Object), freeze: true) + object.should_not.frozen? + Object.should_not.frozen? + end - object = Marshal.send(@method, Marshal.dump(object), freeze: true) - object.should.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 not call freeze method" do - object = MarshalSpec::ObjectWithFreezeRaisingException.new - object = Marshal.send(@method, Marshal.dump(object), freeze: true) + 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 + end - it "returns frozen object even if object does not respond to freeze method" do - object = MarshalSpec::ObjectWithoutFreeze.new - object = Marshal.send(@method, Marshal.dump(object), freeze: true) + ruby_bug "#19427", "3.1"..."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 a frozen object when is an instance of String/Array/Regexp/Hash subclass and has instance variables" do - source_object = UserString.new - source_object.instance_variable_set(:@foo, "bar") - - object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + 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 - describe "when called with a proc" do - it "call the proc with frozen objects" do - arr = [] - s = +'hi' - s.instance_variable_set(:@foo, 5) - st = Struct.new("Brittle", :a).new - st.instance_variable_set(:@clue, 'none') - st.a = 0.0 - h = Hash.new('def') - h['nine'] = 9 - a = [:a, :b, :c] - a.instance_variable_set(:@two, 2) - obj = [s, 10, s, s, st, a] - obj.instance_variable_set(:@zoo, 'ant') - proc = Proc.new { |o| arr << o; o} - - Marshal.send( - @method, - "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", - proc, - freeze: true, - ) - - arr.should == [ - false, 5, "hi", 10, "hi", "hi", 0.0, false, "none", st, - :b, :c, 2, a, false, "ant", ["hi", 10, "hi", "hi", st, [:a, :b, :c]], - ] - - arr.each do |v| - v.should.frozen? - end - - Struct.send(:remove_const, :Brittle) - end + it "returns frozen object extended by a module" do + object = Object.new + object.extend(MarshalSpec::ModuleToExtendBy) - it "does not freeze the object returned by the proc" do - string = Marshal.send(@method, Marshal.dump("foo"), proc { |o| o.upcase }, freeze: true) - string.should == "FOO" - string.should_not.frozen? - end + object = Marshal.send(@method, Marshal.dump(object), freeze: true) + object.should.frozen? end end - end - describe "when called with a proc" do - ruby_bug "#18141", ""..."3.1" do - it "call the proc with fully initialized strings" do - utf8_string = "foo".encode(Encoding::UTF_8) - Marshal.send(@method, Marshal.dump(utf8_string), proc { |arg| - if arg.is_a?(String) - arg.should == utf8_string - arg.encoding.should == Encoding::UTF_8 - end - arg - }) - end - - it "no longer mutate the object after it was passed to the proc" do - string = Marshal.load(Marshal.dump("foo"), :freeze.to_proc) - string.should.frozen? - end + it "does not call freeze method" do + object = MarshalSpec::ObjectWithFreezeRaisingException.new + object = Marshal.send(@method, Marshal.dump(object), freeze: true) + object.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 "returns frozen object even if object does not respond to freeze method" do + object = MarshalSpec::ObjectWithoutFreeze.new + object = Marshal.send(@method, Marshal.dump(object), freeze: true) + object.should.frozen? end - it "returns the value of the proc" do - Marshal.send(@method, Marshal.dump([1,2]), proc { [3,4] }).should == [3,4] - end + it "returns a frozen object when is an instance of String/Array/Regexp/Hash subclass and has instance variables" do + source_object = UserString.new + source_object.instance_variable_set(:@foo, "bar") - ruby_bug "#18141", ""..."3.1" do - it "calls the proc for recursively visited data" do - a = [1] - a << a - ret = [] - Marshal.send(@method, Marshal.dump(a), proc { |arg| ret << arg.inspect; arg }) - ret[0].should == 1.inspect - ret[1].should == a.inspect - ret.size.should == 2 - end + object = Marshal.send(@method, Marshal.dump(source_object), freeze: true) + object.should.frozen? + end - it "loads an Array with proc" do + describe "when called with a proc" do + it "call the proc with frozen objects" do arr = [] s = +'hi' s.instance_variable_set(:@foo, 5) @@ -279,16 +193,96 @@ a.instance_variable_set(:@two, 2) obj = [s, 10, s, s, st, a] obj.instance_variable_set(:@zoo, 'ant') - proc = Proc.new { |o| arr << o.dup; o} + proc = Proc.new { |o| arr << o; o} - Marshal.send(@method, "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", proc) + Marshal.send( + @method, + "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", + proc, + freeze: true, + ) arr.should == [ false, 5, "hi", 10, "hi", "hi", 0.0, false, "none", st, :b, :c, 2, a, false, "ant", ["hi", 10, "hi", "hi", st, [:a, :b, :c]], ] + + arr.each do |v| + v.should.frozen? + end + Struct.send(:remove_const, :Brittle) end + + it "does not freeze the object returned by the proc" do + string = Marshal.send(@method, Marshal.dump("foo"), proc { |o| o.upcase }, freeze: true) + string.should == "FOO" + string.should_not.frozen? + end + end + end + + describe "when called with a proc" do + it "call the proc with fully initialized strings" do + utf8_string = "foo".encode(Encoding::UTF_8) + Marshal.send(@method, Marshal.dump(utf8_string), proc { |arg| + if arg.is_a?(String) + arg.should == utf8_string + arg.encoding.should == Encoding::UTF_8 + end + arg + }) + end + + it "no longer mutate the object after it was passed to the proc" do + string = Marshal.load(Marshal.dump("foo"), :freeze.to_proc) + 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 + end + + it "returns the value of the proc" do + Marshal.send(@method, Marshal.dump([1,2]), proc { [3,4] }).should == [3,4] + end + + it "calls the proc for recursively visited data" do + a = [1] + a << a + ret = [] + Marshal.send(@method, Marshal.dump(a), proc { |arg| ret << arg.inspect; arg }) + ret[0].should == 1.inspect + ret[1].should == a.inspect + ret.size.should == 2 + end + + it "loads an Array with proc" do + arr = [] + s = +'hi' + s.instance_variable_set(:@foo, 5) + st = Struct.new("Brittle", :a).new + st.instance_variable_set(:@clue, 'none') + st.a = 0.0 + h = Hash.new('def') + h['nine'] = 9 + a = [:a, :b, :c] + a.instance_variable_set(:@two, 2) + obj = [s, 10, s, s, st, a] + obj.instance_variable_set(:@zoo, 'ant') + proc = Proc.new { |o| arr << o.dup; o} + + Marshal.send(@method, "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", proc) + + arr.should == [ + false, 5, "hi", 10, "hi", "hi", 0.0, false, "none", st, + :b, :c, 2, a, false, "ant", ["hi", 10, "hi", "hi", st, [:a, :b, :c]], + ] + Struct.send(:remove_const, :Brittle) end end @@ -364,39 +358,37 @@ end end - ruby_bug "#18141", ""..."3.1" do - it "loads an array containing objects having _dump method, and with proc" do - arr = [] - myproc = Proc.new { |o| arr << o.dup; o } - o1 = UserDefined.new; - o2 = UserDefinedWithIvar.new - obj = [o1, o2, o1, o2] + it "loads an array containing objects having _dump method, and with proc" do + arr = [] + myproc = Proc.new { |o| arr << o.dup; o } + o1 = UserDefined.new; + o2 = UserDefinedWithIvar.new + obj = [o1, o2, o1, o2] - Marshal.send(@method, "\x04\b[\tu:\x10UserDefined\x18\x04\b[\aI\"\nstuff\x06:\x06EF@\x06u:\x18UserDefinedWithIvar>\x04\b[\bI\"\nstuff\a:\x06EF:\t@foo:\x18UserDefinedWithIvarI\"\tmore\x06;\x00F@\a@\x06@\a", myproc) + Marshal.send(@method, "\x04\b[\tu:\x10UserDefined\x18\x04\b[\aI\"\nstuff\x06:\x06EF@\x06u:\x18UserDefinedWithIvar>\x04\b[\bI\"\nstuff\a:\x06EF:\t@foo:\x18UserDefinedWithIvarI\"\tmore\x06;\x00F@\a@\x06@\a", myproc) - arr[0].should == o1 - arr[1].should == o2 - arr[2].should == obj - arr.size.should == 3 - end + arr[0].should == o1 + arr[1].should == o2 + arr[2].should == obj + arr.size.should == 3 + end - it "loads an array containing objects having marshal_dump method, and with proc" do - arr = [] - proc = Proc.new { |o| arr << o.dup; o } - o1 = UserMarshal.new - o2 = UserMarshalWithIvar.new + it "loads an array containing objects having marshal_dump method, and with proc" do + arr = [] + proc = Proc.new { |o| arr << o.dup; o } + o1 = UserMarshal.new + o2 = UserMarshalWithIvar.new - Marshal.send(@method, "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc) + Marshal.send(@method, "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc) - arr[0].should == 'stuff' - arr[1].should == o1 - arr[2].should == 'my data' - arr[3].should == ['my data'] - arr[4].should == o2 - arr[5].should == [o1, o2, o1, o2] + arr[0].should == 'stuff' + arr[1].should == o1 + arr[2].should == 'my data' + arr[3].should == ['my data'] + arr[4].should == o2 + arr[5].should == [o1, o2, o1, o2] - arr.size.should == 6 - end + arr.size.should == 6 end it "assigns classes to nested subclasses of Array correctly" do @@ -526,28 +518,26 @@ unmarshalled[:key].instance_variable_get(:@string_ivar).should == 'string ivar' end - ruby_version_is "3.1" do - it "preserves compare_by_identity behaviour" do - h = { a: 1 } - h.compare_by_identity - unmarshalled = Marshal.send(@method, Marshal.dump(h)) - unmarshalled.should.compare_by_identity? + it "preserves compare_by_identity behaviour" do + h = { a: 1 } + h.compare_by_identity + unmarshalled = Marshal.send(@method, Marshal.dump(h)) + unmarshalled.should.compare_by_identity? - h = { a: 1 } - unmarshalled = Marshal.send(@method, Marshal.dump(h)) - unmarshalled.should_not.compare_by_identity? - end + h = { a: 1 } + unmarshalled = Marshal.send(@method, Marshal.dump(h)) + unmarshalled.should_not.compare_by_identity? + end - it "preserves compare_by_identity behaviour for a Hash subclass" do - h = UserHash.new({ a: 1 }) - h.compare_by_identity - unmarshalled = Marshal.send(@method, Marshal.dump(h)) - unmarshalled.should.compare_by_identity? + it "preserves compare_by_identity behaviour for a Hash subclass" do + h = UserHash.new({ a: 1 }) + h.compare_by_identity + unmarshalled = Marshal.send(@method, Marshal.dump(h)) + unmarshalled.should.compare_by_identity? - h = UserHash.new({ a: 1 }) - unmarshalled = Marshal.send(@method, Marshal.dump(h)) - unmarshalled.should_not.compare_by_identity? - end + h = UserHash.new({ a: 1 }) + unmarshalled = Marshal.send(@method, Marshal.dump(h)) + unmarshalled.should_not.compare_by_identity? end it "allocates an instance of the proper class when Hash subclass with compare_by_identity behaviour" do diff --git a/core/matchdata/match_length_spec.rb b/core/matchdata/match_length_spec.rb index f7785ab1a0..824f94a397 100644 --- a/core/matchdata/match_length_spec.rb +++ b/core/matchdata/match_length_spec.rb @@ -2,33 +2,31 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe "MatchData#match_length" do - it "returns the length of the corresponding match when given an Integer" do - md = /(.)(.)(\d+)(\d)/.match("THX1138.") +describe "MatchData#match_length" do + it "returns the length of the corresponding match when given an Integer" do + md = /(.)(.)(\d+)(\d)/.match("THX1138.") - md.match_length(0).should == 6 - md.match_length(1).should == 1 - md.match_length(2).should == 1 - md.match_length(3).should == 3 - md.match_length(4).should == 1 - end + md.match_length(0).should == 6 + md.match_length(1).should == 1 + md.match_length(2).should == 1 + md.match_length(3).should == 3 + md.match_length(4).should == 1 + end - it "returns nil on non-matching index matches" do - md = /\d+(\w)?/.match("THX1138.") - md.match_length(1).should == nil - end + it "returns nil on non-matching index matches" do + md = /\d+(\w)?/.match("THX1138.") + md.match_length(1).should == nil + end - it "returns the length of the corresponding named match when given a Symbol" do - md = 'haystack'.match(/(?t(?ack))/) - md.match_length(:a).should == 3 - md.match_length(:t).should == 4 - end + it "returns the length of the corresponding named match when given a Symbol" do + md = 'haystack'.match(/(?t(?ack))/) + md.match_length(:a).should == 3 + md.match_length(:t).should == 4 + end - it "returns nil on non-matching index matches" do - md = 'haystack'.match(/(?t)(?all)?/) - md.match_length(:t).should == 1 - md.match_length(:a).should == nil - end + it "returns nil on non-matching index matches" do + md = 'haystack'.match(/(?t)(?all)?/) + md.match_length(:t).should == 1 + md.match_length(:a).should == nil end end diff --git a/core/matchdata/match_spec.rb b/core/matchdata/match_spec.rb index 545de6f93f..a16914ea15 100644 --- a/core/matchdata/match_spec.rb +++ b/core/matchdata/match_spec.rb @@ -2,33 +2,31 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe "MatchData#match" do - it "returns the corresponding match when given an Integer" do - md = /(.)(.)(\d+)(\d)/.match("THX1138.") +describe "MatchData#match" do + it "returns the corresponding match when given an Integer" do + md = /(.)(.)(\d+)(\d)/.match("THX1138.") - md.match(0).should == 'HX1138' - md.match(1).should == 'H' - md.match(2).should == 'X' - md.match(3).should == '113' - md.match(4).should == '8' - end + md.match(0).should == 'HX1138' + md.match(1).should == 'H' + md.match(2).should == 'X' + md.match(3).should == '113' + md.match(4).should == '8' + end - it "returns nil on non-matching index matches" do - md = /\d+(\w)?/.match("THX1138.") - md.match(1).should == nil - end + it "returns nil on non-matching index matches" do + md = /\d+(\w)?/.match("THX1138.") + md.match(1).should == nil + end - it "returns the corresponding named match when given a Symbol" do - md = 'haystack'.match(/(?t(?ack))/) - md.match(:a).should == 'ack' - md.match(:t).should == 'tack' - end + it "returns the corresponding named match when given a Symbol" do + md = 'haystack'.match(/(?t(?ack))/) + md.match(:a).should == 'ack' + md.match(:t).should == 'tack' + end - it "returns nil on non-matching index matches" do - md = 'haystack'.match(/(?t)(?all)?/) - md.match(:t).should == 't' - md.match(:a).should == nil - end + it "returns nil on non-matching index matches" do + md = 'haystack'.match(/(?t)(?all)?/) + md.match(:t).should == 't' + md.match(:a).should == nil end end diff --git a/core/method/parameters_spec.rb b/core/method/parameters_spec.rb index 8495aef4d2..0178a61de6 100644 --- a/core/method/parameters_spec.rb +++ b/core/method/parameters_spec.rb @@ -257,30 +257,17 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end end end - ruby_version_is '3.1' do - it "adds block arg with name & for anonymous block argument" do - object = Object.new - - eval(<<~RUBY).should == [[:block, :&]] - def object.foo(&) - end - object.method(:foo).parameters - RUBY + it "adds block arg with name & for anonymous block argument" do + object = Object.new + def object.foo(&) end - end - ruby_version_is ""..."3.1" do - it "returns [:rest, :*], [:block, :&] for forward parameters operator" do - m = MethodSpecs::Methods.new - m.method(:forward_parameters).parameters.should == [[:rest, :*], [:block, :&]] - end + object.method(:foo).parameters.should == [[:block, :&]] end - ruby_version_is "3.1" do - it "returns [:rest, :*], [:keyrest, :**], [:block, :&] for forward parameters operator" do - m = MethodSpecs::Methods.new - m.method(:forward_parameters).parameters.should == [[:rest, :*], [:keyrest, :**], [:block, :&]] - end + it "returns [:rest, :*], [:keyrest, :**], [:block, :&] for forward parameters operator" do + m = MethodSpecs::Methods.new + m.method(:forward_parameters).parameters.should == [[:rest, :*], [:keyrest, :**], [:block, :&]] end it "returns the args and block for a splat and block argument" do diff --git a/core/method/private_spec.rb b/core/method/private_spec.rb index fd550036a3..9b67a77243 100644 --- a/core/method/private_spec.rb +++ b/core/method/private_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "Method#private?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns false when the method is public" do obj = MethodSpecs::Methods.new obj.method(:my_public_method).private?.should == false diff --git a/core/method/protected_spec.rb b/core/method/protected_spec.rb index 8423e8c64c..28c60c7536 100644 --- a/core/method/protected_spec.rb +++ b/core/method/protected_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "Method#protected?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns false when the method is public" do obj = MethodSpecs::Methods.new obj.method(:my_public_method).protected?.should == false diff --git a/core/method/public_spec.rb b/core/method/public_spec.rb index 20d0081a27..4844f4b90b 100644 --- a/core/method/public_spec.rb +++ b/core/method/public_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "Method#public?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns true when the method is public" do obj = MethodSpecs::Methods.new obj.method(:my_public_method).public?.should == true diff --git a/core/module/autoload_spec.rb b/core/module/autoload_spec.rb index 45d18b8608..3cdc48f9ba 100644 --- a/core/module/autoload_spec.rb +++ b/core/module/autoload_spec.rb @@ -486,42 +486,21 @@ def check_before_during_thread_after(const, &check) ScratchPad.recorded.should == [:raise, :raise] end - ruby_version_is "3.1" do - it "removes the constant from Module#constants if the loaded file does not define it" do - path = fixture(__FILE__, "autoload_o.rb") - ScratchPad.record [] - ModuleSpecs::Autoload.autoload :O, path - - ModuleSpecs::Autoload.const_defined?(:O).should == true - ModuleSpecs::Autoload.should have_constant(:O) - ModuleSpecs::Autoload.autoload?(:O).should == path - - -> { ModuleSpecs::Autoload::O }.should raise_error(NameError) - - ModuleSpecs::Autoload.const_defined?(:O).should == false - ModuleSpecs::Autoload.should_not have_constant(:O) - ModuleSpecs::Autoload.autoload?(:O).should == nil - -> { ModuleSpecs::Autoload.const_get(:O) }.should raise_error(NameError) - end - end - - ruby_version_is ""..."3.1" do - it "does not remove the constant from Module#constants if the loaded file does not define it, but leaves it as 'undefined'" do - path = fixture(__FILE__, "autoload_o.rb") - ScratchPad.record [] - ModuleSpecs::Autoload.autoload :O, path + it "removes the constant from Module#constants if the loaded file does not define it" do + path = fixture(__FILE__, "autoload_o.rb") + ScratchPad.record [] + ModuleSpecs::Autoload.autoload :O, path - ModuleSpecs::Autoload.const_defined?(:O).should == true - ModuleSpecs::Autoload.should have_constant(:O) - ModuleSpecs::Autoload.autoload?(:O).should == path + ModuleSpecs::Autoload.const_defined?(:O).should == true + ModuleSpecs::Autoload.should have_constant(:O) + ModuleSpecs::Autoload.autoload?(:O).should == path - -> { ModuleSpecs::Autoload::O }.should raise_error(NameError) + -> { ModuleSpecs::Autoload::O }.should raise_error(NameError) - ModuleSpecs::Autoload.const_defined?(:O).should == false - ModuleSpecs::Autoload.should have_constant(:O) - ModuleSpecs::Autoload.autoload?(:O).should == nil - -> { ModuleSpecs::Autoload.const_get(:O) }.should raise_error(NameError) - end + ModuleSpecs::Autoload.const_defined?(:O).should == false + ModuleSpecs::Autoload.should_not have_constant(:O) + ModuleSpecs::Autoload.autoload?(:O).should == nil + -> { ModuleSpecs::Autoload.const_get(:O) }.should raise_error(NameError) end it "does not try to load the file again if the loaded file did not define the constant" do @@ -654,48 +633,23 @@ module Autoload end end - ruby_version_is "3.1" do - it "looks up in parent scope after failed autoload" do - @remove << :DeclaredInCurrentDefinedInParent - module ModuleSpecs::Autoload - ScratchPad.record -> { - DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent - } - - class LexicalScope - autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb") - -> { DeclaredInCurrentDefinedInParent }.should_not raise_error(NameError) - # Basically, the autoload constant remains in a "undefined" state - self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil - const_defined?(:DeclaredInCurrentDefinedInParent).should == false - -> { const_get(:DeclaredInCurrentDefinedInParent) }.should raise_error(NameError) - end + it "looks up in parent scope after failed autoload" do + @remove << :DeclaredInCurrentDefinedInParent + module ModuleSpecs::Autoload + ScratchPad.record -> { + DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent + } - DeclaredInCurrentDefinedInParent.should == :declared_in_current_defined_in_parent + class LexicalScope + autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb") + -> { DeclaredInCurrentDefinedInParent }.should_not raise_error(NameError) + # Basically, the autoload constant remains in a "undefined" state + self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil + const_defined?(:DeclaredInCurrentDefinedInParent).should == false + -> { const_get(:DeclaredInCurrentDefinedInParent) }.should raise_error(NameError) end - end - end - - ruby_version_is ""..."3.1" do - it "and fails when finding the undefined autoload constant in the current scope when declared in current and defined in parent" do - @remove << :DeclaredInCurrentDefinedInParent - module ModuleSpecs::Autoload - ScratchPad.record -> { - DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent - } - class LexicalScope - autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb") - -> { DeclaredInCurrentDefinedInParent }.should raise_error(NameError) - # Basically, the autoload constant remains in a "undefined" state - self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil - const_defined?(:DeclaredInCurrentDefinedInParent).should == false - self.should have_constant(:DeclaredInCurrentDefinedInParent) - -> { const_get(:DeclaredInCurrentDefinedInParent) }.should raise_error(NameError) - end - - DeclaredInCurrentDefinedInParent.should == :declared_in_current_defined_in_parent - end + DeclaredInCurrentDefinedInParent.should == :declared_in_current_defined_in_parent end end diff --git a/core/module/module_function_spec.rb b/core/module/module_function_spec.rb index 1c3ec5471b..51f647142e 100644 --- a/core/module/module_function_spec.rb +++ b/core/module/module_function_spec.rb @@ -38,22 +38,11 @@ def test3() end m.respond_to?(:test3).should == false end - ruby_version_is ""..."3.1" do - it "returns self" do - Module.new do - def foo; end - module_function(:foo).should equal(self) - end - end - end - - ruby_version_is "3.1" do - it "returns argument or arguments if given" do - Module.new do - def foo; end - module_function(:foo).should equal(:foo) - module_function(:foo, :foo).should == [:foo, :foo] - end + it "returns argument or arguments if given" do + Module.new do + def foo; end + module_function(:foo).should equal(:foo) + module_function(:foo, :foo).should == [:foo, :foo] end end @@ -216,19 +205,9 @@ def test2() end m.respond_to?(:test2).should == true end - ruby_version_is ""..."3.1" do - it "returns self" do - Module.new do - module_function.should equal(self) - end - end - end - - ruby_version_is "3.1" do - it "returns nil" do - Module.new do - module_function.should equal(nil) - end + it "returns nil" do + Module.new do + module_function.should equal(nil) end end diff --git a/core/module/prepend_spec.rb b/core/module/prepend_spec.rb index b40d12f0de..fc8c75ef41 100644 --- a/core/module/prepend_spec.rb +++ b/core/module/prepend_spec.rb @@ -787,34 +787,17 @@ def foo(ary) # https://bugs.ruby-lang.org/issues/17423 describe "when module already exists in ancestor chain" do - ruby_version_is ""..."3.1" do - it "does not modify the ancestor chain" do - m = Module.new do; end - a = Module.new do; end - b = Class.new do; end + it "modifies the ancestor chain" do + m = Module.new do; end + a = Module.new do; end + b = Class.new do; end - b.include(a) - a.prepend(m) - b.ancestors.take(4).should == [b, m, a, Object] + b.include(a) + a.prepend(m) + b.ancestors.take(4).should == [b, m, a, Object] - b.prepend(m) - b.ancestors.take(4).should == [b, m, a, Object] - end - end - - ruby_version_is "3.1" do - it "modifies the ancestor chain" do - m = Module.new do; end - a = Module.new do; end - b = Class.new do; end - - b.include(a) - a.prepend(m) - b.ancestors.take(4).should == [b, m, a, Object] - - b.prepend(m) - b.ancestors.take(5).should == [m, b, m, a, Object] - end + b.prepend(m) + b.ancestors.take(5).should == [m, b, m, a, Object] end end diff --git a/core/module/private_spec.rb b/core/module/private_spec.rb index ead806637c..9e1a297eea 100644 --- a/core/module/private_spec.rb +++ b/core/module/private_spec.rb @@ -38,25 +38,13 @@ class << obj :module_specs_public_method_on_object_for_kernel_private) end - ruby_version_is ""..."3.1" do - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - private(:foo).should equal(self) - private.should equal(self) - end - end - end - - ruby_version_is "3.1" do - it "returns argument or arguments if given" do - (class << Object.new; self; end).class_eval do - def foo; end - private(:foo).should equal(:foo) - private([:foo, :foo]).should == [:foo, :foo] - private(:foo, :foo).should == [:foo, :foo] - private.should equal(nil) - end + it "returns argument or arguments if given" do + (class << Object.new; self; end).class_eval do + def foo; end + private(:foo).should equal(:foo) + private([:foo, :foo]).should == [:foo, :foo] + private(:foo, :foo).should == [:foo, :foo] + private.should equal(nil) end end diff --git a/core/module/protected_spec.rb b/core/module/protected_spec.rb index 058d49d751..9e37223e18 100644 --- a/core/module/protected_spec.rb +++ b/core/module/protected_spec.rb @@ -39,25 +39,13 @@ class << ModuleSpecs::Parent :module_specs_public_method_on_object_for_kernel_protected) end - ruby_version_is ""..."3.1" do - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - protected(:foo).should equal(self) - protected.should equal(self) - end - end - end - - ruby_version_is "3.1" do - it "returns argument or arguments if given" do - (class << Object.new; self; end).class_eval do - def foo; end - protected(:foo).should equal(:foo) - protected([:foo, :foo]).should == [:foo, :foo] - protected(:foo, :foo).should == [:foo, :foo] - protected.should equal(nil) - end + it "returns argument or arguments if given" do + (class << Object.new; self; end).class_eval do + def foo; end + protected(:foo).should equal(:foo) + protected([:foo, :foo]).should == [:foo, :foo] + protected(:foo, :foo).should == [:foo, :foo] + protected.should equal(nil) end end diff --git a/core/module/public_spec.rb b/core/module/public_spec.rb index e3b183f228..ce31eb5d0e 100644 --- a/core/module/public_spec.rb +++ b/core/module/public_spec.rb @@ -27,25 +27,13 @@ :module_specs_private_method_on_object_for_kernel_public) end - ruby_version_is ""..."3.1" do - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - public(:foo).should equal(self) - public.should equal(self) - end - end - end - - ruby_version_is "3.1" do - it "returns argument or arguments if given" do - (class << Object.new; self; end).class_eval do - def foo; end - public(:foo).should equal(:foo) - public([:foo, :foo]).should == [:foo, :foo] - public(:foo, :foo).should == [:foo, :foo] - public.should equal(nil) - end + it "returns argument or arguments if given" do + (class << Object.new; self; end).class_eval do + def foo; end + public(:foo).should equal(:foo) + public([:foo, :foo]).should == [:foo, :foo] + public(:foo, :foo).should == [:foo, :foo] + public.should equal(nil) end end diff --git a/core/module/refine_spec.rb b/core/module/refine_spec.rb index 8b9ea5eca8..6f5fad8015 100644 --- a/core/module/refine_spec.rb +++ b/core/module/refine_spec.rb @@ -300,67 +300,6 @@ def foo result.should == "foo from IncludeMeLater" end - ruby_version_is ""..."3.1" do - it "looks in prepended modules from the refinement first" do - refined_class = ModuleSpecs.build_refined_class - - refinement = Module.new do - refine refined_class do - include ModuleSpecs::IncludedModule - prepend ModuleSpecs::PrependedModule - - def foo; "foo from refinement"; end - end - end - - result = nil - Module.new do - using refinement - result = refined_class.new.foo - end - - result.should == "foo from prepended module" - end - - it "looks in refinement then" do - refined_class = ModuleSpecs.build_refined_class - - refinement = Module.new do - refine(refined_class) do - include ModuleSpecs::IncludedModule - - def foo; "foo from refinement"; end - end - end - - result = nil - Module.new do - using refinement - result = refined_class.new.foo - end - - result.should == "foo from refinement" - end - - it "looks in included modules from the refinement then" do - refined_class = ModuleSpecs.build_refined_class - - refinement = Module.new do - refine refined_class do - include ModuleSpecs::IncludedModule - end - end - - result = nil - Module.new do - using refinement - result = refined_class.new.foo - end - - result.should == "foo from included module" - end - end - it "looks in the class then" do refined_class = ModuleSpecs.build_refined_class @@ -606,30 +545,6 @@ def to_proc(*args) end context "when super is called in a refinement" do - ruby_version_is ""..."3.1" do - it "looks in the included to refinery module" do - refined_class = ModuleSpecs.build_refined_class - - refinement = Module.new do - refine refined_class do - include ModuleSpecs::IncludedModule - - def foo - super - end - end - end - - result = nil - Module.new do - using refinement - result = refined_class.new.foo - end - - result.should == "foo from included module" - end - end - it "looks in the refined class" do refined_class = ModuleSpecs.build_refined_class @@ -650,59 +565,6 @@ def foo result.should == "foo" end - ruby_version_is ""..."3.1" do - it "looks in the refined class from included module" do - refined_class = ModuleSpecs.build_refined_class(for_super: true) - - a = Module.new do - def foo - [:A] + super - end - end - - refinement = Module.new do - refine refined_class do - include a - end - end - - result = nil - Module.new do - using refinement - - result = refined_class.new.foo - end - - result.should == [:A, :C] - end - - it "looks in the refined ancestors from included module" do - refined_class = ModuleSpecs.build_refined_class(for_super: true) - subclass = Class.new(refined_class) - - a = Module.new do - def foo - [:A] + super - end - end - - refinement = Module.new do - refine refined_class do - include a - end - end - - result = nil - Module.new do - using refinement - - result = subclass.new.foo - end - - result.should == [:A, :C] - end - end - # super in a method of a refinement invokes the method in the refined # class even if there is another refinement which has been activated # in the same context. @@ -763,179 +625,6 @@ def bar }.should raise_error(NoMethodError) end end - - ruby_version_is ""..."3.1" do - it "does't have access to active refinements for C from included module" do - refined_class = ModuleSpecs.build_refined_class - - a = Module.new do - def foo - super + bar - end - end - - refinement = Module.new do - refine refined_class do - include a - - def bar - "bar is not seen from A methods" - end - end - end - - Module.new do - using refinement - -> { - refined_class.new.foo - }.should raise_error(NameError) { |e| e.name.should == :bar } - end - end - - it "does't have access to other active refinements from included module" do - refined_class = ModuleSpecs.build_refined_class - - refinement_integer = Module.new do - refine Integer do - def bar - "bar is not seen from A methods" - end - end - end - - a = Module.new do - def foo - super + 1.bar - end - end - - refinement = Module.new do - refine refined_class do - include a - end - end - - Module.new do - using refinement - using refinement_integer - -> { - refined_class.new.foo - }.should raise_error(NameError) { |e| e.name.should == :bar } - end - end - - # https://bugs.ruby-lang.org/issues/16977 - it "looks in the another active refinement if super called from included modules" do - refined_class = ModuleSpecs.build_refined_class(for_super: true) - - a = Module.new do - def foo - [:A] + super - end - end - - b = Module.new do - def foo - [:B] + super - end - end - - refinement_a = Module.new do - refine refined_class do - include a - end - end - - refinement_b = Module.new do - refine refined_class do - include b - end - end - - result = nil - Module.new do - using refinement_a - using refinement_b - result = refined_class.new.foo - end - - result.should == [:B, :A, :C] - end - - it "looks in the current active refinement from included modules" do - refined_class = ModuleSpecs.build_refined_class(for_super: true) - - a = Module.new do - def foo - [:A] + super - end - end - - b = Module.new do - def foo - [:B] + super - end - end - - refinement = Module.new do - refine refined_class do - def foo - [:LAST] + super - end - end - end - - refinement_a_b = Module.new do - refine refined_class do - include a - include b - end - end - - result = nil - Module.new do - using refinement - using refinement_a_b - result = refined_class.new.foo - end - - result.should == [:B, :A, :LAST, :C] - end - - it "looks in the lexical scope refinements before other active refinements" do - refined_class = ModuleSpecs.build_refined_class(for_super: true) - - refinement_local = Module.new do - refine refined_class do - def foo - [:LOCAL] + super - end - end - end - - a = Module.new do - using refinement_local - - def foo - [:A] + super - end - end - - refinement = Module.new do - refine refined_class do - include a - end - end - - result = nil - Module.new do - using refinement - result = refined_class.new.foo - end - - result.should == [:A, :LOCAL, :C] - end - end end it 'and alias aliases a method within a refinement module, but not outside it' do diff --git a/core/objectspace/define_finalizer_spec.rb b/core/objectspace/define_finalizer_spec.rb index 329f8e1f30..0f4b54c345 100644 --- a/core/objectspace/define_finalizer_spec.rb +++ b/core/objectspace/define_finalizer_spec.rb @@ -193,25 +193,23 @@ def finalizer(zelf) ret[1].should.equal?(p) end - ruby_version_is "3.1" do - describe "when $VERBOSE is not nil" do - it "warns if an exception is raised in finalizer" do - code = <<-RUBY - ObjectSpace.define_finalizer(Object.new) { raise "finalizing" } - RUBY - - ruby_exe(code, args: "2>&1").should include("warning: Exception in finalizer", "finalizing") - end + describe "when $VERBOSE is not nil" do + it "warns if an exception is raised in finalizer" do + code = <<-RUBY + ObjectSpace.define_finalizer(Object.new) { raise "finalizing" } + RUBY + + ruby_exe(code, args: "2>&1").should include("warning: Exception in finalizer", "finalizing") end + end - describe "when $VERBOSE is nil" do - it "does not warn even if an exception is raised in finalizer" do - code = <<-RUBY - ObjectSpace.define_finalizer(Object.new) { raise "finalizing" } - RUBY + describe "when $VERBOSE is nil" do + it "does not warn even if an exception is raised in finalizer" do + code = <<-RUBY + ObjectSpace.define_finalizer(Object.new) { raise "finalizing" } + RUBY - ruby_exe(code, args: "2>&1", options: "-W0").should == "" - end + ruby_exe(code, args: "2>&1", options: "-W0").should == "" end end end diff --git a/core/proc/parameters_spec.rb b/core/proc/parameters_spec.rb index 972596d2ea..7a2723487d 100644 --- a/core/proc/parameters_spec.rb +++ b/core/proc/parameters_spec.rb @@ -64,7 +64,7 @@ end it "regards keyword parameters in lambdas as required" do - eval("lambda {|x:| }").parameters.first.first.should == :keyreq + -> x: { }.parameters.first.first.should == :keyreq end it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do @@ -130,10 +130,8 @@ end end - ruby_version_is '3.1' do - it "adds block arg with name & for anonymous block argument" do - eval('-> & {}.parameters').should == [[:block, :&]] - end + it "adds block arg with name & for anonymous block argument" do + -> & {}.parameters.should == [[:block, :&]] end it "does not add locals as block options with a block and splat" do diff --git a/core/process/_fork_spec.rb b/core/process/_fork_spec.rb index 6f711ad2dd..8e907f54bb 100644 --- a/core/process/_fork_spec.rb +++ b/core/process/_fork_spec.rb @@ -1,24 +1,22 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe "Process._fork" do - it "for #respond_to? returns the same as Process.respond_to?(:fork)" do - Process.respond_to?(:_fork).should == Process.respond_to?(:fork) - end +describe "Process._fork" do + it "for #respond_to? returns the same as Process.respond_to?(:fork)" do + Process.respond_to?(:_fork).should == Process.respond_to?(:fork) + end - guard_not -> { Process.respond_to?(:fork) } do - it "raises a NotImplementedError when called" do - -> { Process._fork }.should raise_error(NotImplementedError) - end + guard_not -> { Process.respond_to?(:fork) } do + it "raises a NotImplementedError when called" do + -> { Process._fork }.should raise_error(NotImplementedError) end + end - guard -> { Process.respond_to?(:fork) } do - it "is called by Process#fork" do - Process.should_receive(:_fork).once.and_return(42) + guard -> { Process.respond_to?(:fork) } do + it "is called by Process#fork" do + Process.should_receive(:_fork).once.and_return(42) - pid = Process.fork {} - pid.should equal(42) - end + pid = Process.fork {} + pid.should equal(42) end end end diff --git a/core/queue/initialize_spec.rb b/core/queue/initialize_spec.rb index c6c1ae63c5..592fbe2487 100644 --- a/core/queue/initialize_spec.rb +++ b/core/queue/initialize_spec.rb @@ -11,9 +11,21 @@ Queue.private_instance_methods.include?(:initialize).should == true end - ruby_version_is '3.1' do - it "adds all elements of the passed Enumerable to self" do - q = Queue.new([1, 2, 3]) + it "adds all elements of the passed Enumerable to self" do + q = Queue.new([1, 2, 3]) + q.size.should == 3 + q.should_not.empty? + q.pop.should == 1 + q.pop.should == 2 + q.pop.should == 3 + q.should.empty? + end + + describe "converts the given argument to an Array using #to_a" do + it "uses #to_a on the provided Enumerable" do + enumerable = MockObject.new('mock-enumerable') + enumerable.should_receive(:to_a).and_return([1, 2, 3]) + q = Queue.new(enumerable) q.size.should == 3 q.should_not.empty? q.pop.should == 1 @@ -22,41 +34,27 @@ q.should.empty? end - describe "converts the given argument to an Array using #to_a" do - it "uses #to_a on the provided Enumerable" do - enumerable = MockObject.new('mock-enumerable') - enumerable.should_receive(:to_a).and_return([1, 2, 3]) - q = Queue.new(enumerable) - q.size.should == 3 - q.should_not.empty? - q.pop.should == 1 - q.pop.should == 2 - q.pop.should == 3 - q.should.empty? - end - - it "raises a TypeError if the given argument can't be converted to an Array" do - -> { Queue.new(42) }.should raise_error(TypeError) - -> { Queue.new(:abc) }.should raise_error(TypeError) - end - - it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to an Array" do - enumerable = MockObject.new('mock-enumerable') - enumerable.should_receive(:to_a).and_raise(NoMethodError) - -> { Queue.new(enumerable) }.should raise_error(NoMethodError) - end + it "raises a TypeError if the given argument can't be converted to an Array" do + -> { Queue.new(42) }.should raise_error(TypeError) + -> { Queue.new(:abc) }.should raise_error(TypeError) end - it "raises TypeError if the provided Enumerable does not respond to #to_a" do + it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to an Array" do enumerable = MockObject.new('mock-enumerable') - -> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject into Array") + enumerable.should_receive(:to_a).and_raise(NoMethodError) + -> { Queue.new(enumerable) }.should raise_error(NoMethodError) end + end - it "raises TypeError if #to_a does not return Array" do - enumerable = MockObject.new('mock-enumerable') - enumerable.should_receive(:to_a).and_return("string") + it "raises TypeError if the provided Enumerable does not respond to #to_a" do + enumerable = MockObject.new('mock-enumerable') + -> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject into Array") + end - -> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject to Array (MockObject#to_a gives String)") - end + it "raises TypeError if #to_a does not return Array" do + enumerable = MockObject.new('mock-enumerable') + enumerable.should_receive(:to_a).and_return("string") + + -> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject to Array (MockObject#to_a gives String)") end end diff --git a/core/range/each_spec.rb b/core/range/each_spec.rb index ecae17c881..f10330d61d 100644 --- a/core/range/each_spec.rb +++ b/core/range/each_spec.rb @@ -40,21 +40,21 @@ it "works with endless ranges" do a = [] - eval("(-2..)").each { |x| break if x > 2; a << x } + (-2..).each { |x| break if x > 2; a << x } a.should == [-2, -1, 0, 1, 2] a = [] - eval("(-2...)").each { |x| break if x > 2; a << x } + (-2...).each { |x| break if x > 2; a << x } a.should == [-2, -1, 0, 1, 2] end it "works with String endless ranges" do a = [] - eval("('A'..)").each { |x| break if x > "D"; a << x } + ('A'..).each { |x| break if x > "D"; a << x } a.should == ["A", "B", "C", "D"] a = [] - eval("('A'...)").each { |x| break if x > "D"; a << x } + ('A'...).each { |x| break if x > "D"; a << x } a.should == ["A", "B", "C", "D"] end @@ -82,27 +82,14 @@ enum.to_a.should == [1, 2, 3] end - ruby_version_is "3.1" do - it "supports Time objects that respond to #succ" do - t = Time.utc(1970) - def t.succ; self + 1 end - t_succ = t.succ - def t_succ.succ; self + 1; end + it "supports Time objects that respond to #succ" do + t = Time.utc(1970) + def t.succ; self + 1 end + t_succ = t.succ + def t_succ.succ; self + 1; end - (t..t_succ).to_a.should == [Time.utc(1970), Time.utc(1970, nil, nil, nil, nil, 1)] - (t...t_succ).to_a.should == [Time.utc(1970)] - end - end - - ruby_version_is ""..."3.1" do - it "raises a TypeError if the first element is a Time object even if it responds to #succ" do - t = Time.utc(1970) - def t.succ; self + 1 end - t_succ = t.succ - def t_succ.succ; self + 1; end - - -> { (t..t_succ).each { |i| i } }.should raise_error(TypeError) - end + (t..t_succ).to_a.should == [Time.utc(1970), Time.utc(1970, nil, nil, nil, nil, 1)] + (t...t_succ).to_a.should == [Time.utc(1970)] end it "passes each Symbol element by using #succ" do diff --git a/core/range/step_spec.rb b/core/range/step_spec.rb index 31cfd400cc..0d0caf746d 100644 --- a/core/range/step_spec.rb +++ b/core/range/step_spec.rb @@ -322,13 +322,11 @@ ScratchPad.recorded.should eql([1.0, 2.8, 4.6]) end - ruby_version_is '3.1' do - it "correctly handles values near the upper limit" do # https://bugs.ruby-lang.org/issues/16612 - (1.0...55.6).step(18.2) { |x| ScratchPad << x } - ScratchPad.recorded.should eql([1.0, 19.2, 37.4, 55.599999999999994]) + it "correctly handles values near the upper limit" do # https://bugs.ruby-lang.org/issues/16612 + (1.0...55.6).step(18.2) { |x| ScratchPad << x } + ScratchPad.recorded.should eql([1.0, 19.2, 37.4, 55.599999999999994]) - (1.0...55.6).step(18.2).size.should == 4 - end + (1.0...55.6).step(18.2).size.should == 4 end it "handles infinite values at either end" do @@ -408,108 +406,108 @@ describe "with an endless range" do describe "and Integer values" do it "yield Integer values incremented by 1 when not passed a step" do - eval("(-2..)").step { |x| break if x > 2; ScratchPad << x } + (-2..).step { |x| break if x > 2; ScratchPad << x } ScratchPad.recorded.should eql([-2, -1, 0, 1, 2]) ScratchPad.record [] - eval("(-2...)").step { |x| break if x > 2; ScratchPad << x } + (-2...).step { |x| break if x > 2; ScratchPad << x } ScratchPad.recorded.should eql([-2, -1, 0, 1, 2]) end it "yields Integer values incremented by an Integer step" do - eval("(-5..)").step(2) { |x| break if x > 3; ScratchPad << x } + (-5..).step(2) { |x| break if x > 3; ScratchPad << x } ScratchPad.recorded.should eql([-5, -3, -1, 1, 3]) ScratchPad.record [] - eval("(-5...)").step(2) { |x| break if x > 3; ScratchPad << x } + (-5...).step(2) { |x| break if x > 3; ScratchPad << x } ScratchPad.recorded.should eql([-5, -3, -1, 1, 3]) end it "yields Float values incremented by a Float step" do - eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x } + (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x } ScratchPad.recorded.should eql([-2.0, -0.5, 1.0]) ScratchPad.record [] - eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x } + (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x } ScratchPad.recorded.should eql([-2.0, -0.5, 1.0]) end end describe "and Float values" do it "yields Float values incremented by 1 and less than end when not passed a step" do - eval("(-2.0..)").step { |x| break if x > 1.5; ScratchPad << x } + (-2.0..).step { |x| break if x > 1.5; ScratchPad << x } ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0]) ScratchPad.record [] - eval("(-2.0...)").step { |x| break if x > 1.5; ScratchPad << x } + (-2.0...).step { |x| break if x > 1.5; ScratchPad << x } ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0]) end it "yields Float values incremented by an Integer step" do - eval("(-5.0..)").step(2) { |x| break if x > 3.5; ScratchPad << x } + (-5.0..).step(2) { |x| break if x > 3.5; ScratchPad << x } ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0]) ScratchPad.record [] - eval("(-5.0...)").step(2) { |x| break if x > 3.5; ScratchPad << x } + (-5.0...).step(2) { |x| break if x > 3.5; ScratchPad << x } ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0]) end it "yields Float values incremented by a Float step" do - eval("(-1.0..)").step(0.5) { |x| break if x > 0.6; ScratchPad << x } + (-1.0..).step(0.5) { |x| break if x > 0.6; ScratchPad << x } ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5]) ScratchPad.record [] - eval("(-1.0...)").step(0.5) { |x| break if x > 0.6; ScratchPad << x } + (-1.0...).step(0.5) { |x| break if x > 0.6; ScratchPad << x } ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5]) end it "handles infinite values at the start" do - eval("(-Float::INFINITY..)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } + (-Float::INFINITY..).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY]) ScratchPad.record [] - eval("(-Float::INFINITY...)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } + (-Float::INFINITY...).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY]) end end describe "and String values" do it "yields String values incremented by #succ and less than or equal to end when not passed a step" do - eval("('A'..)").step { |x| break if x > "D"; ScratchPad << x } + ('A'..).step { |x| break if x > "D"; ScratchPad << x } ScratchPad.recorded.should == ["A", "B", "C", "D"] ScratchPad.record [] - eval("('A'...)").step { |x| break if x > "D"; ScratchPad << x } + ('A'...).step { |x| break if x > "D"; ScratchPad << x } ScratchPad.recorded.should == ["A", "B", "C", "D"] end it "yields String values incremented by #succ called Integer step times" do - eval("('A'..)").step(2) { |x| break if x > "F"; ScratchPad << x } + ('A'..).step(2) { |x| break if x > "F"; ScratchPad << x } ScratchPad.recorded.should == ["A", "C", "E"] ScratchPad.record [] - eval("('A'...)").step(2) { |x| break if x > "F"; ScratchPad << x } + ('A'...).step(2) { |x| break if x > "F"; ScratchPad << x } ScratchPad.recorded.should == ["A", "C", "E"] end it "raises a TypeError when passed a Float step" do - -> { eval("('A'..)").step(2.0) { } }.should raise_error(TypeError) - -> { eval("('A'...)").step(2.0) { } }.should raise_error(TypeError) + -> { ('A'..).step(2.0) { } }.should raise_error(TypeError) + -> { ('A'...).step(2.0) { } }.should raise_error(TypeError) end ruby_version_is "3.4" do it "yields String values adjusted by step" do - eval("('A'..)").step("A") { |x| break if x > "AAA"; ScratchPad << x } + ('A'..).step("A") { |x| break if x > "AAA"; ScratchPad << x } ScratchPad.recorded.should == ["A", "AA", "AAA"] ScratchPad.record [] - eval("('A'...)").step("A") { |x| break if x > "AAA"; ScratchPad << x } + ('A'...).step("A") { |x| break if x > "AAA"; ScratchPad << x } ScratchPad.recorded.should == ["A", "AA", "AAA"] end it "raises a TypeError when passed an incompatible type step" do - -> { eval("('A'..)").step([]) { } }.should raise_error(TypeError) - -> { eval("('A'...)").step([]) { } }.should raise_error(TypeError) + -> { ('A'..).step([]) { } }.should raise_error(TypeError) + -> { ('A'...).step([]) { } }.should raise_error(TypeError) end end end diff --git a/core/refinement/import_methods_spec.rb b/core/refinement/import_methods_spec.rb index 614c54dff8..13c0b1004c 100644 --- a/core/refinement/import_methods_spec.rb +++ b/core/refinement/import_methods_spec.rb @@ -2,137 +2,76 @@ require_relative 'fixtures/classes' describe "Refinement#import_methods" do - ruby_version_is "3.1" do - context "when methods are defined in Ruby code" do - it "imports methods" do - str_utils = Module.new do - def indent(level) - " " * level + self - end - end - - Module.new do - refine String do - import_methods str_utils - "foo".indent(3).should == " foo" - end + context "when methods are defined in Ruby code" do + it "imports methods" do + str_utils = Module.new do + def indent(level) + " " * level + self end end - it "throws an exception when argument is not a module" do - Module.new do - refine String do - -> { - import_methods Integer - }.should raise_error(TypeError, "wrong argument type Class (expected Module)") - end + Module.new do + refine String do + import_methods str_utils + "foo".indent(3).should == " foo" end end + end - it "imports methods from multiple modules" do - str_utils = Module.new do - def indent(level) - " " * level + self - end - end - - str_utils_fancy = Module.new do - def indent_star(level) - "*" * level + self - end - end - - Module.new do - refine String do - import_methods str_utils, str_utils_fancy - "foo".indent(3).should == " foo" - "foo".indent_star(3).should == "***foo" - end + it "throws an exception when argument is not a module" do + Module.new do + refine String do + -> { + import_methods Integer + }.should raise_error(TypeError, "wrong argument type Class (expected Module)") end end + end - it "imports a method defined in the last module if method with same name is defined in multiple modules" do - str_utils = Module.new do - def indent(level) - " " * level + self - end - end - - str_utils_fancy = Module.new do - def indent(level) - "*" * level + self - end - end - - Module.new do - refine String do - import_methods str_utils, str_utils_fancy - "foo".indent(3).should == "***foo" - end + it "imports methods from multiple modules" do + str_utils = Module.new do + def indent(level) + " " * level + self end end - it "still imports methods of modules listed before a module that contains method not defined in Ruby" do - str_utils = Module.new do - def indent(level) - " " * level + self - end - end - - string_refined = Module.new do - refine String do - -> { - import_methods str_utils, Kernel - }.should raise_error(ArgumentError) - end + str_utils_fancy = Module.new do + def indent_star(level) + "*" * level + self end + end - Module.new do - using string_refined + Module.new do + refine String do + import_methods str_utils, str_utils_fancy "foo".indent(3).should == " foo" + "foo".indent_star(3).should == "***foo" end end end - it "warns if a module includes/prepends some other module" do - module1 = Module.new do - end - - module2 = Module.new do - include module1 - end - - Module.new do - refine String do - -> { - import_methods module2 - }.should complain(/warning: # has ancestors, but Refinement#import_methods doesn't import their methods/) + it "imports a method defined in the last module if method with same name is defined in multiple modules" do + str_utils = Module.new do + def indent(level) + " " * level + self end end - Module.new do - refine String do - -> { - import_methods RefinementSpec::ModuleWithAncestors - }.should complain(/warning: RefinementSpec::ModuleWithAncestors has ancestors, but Refinement#import_methods doesn't import their methods/) + str_utils_fancy = Module.new do + def indent(level) + "*" * level + self end end - end - it "doesn't import methods from included/prepended modules" do Module.new do refine String do - suppress_warning { import_methods RefinementSpec::ModuleWithAncestors } + import_methods str_utils, str_utils_fancy + "foo".indent(3).should == "***foo" end - - using self - -> { - "foo".indent(3) - }.should raise_error(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/) end end - it "doesn't import any methods if one of the arguments is not a module" do + it "still imports methods of modules listed before a module that contains method not defined in Ruby" do str_utils = Module.new do def indent(level) " " * level + self @@ -142,126 +81,185 @@ def indent(level) string_refined = Module.new do refine String do -> { - import_methods str_utils, Integer - }.should raise_error(TypeError) + import_methods str_utils, Kernel + }.should raise_error(ArgumentError) end end Module.new do using string_refined + "foo".indent(3).should == " foo" + end + end + end + + it "warns if a module includes/prepends some other module" do + module1 = Module.new do + end + + module2 = Module.new do + include module1 + end + + Module.new do + refine String do -> { - "foo".indent(3) - }.should raise_error(NoMethodError) + import_methods module2 + }.should complain(/warning: # has ancestors, but Refinement#import_methods doesn't import their methods/) end end - it "imports methods from multiple modules so that methods see other's module's methods" do - str_utils = Module.new do - def indent(level) - " " * level + self - end + Module.new do + refine String do + -> { + import_methods RefinementSpec::ModuleWithAncestors + }.should complain(/warning: RefinementSpec::ModuleWithAncestors has ancestors, but Refinement#import_methods doesn't import their methods/) + end + end + end + + it "doesn't import methods from included/prepended modules" do + Module.new do + refine String do + suppress_warning { import_methods RefinementSpec::ModuleWithAncestors } end - str_utils_normal = Module.new do - def indent_normal(level) - self.indent(level) - end + using self + -> { + "foo".indent(3) + }.should raise_error(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/) + end + end + + it "doesn't import any methods if one of the arguments is not a module" do + str_utils = Module.new do + def indent(level) + " " * level + self end + end - Module.new do - refine String do - import_methods str_utils, str_utils_normal - end + string_refined = Module.new do + refine String do + -> { + import_methods str_utils, Integer + }.should raise_error(TypeError) + end + end - using self - "foo".indent_normal(3).should == " foo" + Module.new do + using string_refined + -> { + "foo".indent(3) + }.should raise_error(NoMethodError) + end + end + + it "imports methods from multiple modules so that methods see other's module's methods" do + str_utils = Module.new do + def indent(level) + " " * level + self end end - it "imports methods from module so that methods can see each other" do - str_utils = Module.new do - def indent(level) - " " * level + self - end + str_utils_normal = Module.new do + def indent_normal(level) + self.indent(level) + end + end - def indent_with_dot(level) - self.indent(level) + "." - end + Module.new do + refine String do + import_methods str_utils, str_utils_normal end - Module.new do - refine String do - import_methods str_utils - end + using self + "foo".indent_normal(3).should == " foo" + end + end - using self - "foo".indent_with_dot(3).should == " foo." + it "imports methods from module so that methods can see each other" do + str_utils = Module.new do + def indent(level) + " " * level + self + end + + def indent_with_dot(level) + self.indent(level) + "." end end - it "doesn't import module's class methods" do - str_utils = Module.new do - def self.indent(level) - " " * level + self - end + Module.new do + refine String do + import_methods str_utils end - Module.new do - refine String do - import_methods str_utils - end + using self + "foo".indent_with_dot(3).should == " foo." + end + end - using self - -> { - String.indent(3) - }.should raise_error(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/) + it "doesn't import module's class methods" do + str_utils = Module.new do + def self.indent(level) + " " * level + self end end - it "imports module methods with super" do - class_to_refine = Class.new do - def foo(number) - 2 * number - end + Module.new do + refine String do + import_methods str_utils end - extension = Module.new do - def foo(number) - super * 2 - end + using self + -> { + String.indent(3) + }.should raise_error(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/) + end + end + + it "imports module methods with super" do + class_to_refine = Class.new do + def foo(number) + 2 * number end + end - refinement = Module.new do - refine class_to_refine do - import_methods extension - end + extension = Module.new do + def foo(number) + super * 2 end + end - Module.new do - using refinement - class_to_refine.new.foo(2).should == 8 + refinement = Module.new do + refine class_to_refine do + import_methods extension end end - context "when methods are not defined in Ruby code" do - it "raises ArgumentError" do - Module.new do - refine String do - -> { - import_methods Kernel - }.should raise_error(ArgumentError) - end + Module.new do + using refinement + class_to_refine.new.foo(2).should == 8 + end + end + + context "when methods are not defined in Ruby code" do + it "raises ArgumentError" do + Module.new do + refine String do + -> { + import_methods Kernel + }.should raise_error(ArgumentError) end end + end - it "raises ArgumentError when importing methods from C extension" do - require 'zlib' - Module.new do - refine String do - -> { - import_methods Zlib - }.should raise_error(ArgumentError, /Can't import method which is not defined with Ruby code: Zlib#*/) - end + it "raises ArgumentError when importing methods from C extension" do + require 'zlib' + Module.new do + refine String do + -> { + import_methods Zlib + }.should raise_error(ArgumentError, /Can't import method which is not defined with Ruby code: Zlib#*/) end end end diff --git a/core/refinement/include_spec.rb b/core/refinement/include_spec.rb index 25a53f0ec7..d20ab47e33 100644 --- a/core/refinement/include_spec.rb +++ b/core/refinement/include_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "Refinement#include" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "warns about deprecation" do Module.new do refine String do diff --git a/core/refinement/prepend_spec.rb b/core/refinement/prepend_spec.rb index 27b70d392a..5d66766689 100644 --- a/core/refinement/prepend_spec.rb +++ b/core/refinement/prepend_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "Refinement#prepend" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "warns about deprecation" do Module.new do refine String do diff --git a/core/string/unpack1_spec.rb b/core/string/unpack1_spec.rb index df830916a3..3b3b879f75 100644 --- a/core/string/unpack1_spec.rb +++ b/core/string/unpack1_spec.rb @@ -8,29 +8,27 @@ "A".unpack1("B*").should == "01000001" end - ruby_version_is "3.1" do - it "starts unpacking from the given offset" do - "ZZABCD".unpack1('x3C', offset: 2).should == "ABCD".unpack('x3C')[0] - "ZZZZaG9nZWZ1Z2E=".unpack1("m", offset: 4).should == "hogefuga" - "ZA".unpack1("B*", offset: 1).should == "01000001" - end + it "starts unpacking from the given offset" do + "ZZABCD".unpack1('x3C', offset: 2).should == "ABCD".unpack('x3C')[0] + "ZZZZaG9nZWZ1Z2E=".unpack1("m", offset: 4).should == "hogefuga" + "ZA".unpack1("B*", offset: 1).should == "01000001" + end - it "traits offset as a bytes offset" do - "؈".unpack("CC").should == [216, 136] - "؈".unpack1("C").should == 216 - "؈".unpack1("C", offset: 1).should == 136 - end + it "traits offset as a bytes offset" do + "؈".unpack("CC").should == [216, 136] + "؈".unpack1("C").should == 216 + "؈".unpack1("C", offset: 1).should == 136 + end - it "raises an ArgumentError when the offset is negative" do - -> { "a".unpack1("C", offset: -1) }.should raise_error(ArgumentError, "offset can't be negative") - end + it "raises an ArgumentError when the offset is negative" do + -> { "a".unpack1("C", offset: -1) }.should raise_error(ArgumentError, "offset can't be negative") + end - it "returns nil if the offset is at the end of the string" do - "a".unpack1("C", offset: 1).should == nil - end + it "returns nil if the offset is at the end of the string" do + "a".unpack1("C", offset: 1).should == nil + end - it "raises an ArgumentError when the offset is larger than the string bytesize" do - -> { "a".unpack1("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string") - end + it "raises an ArgumentError when the offset is larger than the string bytesize" do + -> { "a".unpack1("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string") end end diff --git a/core/string/unpack_spec.rb b/core/string/unpack_spec.rb index 52b4af3a95..083484ebe9 100644 --- a/core/string/unpack_spec.rb +++ b/core/string/unpack_spec.rb @@ -9,26 +9,24 @@ -> { "abc".unpack(1) }.should raise_error(TypeError) end - ruby_version_is "3.1" do - it "starts unpacking from the given offset" do - "abc".unpack("CC", offset: 1).should == [98, 99] - end + it "starts unpacking from the given offset" do + "abc".unpack("CC", offset: 1).should == [98, 99] + end - it "traits offset as a bytes offset" do - "؈".unpack("CC").should == [216, 136] - "؈".unpack("CC", offset: 1).should == [136, nil] - end + it "traits offset as a bytes offset" do + "؈".unpack("CC").should == [216, 136] + "؈".unpack("CC", offset: 1).should == [136, nil] + end - it "raises an ArgumentError when the offset is negative" do - -> { "a".unpack("C", offset: -1) }.should raise_error(ArgumentError, "offset can't be negative") - end + it "raises an ArgumentError when the offset is negative" do + -> { "a".unpack("C", offset: -1) }.should raise_error(ArgumentError, "offset can't be negative") + end - it "returns nil if the offset is at the end of the string" do - "a".unpack("C", offset: 1).should == [nil] - end + it "returns nil if the offset is at the end of the string" do + "a".unpack("C", offset: 1).should == [nil] + end - it "raises an ArgumentError when the offset is larget than the string" do - -> { "a".unpack("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string") - end + it "raises an ArgumentError when the offset is larget than the string" do + -> { "a".unpack("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string") end end diff --git a/core/struct/initialize_spec.rb b/core/struct/initialize_spec.rb index a5ebe9551c..1861bcafb0 100644 --- a/core/struct/initialize_spec.rb +++ b/core/struct/initialize_spec.rb @@ -41,7 +41,7 @@ StructClasses::SubclassX.new(:y).new.key.should == :value end - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "warns about passing only keyword arguments" do -> { StructClasses::Ruby.new(version: "3.1", platform: "OS") diff --git a/core/struct/keyword_init_spec.rb b/core/struct/keyword_init_spec.rb index 8de4c14351..178996da10 100644 --- a/core/struct/keyword_init_spec.rb +++ b/core/struct/keyword_init_spec.rb @@ -1,40 +1,38 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - # See https://bugs.ruby-lang.org/issues/18008 - describe "StructClass#keyword_init?" do - it "returns true for a struct that accepts keyword arguments to initialize" do - struct = Struct.new(:arg, keyword_init: true) - struct.keyword_init?.should be_true - end - - it "returns false for a struct that does not accept keyword arguments to initialize" do - struct = Struct.new(:arg, keyword_init: false) - struct.keyword_init?.should be_false - end - - it "returns nil for a struct that did not explicitly specify keyword_init" do - struct = Struct.new(:arg) - struct.keyword_init?.should be_nil - end - - it "returns nil for a struct that does specify keyword_init to be nil" do - struct = Struct.new(:arg, keyword_init: nil) - struct.keyword_init?.should be_nil - end - - it "returns true for any truthy value, not just for true" do - struct = Struct.new(:arg, keyword_init: 1) - struct.keyword_init?.should be_true - - struct = Struct.new(:arg, keyword_init: "") - struct.keyword_init?.should be_true - - struct = Struct.new(:arg, keyword_init: []) - struct.keyword_init?.should be_true - - struct = Struct.new(:arg, keyword_init: {}) - struct.keyword_init?.should be_true - end +# See https://bugs.ruby-lang.org/issues/18008 +describe "StructClass#keyword_init?" do + it "returns true for a struct that accepts keyword arguments to initialize" do + struct = Struct.new(:arg, keyword_init: true) + struct.keyword_init?.should be_true + end + + it "returns false for a struct that does not accept keyword arguments to initialize" do + struct = Struct.new(:arg, keyword_init: false) + struct.keyword_init?.should be_false + end + + it "returns nil for a struct that did not explicitly specify keyword_init" do + struct = Struct.new(:arg) + struct.keyword_init?.should be_nil + end + + it "returns nil for a struct that does specify keyword_init to be nil" do + struct = Struct.new(:arg, keyword_init: nil) + struct.keyword_init?.should be_nil + end + + it "returns true for any truthy value, not just for true" do + struct = Struct.new(:arg, keyword_init: 1) + struct.keyword_init?.should be_true + + struct = Struct.new(:arg, keyword_init: "") + struct.keyword_init?.should be_true + + struct = Struct.new(:arg, keyword_init: []) + struct.keyword_init?.should be_true + + struct = Struct.new(:arg, keyword_init: {}) + struct.keyword_init?.should be_true end end diff --git a/core/struct/new_spec.rb b/core/struct/new_spec.rb index a94eb852e1..ab2fac44d2 100644 --- a/core/struct/new_spec.rb +++ b/core/struct/new_spec.rb @@ -158,19 +158,6 @@ def platform -> { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.1' do - it "passes a hash as a normal argument" do - type = Struct.new(:args) - - obj = suppress_warning {type.new(keyword: :arg)} - obj2 = type.new(*[{keyword: :arg}]) - - obj.should == obj2 - obj.args.should == {keyword: :arg} - obj2.args.should == {keyword: :arg} - end - end - ruby_version_is '3.2' do it "accepts keyword arguments to initialize" do type = Struct.new(:args) diff --git a/core/thread/backtrace/limit_spec.rb b/core/thread/backtrace/limit_spec.rb index 26a87a806c..b55ca67ea0 100644 --- a/core/thread/backtrace/limit_spec.rb +++ b/core/thread/backtrace/limit_spec.rb @@ -1,15 +1,13 @@ require_relative '../../../spec_helper' -ruby_version_is "3.1" do - describe "Thread::Backtrace.limit" do - it "returns maximum backtrace length set by --backtrace-limit command-line option" do - out = ruby_exe("print Thread::Backtrace.limit", options: "--backtrace-limit=2") - out.should == "2" - end +describe "Thread::Backtrace.limit" do + it "returns maximum backtrace length set by --backtrace-limit command-line option" do + out = ruby_exe("print Thread::Backtrace.limit", options: "--backtrace-limit=2") + out.should == "2" + end - it "returns -1 when --backtrace-limit command-line option is not set" do - out = ruby_exe("print Thread::Backtrace.limit") - out.should == "-1" - end + it "returns -1 when --backtrace-limit command-line option is not set" do + out = ruby_exe("print Thread::Backtrace.limit") + out.should == "-1" end end diff --git a/core/thread/backtrace/location/absolute_path_spec.rb b/core/thread/backtrace/location/absolute_path_spec.rb index 6e381e4868..68a69049d9 100644 --- a/core/thread/backtrace/location/absolute_path_spec.rb +++ b/core/thread/backtrace/location/absolute_path_spec.rb @@ -27,20 +27,11 @@ end context "when used in eval with a given filename" do - code = "caller_locations(0)[0].absolute_path" + it "returns nil with absolute_path" do + code = "caller_locations(0)[0].absolute_path" - ruby_version_is ""..."3.1" do - it "returns filename with absolute_path" do - eval(code, nil, "foo.rb").should == "foo.rb" - eval(code, nil, "foo/bar.rb").should == "foo/bar.rb" - end - end - - ruby_version_is "3.1" do - it "returns nil with absolute_path" do - eval(code, nil, "foo.rb").should == nil - eval(code, nil, "foo/bar.rb").should == nil - end + eval(code, nil, "foo.rb").should == nil + eval(code, nil, "foo/bar.rb").should == nil end end diff --git a/core/thread/native_thread_id_spec.rb b/core/thread/native_thread_id_spec.rb index 17a08c8a15..374cc59279 100644 --- a/core/thread/native_thread_id_spec.rb +++ b/core/thread/native_thread_id_spec.rb @@ -1,37 +1,35 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - platform_is :linux, :darwin, :windows, :freebsd do - describe "Thread#native_thread_id" do - it "returns an integer when the thread is alive" do - Thread.current.native_thread_id.should be_kind_of(Integer) - end +platform_is :linux, :darwin, :windows, :freebsd do + describe "Thread#native_thread_id" do + it "returns an integer when the thread is alive" do + Thread.current.native_thread_id.should be_kind_of(Integer) + end - it "returns nil when the thread is not running" do - t = Thread.new {} - t.join - t.native_thread_id.should == nil - end + it "returns nil when the thread is not running" do + t = Thread.new {} + t.join + t.native_thread_id.should == nil + end - it "each thread has different native thread id" do - t = Thread.new { sleep } - Thread.pass until t.stop? - main_thread_id = Thread.current.native_thread_id - t_thread_id = t.native_thread_id + it "each thread has different native thread id" do + t = Thread.new { sleep } + Thread.pass until t.stop? + 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 + 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 - main_thread_id.should_not == t_thread_id + main_thread_id.should_not == t_thread_id - t.run - t.join - t.native_thread_id.should == nil - end + t.run + t.join + t.native_thread_id.should == nil end end end diff --git a/core/time/at_spec.rb b/core/time/at_spec.rb index 85bb6d7ebf..c1549f496f 100644 --- a/core/time/at_spec.rb +++ b/core/time/at_spec.rb @@ -288,39 +288,19 @@ end it "raises ArgumentError if hours greater than 23" do # TODO - ruby_version_is ""..."3.1" do - -> { Time.at(@epoch_time, in: "+24:00") }.should raise_error(ArgumentError, 'utc_offset out of range') - -> { Time.at(@epoch_time, in: "+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.at(@epoch_time, in: "+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.at(@epoch_time, in: "+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.at(@epoch_time, in: "+99:00") }.should raise_error(ArgumentError, 'utc_offset out of range') - -> { Time.at(@epoch_time, in: "+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.at(@epoch_time, in: "+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.at(@epoch_time, in: "+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - - -> { Time.at(@epoch_time, in: "+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.at(@epoch_time, in: "+9900") }.should raise_error(ArgumentError, "utc_offset out of range") - end + -> { Time.at(@epoch_time, in: "+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.at(@epoch_time, in: "+9900") }.should raise_error(ArgumentError, "utc_offset out of range") end it "raises ArgumentError if minutes greater than 59" do # TODO - ruby_version_is ""..."3.1" do - -> { Time.at(@epoch_time, in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.at(@epoch_time, in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.at(@epoch_time, in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') + -> { Time.at(@epoch_time, in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - -> { Time.at(@epoch_time, in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.at(@epoch_time, in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.at(@epoch_time, in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') - -> { Time.at(@epoch_time, in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - - -> { Time.at(@epoch_time, in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') - -> { Time.at(@epoch_time, in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') - end + -> { Time.at(@epoch_time, in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') + -> { Time.at(@epoch_time, in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') end ruby_bug '#20797', ''...'3.4' do diff --git a/core/time/getlocal_spec.rb b/core/time/getlocal_spec.rb index ff3e3d8dd1..d226e5f744 100644 --- a/core/time/getlocal_spec.rb +++ b/core/time/getlocal_spec.rb @@ -110,39 +110,19 @@ end it "raises ArgumentError if String argument and hours greater than 23" do - ruby_version_is ""..."3.1" do - -> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - - -> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, "utc_offset out of range") - end + -> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, "utc_offset out of range") end it "raises ArgumentError if String argument and minutes greater than 59" do - ruby_version_is ""..."3.1" do - -> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') + -> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - -> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') - -> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - - -> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') - -> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') - end + -> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') + -> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') end ruby_bug '#20797', ''...'3.4' do diff --git a/core/time/localtime_spec.rb b/core/time/localtime_spec.rb index 5badba9fb2..d98680ca26 100644 --- a/core/time/localtime_spec.rb +++ b/core/time/localtime_spec.rb @@ -106,39 +106,19 @@ end it "raises ArgumentError if String argument and hours greater than 23" do - ruby_version_is ""..."3.1" do - -> { Time.now.localtime("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.localtime("+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.now.localtime("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now.localtime("+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.localtime("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.localtime("+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.now.localtime("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.localtime("+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - - -> { Time.now.localtime("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now.localtime("+9900") }.should raise_error(ArgumentError, "utc_offset out of range") - end + -> { Time.now.localtime("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now.localtime("+9900") }.should raise_error(ArgumentError, "utc_offset out of range") end it "raises ArgumentError if String argument and minutes greater than 59" do - ruby_version_is ""..."3.1" do - -> { Time.now.localtime("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.now.localtime("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') + -> { Time.now.localtime("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') + -> { Time.now.localtime("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - -> { Time.now.localtime("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - -> { Time.now.localtime("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset') - end - - ruby_version_is "3.1" do - -> { Time.now.localtime("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') - -> { Time.now.localtime("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - - -> { Time.now.localtime("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') - -> { Time.now.localtime("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') - end + -> { Time.now.localtime("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') + -> { Time.now.localtime("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') end ruby_bug '#20797', ''...'3.4' do diff --git a/core/time/new_spec.rb b/core/time/new_spec.rb index 1a743b485e..95a456c4db 100644 --- a/core/time/new_spec.rb +++ b/core/time/new_spec.rb @@ -58,30 +58,28 @@ Time.new(2000, 1, 1, 0, 0, 0, "-04:10:43").utc_offset.should == -15043 end - ruby_bug '#13669', ''...'3.1' do - it "returns a Time with a UTC offset specified as +HH" do - Time.new(2000, 1, 1, 0, 0, 0, "+05").utc_offset.should == 3600 * 5 - end + it "returns a Time with a UTC offset specified as +HH" do + Time.new(2000, 1, 1, 0, 0, 0, "+05").utc_offset.should == 3600 * 5 + end - it "returns a Time with a UTC offset specified as -HH" do - Time.new(2000, 1, 1, 0, 0, 0, "-05").utc_offset.should == -3600 * 5 - end + it "returns a Time with a UTC offset specified as -HH" do + Time.new(2000, 1, 1, 0, 0, 0, "-05").utc_offset.should == -3600 * 5 + end - it "returns a Time with a UTC offset specified as +HHMM" do - Time.new(2000, 1, 1, 0, 0, 0, "+0530").utc_offset.should == 19800 - end + it "returns a Time with a UTC offset specified as +HHMM" do + Time.new(2000, 1, 1, 0, 0, 0, "+0530").utc_offset.should == 19800 + end - it "returns a Time with a UTC offset specified as -HHMM" do - Time.new(2000, 1, 1, 0, 0, 0, "-0530").utc_offset.should == -19800 - end + it "returns a Time with a UTC offset specified as -HHMM" do + Time.new(2000, 1, 1, 0, 0, 0, "-0530").utc_offset.should == -19800 + end - it "returns a Time with a UTC offset specified as +HHMMSS" do - Time.new(2000, 1, 1, 0, 0, 0, "+053037").utc_offset.should == 19837 - end + it "returns a Time with a UTC offset specified as +HHMMSS" do + Time.new(2000, 1, 1, 0, 0, 0, "+053037").utc_offset.should == 19837 + end - it "returns a Time with a UTC offset specified as -HHMMSS" do - Time.new(2000, 1, 1, 0, 0, 0, "-053037").utc_offset.should == -19837 - end + it "returns a Time with a UTC offset specified as -HHMMSS" do + Time.new(2000, 1, 1, 0, 0, 0, "-053037").utc_offset.should == -19837 end describe "with an argument that responds to #to_str" do @@ -129,18 +127,9 @@ end end - ruby_version_is ""..."3.1" do - it "raises ArgumentError if the string argument is J" do - message = '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset' - -> { Time.new(2000, 1, 1, 0, 0, 0, "J") }.should raise_error(ArgumentError, message) - end - end - - ruby_version_is "3.1" do - it "raises ArgumentError if the string argument is J" do - message = '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: J' - -> { Time.new(2000, 1, 1, 0, 0, 0, "J") }.should raise_error(ArgumentError, message) - end + it "raises ArgumentError if the string argument is J" do + message = '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: J' + -> { Time.new(2000, 1, 1, 0, 0, 0, "J") }.should raise_error(ArgumentError, message) end it "returns a local Time if the argument is nil" do @@ -403,79 +392,77 @@ def zone.local_to_utc(t) end end - ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/17485 - describe ":in keyword argument" do - it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do - time = Time.new(2000, 1, 1, 12, 0, 0, in: "+05:00") + describe ":in keyword argument" do + it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do + time = Time.new(2000, 1, 1, 12, 0, 0, in: "+05:00") - time.utc_offset.should == 5*60*60 - time.zone.should == nil + time.utc_offset.should == 5*60*60 + time.zone.should == nil - time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00") + time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00") - time.utc_offset.should == -9*60*60 - time.zone.should == nil + time.utc_offset.should == -9*60*60 + time.zone.should == nil - time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00:01") + time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00:01") - time.utc_offset.should == -(9*60*60 + 1) - time.zone.should == nil - end + time.utc_offset.should == -(9*60*60 + 1) + time.zone.should == nil + end - it "could be UTC offset as a number of seconds" do - time = Time.new(2000, 1, 1, 12, 0, 0, in: 5*60*60) + it "could be UTC offset as a number of seconds" do + time = Time.new(2000, 1, 1, 12, 0, 0, in: 5*60*60) - time.utc_offset.should == 5*60*60 - time.zone.should == nil + time.utc_offset.should == 5*60*60 + time.zone.should == nil - time = Time.new(2000, 1, 1, 12, 0, 0, in: -9*60*60) + time = Time.new(2000, 1, 1, 12, 0, 0, in: -9*60*60) - time.utc_offset.should == -9*60*60 - time.zone.should == nil - end + time.utc_offset.should == -9*60*60 + time.zone.should == nil + end - it "returns a Time with UTC offset specified as a single letter military timezone" do - Time.new(2000, 1, 1, 0, 0, 0, in: "W").utc_offset.should == 3600 * -10 - end + it "returns a Time with UTC offset specified as a single letter military timezone" do + Time.new(2000, 1, 1, 0, 0, 0, in: "W").utc_offset.should == 3600 * -10 + end - it "could be a timezone object" do - zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") - time = Time.new(2000, 1, 1, 12, 0, 0, in: zone) + it "could be a timezone object" do + zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") + time = Time.new(2000, 1, 1, 12, 0, 0, in: zone) - time.utc_offset.should == 5*3600+30*60 - time.zone.should == zone + time.utc_offset.should == 5*3600+30*60 + time.zone.should == zone - zone = TimeSpecs::TimezoneWithName.new(name: "PST") - time = Time.new(2000, 1, 1, 12, 0, 0, in: zone) + zone = TimeSpecs::TimezoneWithName.new(name: "PST") + time = Time.new(2000, 1, 1, 12, 0, 0, in: zone) - time.utc_offset.should == -9*60*60 - time.zone.should == zone - end + time.utc_offset.should == -9*60*60 + time.zone.should == zone + end - it "allows omitting minor arguments" do - Time.new(2000, 1, 1, 12, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 1, "+05:00") - Time.new(2000, 1, 1, 12, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 0, "+05:00") - Time.new(2000, 1, 1, 12, in: "+05:00").should == Time.new(2000, 1, 1, 12, 0, 0, "+05:00") - Time.new(2000, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") - Time.new(2000, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") - Time.new(2000, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") - Time.new(in: "+05:00").should be_close(Time.now.getlocal("+05:00"), TIME_TOLERANCE) - end + it "allows omitting minor arguments" do + Time.new(2000, 1, 1, 12, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 1, "+05:00") + Time.new(2000, 1, 1, 12, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 0, "+05:00") + Time.new(2000, 1, 1, 12, in: "+05:00").should == Time.new(2000, 1, 1, 12, 0, 0, "+05:00") + Time.new(2000, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") + Time.new(2000, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") + Time.new(2000, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00") + Time.new(in: "+05:00").should be_close(Time.now.getlocal("+05:00"), TIME_TOLERANCE) + end - it "converts to a provided timezone if all the positional arguments are omitted" do - Time.new(in: "+05:00").utc_offset.should == 5*3600 - end + it "converts to a provided timezone if all the positional arguments are omitted" do + Time.new(in: "+05:00").utc_offset.should == 5*3600 + end - it "raises ArgumentError if format is invalid" do - -> { Time.new(2000, 1, 1, 12, 0, 0, in: "+09:99") }.should raise_error(ArgumentError) - -> { Time.new(2000, 1, 1, 12, 0, 0, in: "ABC") }.should raise_error(ArgumentError) - end + it "raises ArgumentError if format is invalid" do + -> { Time.new(2000, 1, 1, 12, 0, 0, in: "+09:99") }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 12, 0, 0, in: "ABC") }.should raise_error(ArgumentError) + end - it "raises ArgumentError if two offset arguments are given" do - -> { - Time.new(2000, 1, 1, 12, 0, 0, "+05:00", in: "+05:00") - }.should raise_error(ArgumentError, "timezone argument given as positional and keyword arguments") - end + it "raises ArgumentError if two offset arguments are given" do + -> { + Time.new(2000, 1, 1, 12, 0, 0, "+05:00", in: "+05:00") + }.should raise_error(ArgumentError, "timezone argument given as positional and keyword arguments") end end diff --git a/core/time/now_spec.rb b/core/time/now_spec.rb index 7c2425411a..b09f56293f 100644 --- a/core/time/now_spec.rb +++ b/core/time/now_spec.rb @@ -4,84 +4,82 @@ describe "Time.now" do it_behaves_like :time_now, :now - ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/17485 - describe ":in keyword argument" do - it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do - time = Time.now(in: "+05:00") + describe ":in keyword argument" do + it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do + time = Time.now(in: "+05:00") - time.utc_offset.should == 5*60*60 - time.zone.should == nil + time.utc_offset.should == 5*60*60 + time.zone.should == nil - time = Time.now(in: "-09:00") + time = Time.now(in: "-09:00") - time.utc_offset.should == -9*60*60 - time.zone.should == nil + time.utc_offset.should == -9*60*60 + time.zone.should == nil - time = Time.now(in: "-09:00:01") + time = Time.now(in: "-09:00:01") - time.utc_offset.should == -(9*60*60 + 1) - time.zone.should == nil - end + time.utc_offset.should == -(9*60*60 + 1) + time.zone.should == nil + end - it "could be UTC offset as a number of seconds" do - time = Time.now(in: 5*60*60) + it "could be UTC offset as a number of seconds" do + time = Time.now(in: 5*60*60) - time.utc_offset.should == 5*60*60 - time.zone.should == nil + time.utc_offset.should == 5*60*60 + time.zone.should == nil - time = Time.now(in: -9*60*60) + time = Time.now(in: -9*60*60) - time.utc_offset.should == -9*60*60 - time.zone.should == nil - end + time.utc_offset.should == -9*60*60 + time.zone.should == nil + end - it "returns a Time with UTC offset specified as a single letter military timezone" do - Time.now(in: "W").utc_offset.should == 3600 * -10 - end + it "returns a Time with UTC offset specified as a single letter military timezone" do + Time.now(in: "W").utc_offset.should == 3600 * -10 + end - it "could be a timezone object" do - zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") - time = Time.now(in: zone) + it "could be a timezone object" do + zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") + time = Time.now(in: zone) - time.utc_offset.should == 5*3600+30*60 - time.zone.should == zone + time.utc_offset.should == 5*3600+30*60 + time.zone.should == zone - zone = TimeSpecs::TimezoneWithName.new(name: "PST") - time = Time.now(in: zone) + zone = TimeSpecs::TimezoneWithName.new(name: "PST") + time = Time.now(in: zone) - time.utc_offset.should == -9*60*60 - time.zone.should == zone - end + time.utc_offset.should == -9*60*60 + time.zone.should == zone + end - it "raises ArgumentError if format is invalid" do - -> { Time.now(in: "+09:99") }.should raise_error(ArgumentError) - -> { Time.now(in: "ABC") }.should raise_error(ArgumentError) - end + it "raises ArgumentError if format is invalid" do + -> { Time.now(in: "+09:99") }.should raise_error(ArgumentError) + -> { Time.now(in: "ABC") }.should raise_error(ArgumentError) + end - it "raises ArgumentError if String argument and hours greater than 23" do - -> { Time.now(in: "+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now(in: "+2400") }.should raise_error(ArgumentError, "utc_offset out of range") + it "raises ArgumentError if String argument and hours greater than 23" do + -> { Time.now(in: "+24:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now(in: "+2400") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now(in: "+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") - -> { Time.now(in: "+9900") }.should raise_error(ArgumentError, "utc_offset out of range") - end + -> { Time.now(in: "+99:00") }.should raise_error(ArgumentError, "utc_offset out of range") + -> { Time.now(in: "+9900") }.should raise_error(ArgumentError, "utc_offset out of range") + end - it "raises ArgumentError if String argument and minutes greater than 59" do - -> { Time.now(in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') - -> { Time.now(in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') + it "raises ArgumentError if String argument and minutes greater than 59" do + -> { Time.now(in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60') + -> { Time.now(in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060') - -> { Time.now(in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') - -> { Time.now(in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') - end + -> { Time.now(in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99') + -> { Time.now(in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099') + end - ruby_bug '#20797', ''...'3.4' do - it "raises ArgumentError if String argument and seconds greater than 59" do - -> { Time.now(in: "+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60') - -> { Time.now(in: "+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060') + ruby_bug '#20797', ''...'3.4' do + it "raises ArgumentError if String argument and seconds greater than 59" do + -> { Time.now(in: "+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60') + -> { Time.now(in: "+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060') - -> { Time.now(in: "+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99') - -> { Time.now(in: "+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099') - end + -> { Time.now(in: "+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99') + -> { Time.now(in: "+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099') end end end diff --git a/core/time/strftime_spec.rb b/core/time/strftime_spec.rb index 4cb300c916..fd233f3577 100644 --- a/core/time/strftime_spec.rb +++ b/core/time/strftime_spec.rb @@ -50,44 +50,42 @@ time.strftime("%::z").should == "+01:01:05" end - ruby_version_is "3.1" do - it "supports RFC 3339 UTC for unknown offset local time, -0000, as %-z" do - time = Time.gm(2022) - - time.strftime("%z").should == "+0000" - time.strftime("%-z").should == "-0000" - time.strftime("%-:z").should == "-00:00" - time.strftime("%-::z").should == "-00:00:00" - end + it "supports RFC 3339 UTC for unknown offset local time, -0000, as %-z" do + time = Time.gm(2022) - it "applies '-' flag to UTC time" do - time = Time.utc(2022) - time.strftime("%-z").should == "-0000" + time.strftime("%z").should == "+0000" + time.strftime("%-z").should == "-0000" + time.strftime("%-:z").should == "-00:00" + time.strftime("%-::z").should == "-00:00:00" + end - time = Time.gm(2022) - time.strftime("%-z").should == "-0000" + it "applies '-' flag to UTC time" do + time = Time.utc(2022) + time.strftime("%-z").should == "-0000" - time = Time.new(2022, 1, 1, 0, 0, 0, "Z") - time.strftime("%-z").should == "-0000" + time = Time.gm(2022) + time.strftime("%-z").should == "-0000" - time = Time.new(2022, 1, 1, 0, 0, 0, "-00:00") - time.strftime("%-z").should == "-0000" + time = Time.new(2022, 1, 1, 0, 0, 0, "Z") + time.strftime("%-z").should == "-0000" - time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00").utc - time.strftime("%-z").should == "-0000" - end + time = Time.new(2022, 1, 1, 0, 0, 0, "-00:00") + time.strftime("%-z").should == "-0000" - it "ignores '-' flag for non-UTC time" do - time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00") - time.strftime("%-z").should == "+0300" - end + time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00").utc + time.strftime("%-z").should == "-0000" + end - it "works correctly with width, _ and 0 flags, and :" do - Time.now.utc.strftime("%-_10z").should == " -000" - Time.now.utc.strftime("%-10z").should == "-000000000" - Time.now.utc.strftime("%-010:z").should == "-000000:00" - Time.now.utc.strftime("%-_10:z").should == " -0:00" - Time.now.utc.strftime("%-_10::z").should == " -0:00:00" - end + it "ignores '-' flag for non-UTC time" do + time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00") + time.strftime("%-z").should == "+0300" + end + + it "works correctly with width, _ and 0 flags, and :" do + Time.now.utc.strftime("%-_10z").should == " -000" + Time.now.utc.strftime("%-10z").should == "-000000000" + Time.now.utc.strftime("%-010:z").should == "-000000:00" + Time.now.utc.strftime("%-_10:z").should == " -0:00" + Time.now.utc.strftime("%-_10::z").should == " -0:00:00" end end diff --git a/core/time/utc_spec.rb b/core/time/utc_spec.rb index 566509fd33..3d36e13ccf 100644 --- a/core/time/utc_spec.rb +++ b/core/time/utc_spec.rb @@ -22,10 +22,8 @@ Time.now.localtime("UTC").utc?.should == true Time.at(Time.now, in: 'UTC').utc?.should == true - ruby_version_is "3.1" do - Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").utc?.should == true - Time.now(in: "UTC").utc?.should == true - end + Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").utc?.should == true + Time.now(in: "UTC").utc?.should == true end it "does treat time with Z offset as UTC" do @@ -33,18 +31,14 @@ Time.now.localtime("Z").utc?.should == true Time.at(Time.now, in: 'Z').utc?.should == true - ruby_version_is "3.1" do - Time.new(2022, 1, 1, 0, 0, 0, in: "Z").utc?.should == true - Time.now(in: "Z").utc?.should == true - end + Time.new(2022, 1, 1, 0, 0, 0, in: "Z").utc?.should == true + Time.now(in: "Z").utc?.should == true end - ruby_version_is "3.1" do - it "does treat time with -00:00 offset as UTC" do - Time.new(2022, 1, 1, 0, 0, 0, "-00:00").utc?.should == true - Time.now.localtime("-00:00").utc?.should == true - Time.at(Time.now, in: '-00:00').utc?.should == true - end + it "does treat time with -00:00 offset as UTC" do + Time.new(2022, 1, 1, 0, 0, 0, "-00:00").utc?.should == true + Time.now.localtime("-00:00").utc?.should == true + Time.at(Time.now, in: '-00:00').utc?.should == true end it "does not treat time with +00:00 offset as UTC" do diff --git a/core/time/zone_spec.rb b/core/time/zone_spec.rb index 63c92602d1..9a15bd569b 100644 --- a/core/time/zone_spec.rb +++ b/core/time/zone_spec.rb @@ -69,22 +69,18 @@ Time.at(Time.now, in: 'UTC').zone.should == "UTC" Time.at(Time.now, in: 'Z').zone.should == "UTC" - ruby_version_is "3.1" do - Time.new(2022, 1, 1, 0, 0, 0, "-00:00").zone.should == "UTC" - Time.now.localtime("-00:00").zone.should == "UTC" - Time.at(Time.now, in: '-00:00').zone.should == "UTC" - end + Time.new(2022, 1, 1, 0, 0, 0, "-00:00").zone.should == "UTC" + Time.now.localtime("-00:00").zone.should == "UTC" + Time.at(Time.now, in: '-00:00').zone.should == "UTC" - ruby_version_is "3.1" do - Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").zone.should == "UTC" - Time.new(2022, 1, 1, 0, 0, 0, in: "Z").zone.should == "UTC" + Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").zone.should == "UTC" + Time.new(2022, 1, 1, 0, 0, 0, in: "Z").zone.should == "UTC" - Time.now(in: 'UTC').zone.should == "UTC" - Time.now(in: 'Z').zone.should == "UTC" + Time.now(in: 'UTC').zone.should == "UTC" + Time.now(in: 'Z').zone.should == "UTC" - Time.at(Time.now, in: 'UTC').zone.should == "UTC" - Time.at(Time.now, in: 'Z').zone.should == "UTC" - end + Time.at(Time.now, in: 'UTC').zone.should == "UTC" + Time.at(Time.now, in: 'Z').zone.should == "UTC" end platform_is_not :aix, :windows do diff --git a/core/tracepoint/allow_reentry_spec.rb b/core/tracepoint/allow_reentry_spec.rb index 6bff1bed76..75e9e859a9 100644 --- a/core/tracepoint/allow_reentry_spec.rb +++ b/core/tracepoint/allow_reentry_spec.rb @@ -1,32 +1,30 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "3.1" do - describe 'TracePoint.allow_reentry' do - it 'allows the reentrance in a given block' do - event_lines = [] - l1 = l2 = l3 = l4 = nil - TracePoint.new(:line) do |tp| - next unless TracePointSpec.target_thread? +describe 'TracePoint.allow_reentry' do + it 'allows the reentrance in a given block' do + event_lines = [] + l1 = l2 = l3 = l4 = nil + TracePoint.new(:line) do |tp| + next unless TracePointSpec.target_thread? - event_lines << tp.lineno - next if (__LINE__ + 2 .. __LINE__ + 4).cover?(tp.lineno) - TracePoint.allow_reentry do - a = 1; l3 = __LINE__ - b = 2; l4 = __LINE__ - end - end.enable do - c = 3; l1 = __LINE__ - d = 4; l2 = __LINE__ + event_lines << tp.lineno + next if (__LINE__ + 2 .. __LINE__ + 4).cover?(tp.lineno) + TracePoint.allow_reentry do + a = 1; l3 = __LINE__ + b = 2; l4 = __LINE__ end - - event_lines.should == [l1, l3, l4, l2, l3, l4] + end.enable do + c = 3; l1 = __LINE__ + d = 4; l2 = __LINE__ end - it 'raises RuntimeError when not called inside a TracePoint' do - -> { - TracePoint.allow_reentry{} - }.should raise_error(RuntimeError) - end + event_lines.should == [l1, l3, l4, l2, l3, l4] + end + + it 'raises RuntimeError when not called inside a TracePoint' do + -> { + TracePoint.allow_reentry{} + }.should raise_error(RuntimeError) end end diff --git a/core/unboundmethod/private_spec.rb b/core/unboundmethod/private_spec.rb index 8ea50bb5d4..9a890db6fd 100644 --- a/core/unboundmethod/private_spec.rb +++ b/core/unboundmethod/private_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "UnboundMethod#private?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns false when the method is public" do obj = UnboundMethodSpecs::Methods.new obj.method(:my_public_method).unbind.private?.should == false diff --git a/core/unboundmethod/protected_spec.rb b/core/unboundmethod/protected_spec.rb index 0c215d8638..b79e2da63b 100644 --- a/core/unboundmethod/protected_spec.rb +++ b/core/unboundmethod/protected_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "UnboundMethod#protected?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns false when the method is public" do obj = UnboundMethodSpecs::Methods.new obj.method(:my_public_method).unbind.protected?.should == false diff --git a/core/unboundmethod/public_spec.rb b/core/unboundmethod/public_spec.rb index 552bbf6eab..c2a2795a84 100644 --- a/core/unboundmethod/public_spec.rb +++ b/core/unboundmethod/public_spec.rb @@ -2,7 +2,7 @@ require_relative 'fixtures/classes' describe "UnboundMethod#public?" do - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "returns true when the method is public" do obj = UnboundMethodSpecs::Methods.new obj.method(:my_public_method).unbind.public?.should == true diff --git a/language/assignments_spec.rb b/language/assignments_spec.rb index 2773508d8d..222d8699c5 100644 --- a/language/assignments_spec.rb +++ b/language/assignments_spec.rb @@ -276,117 +276,73 @@ def [](k) (@h ||= {})[k]; end describe 'Multiple assignments' do describe 'evaluation order' do - ruby_version_is ''...'3.1' do - it 'evaluates expressions right to left when assignment with an accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) - ScratchPad.recorded.should == [:c, :d, :a, :b] - end - - it 'evaluates expressions right to left when assignment with a nested accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with an accessor' do + object = Object.new + def object.a=(value) end + ScratchPad.record [] - ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] - ScratchPad.recorded.should == [:b, :a] - end + (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) + ScratchPad.recorded.should == [:a, :b, :c, :d] end - ruby_version_is '3.1' do - it 'evaluates expressions left to right when assignment with an accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) - ScratchPad.recorded.should == [:a, :b, :c, :d] - end - - it 'evaluates expressions left to right when assignment with a nested accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] - ScratchPad.recorded.should == [:a, :b] - end - - it 'evaluates expressions left to right when assignment with a deeply nested accessor' do - o = Object.new - def o.a=(value) end - def o.b=(value) end - def o.c=(value) end - def o.d=(value) end - def o.e=(value) end - def o.f=(value) end - ScratchPad.record [] - - (ScratchPad << :a; o).a, - ((ScratchPad << :b; o).b, - ((ScratchPad << :c; o).c, (ScratchPad << :d; o).d), - (ScratchPad << :e; o).e), - (ScratchPad << :f; o).f = (ScratchPad << :value; :value) + it 'evaluates expressions left to right when assignment with a nested accessor' do + object = Object.new + def object.a=(value) end + ScratchPad.record [] - ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value] - end + ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] + ScratchPad.recorded.should == [:a, :b] end - ruby_version_is ''...'3.1' do - it 'evaluates expressions right to left when assignment with a #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] - - (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) - ScratchPad.recorded.should == [:e, :f, :a, :b, :c, :d] - end - - it 'evaluates expressions right to left when assignment with a nested #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] - - ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] - ScratchPad.recorded.should == [:c, :a, :b] - end + it 'evaluates expressions left to right when assignment with a deeply nested accessor' do + o = Object.new + def o.a=(value) end + def o.b=(value) end + def o.c=(value) end + def o.d=(value) end + def o.e=(value) end + def o.f=(value) end + ScratchPad.record [] + + (ScratchPad << :a; o).a, + ((ScratchPad << :b; o).b, + ((ScratchPad << :c; o).c, (ScratchPad << :d; o).d), + (ScratchPad << :e; o).e), + (ScratchPad << :f; o).f = (ScratchPad << :value; :value) + + ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value] end - ruby_version_is '3.1' do - it 'evaluates expressions left to right when assignment with a #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a #[]=' do + object = Object.new + def object.[]=(_, _) end + ScratchPad.record [] - (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) - ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f] - end + (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) + ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f] + end - it 'evaluates expressions left to right when assignment with a nested #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a nested #[]=' do + object = Object.new + def object.[]=(_, _) end + ScratchPad.record [] - ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] - ScratchPad.recorded.should == [:a, :b, :c] - end + ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] + ScratchPad.recorded.should == [:a, :b, :c] + end - it 'evaluates expressions left to right when assignment with a deeply nested #[]=' do - o = Object.new - def o.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a deeply nested #[]=' do + o = Object.new + def o.[]=(_, _) end + ScratchPad.record [] - (ScratchPad << :ra; o)[(ScratchPad << :aa; :aa)], - ((ScratchPad << :rb; o)[(ScratchPad << :ab; :ab)], - ((ScratchPad << :rc; o)[(ScratchPad << :ac; :ac)], (ScratchPad << :rd; o)[(ScratchPad << :ad; :ad)]), - (ScratchPad << :re; o)[(ScratchPad << :ae; :ae)]), - (ScratchPad << :rf; o)[(ScratchPad << :af; :af)] = (ScratchPad << :value; :value) + (ScratchPad << :ra; o)[(ScratchPad << :aa; :aa)], + ((ScratchPad << :rb; o)[(ScratchPad << :ab; :ab)], + ((ScratchPad << :rc; o)[(ScratchPad << :ac; :ac)], (ScratchPad << :rd; o)[(ScratchPad << :ad; :ad)]), + (ScratchPad << :re; o)[(ScratchPad << :ae; :ae)]), + (ScratchPad << :rf; o)[(ScratchPad << :af; :af)] = (ScratchPad << :value; :value) - ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value] - end + ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value] end ruby_version_is ''...'3.2' do diff --git a/language/block_spec.rb b/language/block_spec.rb index 75c1e71bc2..1a73b415f2 100644 --- a/language/block_spec.rb +++ b/language/block_spec.rb @@ -294,7 +294,7 @@ def obj.to_ary; raise "Exception raised in #to_ary" end end it "may include a rescue clause" do - eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7 + @y.z do raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -308,7 +308,7 @@ def obj.to_ary; raise "Exception raised in #to_ary" end end it "may include a rescue clause" do - eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7 + @y.z do || raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -337,7 +337,7 @@ def obj.to_ary; raise "Exception raised in #to_ary" end end it "may include a rescue clause" do - eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7 + @y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -737,9 +737,9 @@ def obj.to_ary; raise "Exception raised in #to_ary" end end it "accepts unnamed arguments" do - eval("lambda { |_,_| }").should be_an_instance_of(Proc) - eval("->(_,_) {}").should be_an_instance_of(Proc) - eval("Proc.new { |_,_| }").should be_an_instance_of(Proc) + lambda { |_,_| }.should be_an_instance_of(Proc) # rubocop:disable Style/Lambda + -> _,_ {}.should be_an_instance_of(Proc) + Proc.new { |_,_| }.should be_an_instance_of(Proc) end end @@ -1001,55 +1001,43 @@ def a; 1; end # tested more thoroughly in language/delegation_spec.rb describe "Anonymous block forwarding" do - ruby_version_is "3.1" do - it "forwards blocks to other method that formally declares anonymous block" do - eval <<-EOF - def b(&); c(&) end - def c(&); yield :non_null end - EOF + it "forwards blocks to other method that formally declares anonymous block" do + def b(&); c(&) end + def c(&); yield :non_null end - b { |c| c }.should == :non_null - end + b { |c| c }.should == :non_null + end - it "requires the anonymous block parameter to be declared if directly passing a block" do - -> { eval "def a; b(&); end; def b; end" }.should raise_error(SyntaxError) - end + it "requires the anonymous block parameter to be declared if directly passing a block" do + -> { eval "def a; b(&); end; def b; end" }.should raise_error(SyntaxError) + end - it "works when it's the only declared parameter" do - eval <<-EOF - def inner; yield end - def block_only(&); inner(&) end - EOF + it "works when it's the only declared parameter" do + def inner; yield end + def block_only(&); inner(&) end - block_only { 1 }.should == 1 - end + block_only { 1 }.should == 1 + end - it "works alongside positional parameters" do - eval <<-EOF - def inner; yield end - def pos(arg1, &); inner(&) end - EOF + it "works alongside positional parameters" do + def inner; yield end + def pos(arg1, &); inner(&) end - pos(:a) { 1 }.should == 1 - end + pos(:a) { 1 }.should == 1 + end - it "works alongside positional arguments and splatted keyword arguments" do - eval <<-EOF - def inner; yield end - def pos_kwrest(arg1, **kw, &); inner(&) end - EOF + it "works alongside positional arguments and splatted keyword arguments" do + def inner; yield end + def pos_kwrest(arg1, **kw, &); inner(&) end - pos_kwrest(:a, arg: 3) { 1 }.should == 1 - end + pos_kwrest(:a, arg: 3) { 1 }.should == 1 + end - it "works alongside positional arguments and disallowed keyword arguments" do - eval <<-EOF - def inner; yield end - def no_kw(arg1, **nil, &); inner(&) end - EOF + it "works alongside positional arguments and disallowed keyword arguments" do + def inner; yield end + def no_kw(arg1, **nil, &); inner(&) end - no_kw(:a) { 1 }.should == 1 - end + no_kw(:a) { 1 }.should == 1 end ruby_version_is "3.2" do diff --git a/language/delegation_spec.rb b/language/delegation_spec.rb index b75f3f5f7c..0fcd3e57bf 100644 --- a/language/delegation_spec.rb +++ b/language/delegation_spec.rb @@ -137,27 +137,25 @@ def delegate(**) end end -ruby_version_is "3.1" do - describe "delegation with def(&)" do - it "delegates an anonymous block parameter" do - a = Class.new(DelegationSpecs::Target) - a.class_eval(<<-RUBY) - def delegate(&) - target(&) - end - RUBY - - block = proc {} - a.new.delegate(&block).should == [[], {}, block] +describe "delegation with def(&)" do + it "delegates an anonymous block parameter" do + a = Class.new(DelegationSpecs::Target) + a.class_eval(<<-RUBY) + def delegate(&) + target(&) end + RUBY - 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 + block = proc {} + 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 end end diff --git a/language/hash_spec.rb b/language/hash_spec.rb index 068ac0f39c..b119b6ca73 100644 --- a/language/hash_spec.rb +++ b/language/hash_spec.rb @@ -60,14 +60,12 @@ @h.should == {1000 => :foo} end - ruby_version_is "3.1" do - it "checks duplicated float keys on initialization" do - -> { - @h = eval "{1.0 => :bar, 1.0 => :foo}" - }.should complain(/key 1.0 is duplicated|duplicated key/) - @h.keys.size.should == 1 - @h.should == {1.0 => :foo} - end + it "checks duplicated float keys on initialization" do + -> { + @h = eval "{1.0 => :bar, 1.0 => :foo}" + }.should complain(/key 1.0 is duplicated|duplicated key/) + @h.keys.size.should == 1 + @h.should == {1.0 => :foo} end it "accepts a hanging comma" do @@ -77,9 +75,9 @@ end it "recognizes '=' at the end of the key" do - eval("{:a==>1}").should == {:"a=" => 1} - eval("{:a= =>1}").should == {:"a=" => 1} - eval("{:a= => 1}").should == {:"a=" => 1} + {:a==>1}.should == {:"a=" => 1} + {:a= =>1}.should == {:"a=" => 1} + {:a= => 1}.should == {:"a=" => 1} end it "with '==>' in the middle raises SyntaxError" do @@ -87,11 +85,11 @@ end it "recognizes '!' at the end of the key" do - eval("{:a! =>1}").should == {:"a!" => 1} - eval("{:a! => 1}").should == {:"a!" => 1} + {:a! =>1}.should == {:"a!" => 1} + {:a! => 1}.should == {:"a!" => 1} - eval("{a!:1}").should == {:"a!" => 1} - eval("{a!: 1}").should == {:"a!" => 1} + {a!:1}.should == {:"a!" => 1} + {a!: 1}.should == {:"a!" => 1} end it "raises a SyntaxError if there is no space between `!` and `=>`" do @@ -99,11 +97,11 @@ end it "recognizes '?' at the end of the key" do - eval("{:a? =>1}").should == {:"a?" => 1} - eval("{:a? => 1}").should == {:"a?" => 1} + {:a? =>1}.should == {:"a?" => 1} + {:a? => 1}.should == {:"a?" => 1} - eval("{a?:1}").should == {:"a?" => 1} - eval("{a?: 1}").should == {:"a?" => 1} + {a?:1}.should == {:"a?" => 1} + {a?: 1}.should == {:"a?" => 1} end it "raises a SyntaxError if there is no space between `?` and `=>`" do @@ -129,7 +127,7 @@ it "accepts mixed 'key: value', 'key => value' and '\"key\"': value' syntax" do h = {:a => 1, :b => 2, "c" => 3, :d => 4} - eval('{a: 1, :b => 2, "c" => 3, "d": 4}').should == h + {a: 1, :b => 2, "c" => 3, "d": 4}.should == h end it "expands an '**{}' element into the containing Hash literal initialization" do @@ -259,50 +257,48 @@ def m(h) end end - ruby_version_is "3.1" do - describe "hash with omitted value" do - it "accepts short notation 'key' for 'key: value' syntax" do - a, b, c = 1, 2, 3 - h = eval('{a:}') - {a: 1}.should == h - h = eval('{a:, b:, c:}') - {a: 1, b: 2, c: 3}.should == h - end + describe "hash with omitted value" do + it "accepts short notation 'key' for 'key: value' syntax" do + a, b, c = 1, 2, 3 + h = {a:} + {a: 1}.should == h + h = {a:, b:, c:} + {a: 1, b: 2, c: 3}.should == h + end - it "ignores hanging comma on short notation" do - a, b, c = 1, 2, 3 - h = eval('{a:, b:, c:,}') - {a: 1, b: 2, c: 3}.should == h - end + it "ignores hanging comma on short notation" do + a, b, c = 1, 2, 3 + h = {a:, b:, c:,} + {a: 1, b: 2, c: 3}.should == h + end - it "accepts mixed syntax" do - a, e = 1, 5 - h = eval('{a:, b: 2, "c" => 3, :d => 4, e:}') - eval('{a: 1, :b => 2, "c" => 3, "d": 4, e: 5}').should == h - end + it "accepts mixed syntax" do + a, e = 1, 5 + h = {a:, b: 2, "c" => 3, :d => 4, e:} + {a: 1, :b => 2, "c" => 3, "d": 4, e: 5}.should == h + end - it "works with methods and local vars" do - a = Class.new - a.class_eval(<<-RUBY) - def bar - "baz" - end + it "works with methods and local vars" do + a = Class.new + a.class_eval(<<-RUBY) + def bar + "baz" + end - def foo(val) - {bar:, val:} - end - RUBY + def foo(val) + {bar:, val:} + end + RUBY - a.new.foo(1).should == {bar: "baz", val: 1} - end + a.new.foo(1).should == {bar: "baz", val: 1} + end - it "raises a SyntaxError when the hash key ends with `!`" do - -> { eval("{a!:}") }.should raise_error(SyntaxError, /identifier a! is not valid to get/) - end + it "raises a SyntaxError when the hash key ends with `!`" do + -> { eval("{a!:}") }.should raise_error(SyntaxError, /identifier a! is not valid to get/) + end - it "raises a SyntaxError when the hash key ends with `?`" do - -> { eval("{a?:}") }.should raise_error(SyntaxError, /identifier a\? is not valid to get/) - end + it "raises a SyntaxError when the hash key ends with `?`" do + -> { eval("{a?:}") }.should raise_error(SyntaxError, /identifier a\? is not valid to get/) end end end diff --git a/language/keyword_arguments_spec.rb b/language/keyword_arguments_spec.rb index 8668799d26..3f8ddfa40d 100644 --- a/language/keyword_arguments_spec.rb +++ b/language/keyword_arguments_spec.rb @@ -323,18 +323,16 @@ def m(*args) m({a: 1}).should == [[{a: 1}], {}] end - ruby_version_is "3.1" do - describe "omitted values" do - it "accepts short notation 'key' for 'key: value' syntax" do - def m(a:, b:) - [a, b] - end + describe "omitted values" do + it "accepts short notation 'key' for 'key: value' syntax" do + def m(a:, b:) + [a, b] + end - a = 1 - b = 2 + a = 1 + b = 2 - eval('m(a:, b:).should == [1, 2]') - end + m(a:, b:).should == [1, 2] end end diff --git a/language/method_spec.rb b/language/method_spec.rb index 9abe4cde20..b0d7058dbe 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -1416,53 +1416,49 @@ def foo(a, b, c, key: 1) end end -ruby_version_is "3.1" do - describe "kwarg with omitted value in a method call" do - context "accepts short notation 'kwarg' in method call" do - evaluate <<-ruby do - def call(*args, **kwargs) = [args, kwargs] - ruby +describe "kwarg with omitted value in a method call" do + context "accepts short notation 'kwarg' in method call" do + evaluate <<-ruby do + def call(*args, **kwargs) = [args, kwargs] + ruby - a, b, c = 1, 2, 3 - arr, h = eval('call a:') - h.should == {a: 1} - arr.should == [] + a, b, c = 1, 2, 3 + arr, h = call(a:) + h.should == {a: 1} + arr.should == [] - arr, h = eval('call(a:, b:, c:)') - h.should == {a: 1, b: 2, c: 3} - arr.should == [] + arr, h = call(a:, b:, c:) + h.should == {a: 1, b: 2, c: 3} + arr.should == [] - arr, h = eval('call(a:, b: 10, c:)') - h.should == {a: 1, b: 10, c: 3} - arr.should == [] - end + arr, h = call(a:, b: 10, c:) + h.should == {a: 1, b: 10, c: 3} + arr.should == [] end + end - context "with methods and local variables" do - evaluate <<-ruby do - def call(*args, **kwargs) = [args, kwargs] + context "with methods and local variables" do + evaluate <<-ruby do + def call(*args, **kwargs) = [args, kwargs] - def bar - "baz" - end + def bar + "baz" + end - def foo(val) - call bar:, val: - end - ruby + def foo(val) + call bar:, val: + end + ruby - foo(1).should == [[], {bar: "baz", val: 1}] - end + foo(1).should == [[], {bar: "baz", val: 1}] end end +end - describe "Inside 'endless' method definitions" do - it "allows method calls without parenthesis" do - eval <<-ruby - def greet(person) = "Hi, ".dup.concat person - ruby +describe "Inside 'endless' method definitions" do + it "allows method calls without parenthesis" do + def greet(person) = "Hi, ".dup.concat person - greet("Homer").should == "Hi, Homer" - end + greet("Homer").should == "Hi, Homer" end end diff --git a/language/pattern_matching/3.1.rb b/language/pattern_matching/3.1.rb deleted file mode 100644 index 7a09084e41..0000000000 --- a/language/pattern_matching/3.1.rb +++ /dev/null @@ -1,75 +0,0 @@ -describe "Pattern matching" do - before :each do - ScratchPad.record [] - end - - describe "Ruby 3.1 improvements" do - ruby_version_is "3.1" do - it "can omit parentheses in one line pattern matching" do - [1, 2] => a, b - [a, b].should == [1, 2] - - {a: 1} => a: - a.should == 1 - end - - it "supports pinning instance variables" do - @a = /a/ - case 'abc' - in ^@a - true - end.should == true - end - - it "supports pinning class variables" do - result = nil - Module.new do - result = module_eval(<<~RUBY) - @@a = 0..10 - - case 2 - in ^@@a - true - end - RUBY - end - - result.should == true - end - - it "supports pinning global variables" do - $a = /a/ - case 'abc' - in ^$a - true - end.should == true - end - - it "supports pinning expressions" do - case 'abc' - in ^(/a/) - true - end.should == true - - case 0 - in ^(0 + 0) - true - end.should == true - end - - it "supports pinning expressions in array pattern" do - case [3] - in [^(1 + 2)] - true - end.should == true - end - - it "supports pinning expressions in hash pattern" do - case {name: '2.6', released_at: Time.new(2018, 12, 25)} - in {released_at: ^(Time.new(2010)..Time.new(2020))} - true - end.should == true - end - end - end -end diff --git a/language/pattern_matching_spec.rb b/language/pattern_matching_spec.rb index 94432b1fa0..cb4f5864d7 100644 --- a/language/pattern_matching_spec.rb +++ b/language/pattern_matching_spec.rb @@ -164,16 +164,8 @@ @src = '[0, 1] => [a, b]' end - ruby_version_is ""..."3.1" do - it "warns about pattern matching is experimental feature" do - -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i) - end - end - - ruby_version_is "3.1" do - it "does not warn about pattern matching is experimental feature" do - -> { eval @src }.should_not complain - end + it "does not warn about pattern matching is experimental feature" do + -> { eval @src }.should_not complain end end end @@ -1220,8 +1212,99 @@ def ===(obj) result.should == true end end -end -ruby_version_is "3.1" do - require_relative 'pattern_matching/3.1' + describe "Ruby 3.1 improvements" do + it "can omit parentheses in one line pattern matching" do + [1, 2] => a, b + [a, b].should == [1, 2] + + {a: 1} => a: + a.should == 1 + end + + it "supports pinning instance variables" do + @a = /a/ + case 'abc' + in ^@a + true + end.should == true + end + + it "supports pinning class variables" do + result = nil + Module.new do + # avoid "class variable access from toplevel" runtime error with #module_eval + result = module_eval(<<~RUBY) + @@a = 0..10 + + case 2 + in ^@@a + true + end + RUBY + end + + result.should == true + end + + it "supports pinning global variables" do + $a = /a/ + case 'abc' + in ^$a + true + end.should == true + end + + it "supports pinning expressions" do + case 'abc' + in ^(/a/) + true + end.should == true + + case 0 + in ^(0 + 0) + true + end.should == true + end + + it "supports pinning expressions in array pattern" do + case [3] + in [^(1 + 2)] + true + end.should == true + end + + it "supports pinning expressions in hash pattern" do + case {name: '2.6', released_at: Time.new(2018, 12, 25)} + in {released_at: ^(Time.new(2010)..Time.new(2020))} + true + end.should == true + end + end + + describe "value in pattern" do + it "returns true if the pattern matches" do + (1 in 1).should == true + + (1 in Integer).should == true + + e = nil + ([1, 2] in [1, e]).should == true + e.should == 2 + + k = nil + ({k: 1} in {k:}).should == true + k.should == 1 + end + + it "returns false if the pattern does not match" do + (1 in 2).should == false + + (1 in Float).should == false + + ([1, 2] in [2, e]).should == false + + ({k: 1} in {k: 2}).should == false + end + end end diff --git a/language/predefined_spec.rb b/language/predefined_spec.rb index cc231e341e..9338a04715 100644 --- a/language/predefined_spec.rb +++ b/language/predefined_spec.rb @@ -71,7 +71,7 @@ def obj.foo2(&proc); proc.call; end match2.should_not == nil $~.should == match2 - eval 'match3 = /baz/.match("baz")' + match3 = /baz/.match("baz") match3.should_not == nil $~.should == match3 @@ -768,7 +768,7 @@ def obj.foo2; yield; end match.should == "bar\n" $_.should == match - eval 'match = stdin.gets' + match = stdin.gets match.should == "baz\n" $_.should == match @@ -1341,16 +1341,8 @@ def obj.foo2; yield; end path.should.end_with?("/etc.#{RbConfig::CONFIG['DLEXT']}") end - ruby_version_is ""..."3.1" do - it "raises LoadError if feature cannot be found" do - -> { $LOAD_PATH.resolve_feature_path('noop') }.should raise_error(LoadError) - end - end - - ruby_version_is "3.1" do - it "return nil if feature cannot be found" do - $LOAD_PATH.resolve_feature_path('noop').should be_nil - end + it "return nil if feature cannot be found" do + $LOAD_PATH.resolve_feature_path('noop').should be_nil end end diff --git a/language/variables_spec.rb b/language/variables_spec.rb index 01be61a9dc..2bca287d2c 100644 --- a/language/variables_spec.rb +++ b/language/variables_spec.rb @@ -14,69 +14,34 @@ end context "with multiple assignment" do - ruby_version_is ""..."3.1" do - it "does not evaluate from left to right" do - obj = VariablesSpecs::EvalOrder.new - - obj.instance_eval do - foo[0], bar.baz = a, b - end - - obj.order.should == ["a", "b", "foo", "foo[]=", "bar", "bar.baz="] + it "evaluates from left to right, receivers first then methods" do + obj = VariablesSpecs::EvalOrder.new + obj.instance_eval do + foo[0], bar.baz = a, b end - it "cannot be used to swap variables with nested method calls" do - node = VariablesSpecs::EvalOrder.new.node - - original_node = node - original_node_left = node.left - original_node_left_right = node.left.right - - node.left, node.left.right, node = node.left.right, node, node.left - # Should evaluate in the order of: - # RHS: node.left.right, node, node.left - # LHS: - # * node(original_node), original_node.left = original_node_left_right - # * node(original_node), node.left(changed in the previous assignment to original_node_left_right), - # original_node_left_right.right = original_node - # * node = original_node_left - - node.should == original_node_left - node.right.should_not == original_node - node.right.left.should_not == original_node_left_right - end + obj.order.should == ["foo", "bar", "a", "b", "foo[]=", "bar.baz="] end - ruby_version_is "3.1" do - it "evaluates from left to right, receivers first then methods" do - obj = VariablesSpecs::EvalOrder.new - obj.instance_eval do - foo[0], bar.baz = a, b - end + it "can be used to swap variables with nested method calls" do + node = VariablesSpecs::EvalOrder.new.node - obj.order.should == ["foo", "bar", "a", "b", "foo[]=", "bar.baz="] - end + original_node = node + original_node_left = node.left + original_node_left_right = node.left.right - it "can be used to swap variables with nested method calls" do - node = VariablesSpecs::EvalOrder.new.node - - original_node = node - original_node_left = node.left - original_node_left_right = node.left.right - - node.left, node.left.right, node = node.left.right, node, node.left - # Should evaluate in the order of: - # LHS: node, node.left(original_node_left) - # RHS: original_node_left_right, original_node, original_node_left - # Ops: - # * node(original_node), original_node.left = original_node_left_right - # * original_node_left.right = original_node - # * node = original_node_left - - node.should == original_node_left - node.right.should == original_node - node.right.left.should == original_node_left_right - end + node.left, node.left.right, node = node.left.right, node, node.left + # Should evaluate in the order of: + # LHS: node, node.left(original_node_left) + # RHS: original_node_left_right, original_node, original_node_left + # Ops: + # * node(original_node), original_node.left = original_node_left_right + # * original_node_left.right = original_node + # * node = original_node_left + + node.should == original_node_left + node.right.should == original_node + node.right.left.should == original_node_left_right end end end diff --git a/library/coverage/result_spec.rb b/library/coverage/result_spec.rb index 54a3249e45..bc999a5369 100644 --- a/library/coverage/result_spec.rb +++ b/library/coverage/result_spec.rb @@ -108,16 +108,6 @@ result.should == {} end - ruby_version_is ''...'3.1' do - it 'second Coverage.start does nothing' do - Coverage.start - require @config_file.chomp('.rb') - result = Coverage.result - - result.should == { @config_file => [1, 1, 1] } - end - end - it 'does not include the file starting coverage since it is not tracked' do require @config_file.chomp('.rb') Coverage.result.should_not include(@config_file) diff --git a/library/coverage/start_spec.rb b/library/coverage/start_spec.rb index 7fccf2d5cf..757837a462 100644 --- a/library/coverage/start_spec.rb +++ b/library/coverage/start_spec.rb @@ -19,14 +19,12 @@ Coverage.start.should == nil end - ruby_version_is '3.1' do - it 'raises error when repeated Coverage.start call happens' do - Coverage.start + it 'raises error when repeated Coverage.start call happens' do + Coverage.start - -> { - Coverage.start - }.should raise_error(RuntimeError, 'coverage measurement is already setup') - end + -> { + Coverage.start + }.should raise_error(RuntimeError, 'coverage measurement is already setup') end ruby_version_is '3.2' do diff --git a/library/date/strftime_spec.rb b/library/date/strftime_spec.rb index b5232a2073..1b93a8d1b2 100644 --- a/library/date/strftime_spec.rb +++ b/library/date/strftime_spec.rb @@ -23,19 +23,9 @@ @date.strftime("%Z").should == "+00:00" end - # %v is %e-%b-%Y for Date/DateTime - version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do - it "should be able to show the commercial week" do - @date.strftime("%v").should == " 9-Apr-2000" - @date.strftime("%v").should == @date.strftime('%e-%b-%Y') - end - end - - version_is date_version, "3.2" do #ruby_version_is "3.1" do - it "should be able to show the commercial week" do - @date.strftime("%v").should == " 9-APR-2000" - @date.strftime("%v").should != @date.strftime('%e-%b-%Y') - end + it "should be able to show the commercial week" do + @date.strftime("%v").should == " 9-APR-2000" + @date.strftime("%v").should != @date.strftime('%e-%b-%Y') end # additional conversion specifiers only in Date/DateTime diff --git a/library/datetime/strftime_spec.rb b/library/datetime/strftime_spec.rb index abb0838e8e..a07cc9c1aa 100644 --- a/library/datetime/strftime_spec.rb +++ b/library/datetime/strftime_spec.rb @@ -33,19 +33,9 @@ @time.strftime("%Z").should == "+00:00" end - # %v is %e-%b-%Y for Date/DateTime - version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do - it "should be able to show the commercial week" do - @time.strftime("%v").should == " 3-Feb-2001" - @time.strftime("%v").should == @time.strftime('%e-%b-%Y') - end - end - - version_is date_version, "3.2" do #ruby_version_is "3.1" do - it "should be able to show the commercial week" do - @time.strftime("%v").should == " 3-FEB-2001" - @time.strftime("%v").should != @time.strftime('%e-%b-%Y') - end + it "should be able to show the commercial week" do + @time.strftime("%v").should == " 3-FEB-2001" + @time.strftime("%v").should != @time.strftime('%e-%b-%Y') end # additional conversion specifiers only in Date/DateTime diff --git a/library/erb/new_spec.rb b/library/erb/new_spec.rb index f721529ab0..ec1be5c234 100644 --- a/library/erb/new_spec.rb +++ b/library/erb/new_spec.rb @@ -140,18 +140,16 @@ end describe "warning about arguments" do - version_is ERB.version, "2.2.1" do #ruby_version_is "3.1" do - it "warns when passed safe_level and later arguments" do - -> { - ERB.new(@eruby_str, nil, '%') - }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) - end - - it "does not warn when passed arguments as keyword argument" do - -> { - ERB.new(@eruby_str, trim_mode: '%') - }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) - end + it "warns when passed safe_level and later arguments" do + -> { + ERB.new(@eruby_str, nil, '%') + }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) + end + + it "does not warn when passed arguments as keyword argument" do + -> { + ERB.new(@eruby_str, trim_mode: '%') + }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./) end end end diff --git a/library/fiber/current_spec.rb b/library/fiber/current_spec.rb index 1467a88d0d..66e7b35167 100644 --- a/library/fiber/current_spec.rb +++ b/library/fiber/current_spec.rb @@ -3,10 +3,8 @@ require 'fiber' describe "Fiber.current" do - ruby_version_is "3.1" do - it "is available without an extra require" do - ruby_exe("print Fiber.current.class", options: '--disable-gems --disable-did-you-mean').should == "Fiber" - end + it "is available without an extra require" do + ruby_exe("print Fiber.current.class", options: '--disable-gems --disable-did-you-mean').should == "Fiber" end it "returns the root Fiber when called outside of a Fiber" do diff --git a/library/ipaddr/new_spec.rb b/library/ipaddr/new_spec.rb index 714c1e2f1a..2c0f44acf2 100644 --- a/library/ipaddr/new_spec.rb +++ b/library/ipaddr/new_spec.rb @@ -77,40 +77,16 @@ a.family.should == Socket::AF_INET6 end - ipaddr_version = if defined?(IPAddr::VERSION) #ruby_version_is ""..."3.1" do - IPAddr::VERSION - else - "1.2.2" - end - - version_is ipaddr_version, ""..."1.2.3" do #ruby_version_is ""..."3.1" do - it "raises on incorrect IPAddr strings" do - [ - ["fe80::1%fxp0"], - ["::1/255.255.255.0"], - [IPAddr.new("::1").to_i], - ["::ffff:192.168.1.2/120", Socket::AF_INET], - ["[192.168.1.2]/120"], - ].each { |args| - ->{ - IPAddr.new(*args) - }.should raise_error(ArgumentError) - } - end - end - - version_is ipaddr_version, "1.2.3" do #ruby_version_is "3.1" do - it "raises on incorrect IPAddr strings" do - [ - ["::1/255.255.255.0"], - [IPAddr.new("::1").to_i], - ["::ffff:192.168.1.2/120", Socket::AF_INET], - ["[192.168.1.2]/120"], - ].each { |args| - ->{ - IPAddr.new(*args) - }.should raise_error(ArgumentError) - } - end + it "raises on incorrect IPAddr strings" do + [ + ["::1/255.255.255.0"], + [IPAddr.new("::1").to_i], + ["::ffff:192.168.1.2/120", Socket::AF_INET], + ["[192.168.1.2]/120"], + ].each { |args| + ->{ + IPAddr.new(*args) + }.should raise_error(ArgumentError) + } end end diff --git a/library/matrix/exponent_spec.rb b/library/matrix/exponent_spec.rb index b76e18b4cd..38cdfa9276 100644 --- a/library/matrix/exponent_spec.rb +++ b/library/matrix/exponent_spec.rb @@ -34,17 +34,15 @@ end end - ruby_version_is '3.1.0' do # https://bugs.ruby-lang.org/issues/17521 - describe "that is 0" do - it "returns the identity for square matrices" do - m = Matrix[ [1, 1], [1, 1] ] - (m ** 0).should == Matrix.identity(2) - end + describe "that is 0" do + it "returns the identity for square matrices" do + m = Matrix[ [1, 1], [1, 1] ] + (m ** 0).should == Matrix.identity(2) + end - it "raises an ErrDimensionMismatch for non-square matrices" do - m = Matrix[ [1, 1] ] - -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an ErrDimensionMismatch for non-square matrices" do + m = Matrix[ [1, 1] ] + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/library/net-ftp/connect_spec.rb b/library/net-ftp/connect_spec.rb index 4330d430b4..e606b11e2a 100644 --- a/library/net-ftp/connect_spec.rb +++ b/library/net-ftp/connect_spec.rb @@ -26,14 +26,6 @@ @ftp.connect(@server.hostname, @server.server_port).should be_nil end - ruby_version_is ""..."3.1" do - it "prints a small debug line when in debug mode" do - @ftp.debug_mode = true - -> { @ftp.connect(@server.hostname, @server.server_port) }.should output(/connect: #{@server.hostname}, #{@server.server_port}\nget: 220 Dummy FTP Server ready!/) - @ftp.debug_mode = false - end - end - it "does not raise any error when the response code is 220" do @server.connect_message = "220 Dummy FTP Server ready!" -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error diff --git a/library/objectspace/trace_spec.rb b/library/objectspace/trace_spec.rb index 532c282ce4..3957dc930d 100644 --- a/library/objectspace/trace_spec.rb +++ b/library/objectspace/trace_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' -ruby_version_is "3.1" do - describe 'require "objspace/trace"' do - it "shows object allocation sites" do - file = fixture(__FILE__ , "trace.rb") - ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ - "objspace/trace is enabled", - "\"foo\" @ #{file}:3", - "\"bar\" @ #{file}:4", - "42" - ] - end +describe 'require "objspace/trace"' do + it "shows object allocation sites" do + file = fixture(__FILE__ , "trace.rb") + ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ + "objspace/trace is enabled", + "\"foo\" @ #{file}:3", + "\"bar\" @ #{file}:4", + "42" + ] end end diff --git a/library/random/formatter/alphanumeric_spec.rb b/library/random/formatter/alphanumeric_spec.rb index df14c29e24..9bd325e1d0 100644 --- a/library/random/formatter/alphanumeric_spec.rb +++ b/library/random/formatter/alphanumeric_spec.rb @@ -1,58 +1,56 @@ require_relative '../../../spec_helper' -ruby_version_is "3.1" do - require 'random/formatter' - - describe "Random::Formatter#alphanumeric" do - before :each do - @object = Object.new - @object.extend(Random::Formatter) - @object.define_singleton_method(:bytes) do |n| - "\x00".b * n - end - end +require 'random/formatter' - it "generates a random alphanumeric string" do - @object.alphanumeric.should =~ /\A[A-Za-z0-9]+\z/ +describe "Random::Formatter#alphanumeric" do + before :each do + @object = Object.new + @object.extend(Random::Formatter) + @object.define_singleton_method(:bytes) do |n| + "\x00".b * n end + end - it "has a default size of 16 characters" do - @object.alphanumeric.size.should == 16 - end + it "generates a random alphanumeric string" do + @object.alphanumeric.should =~ /\A[A-Za-z0-9]+\z/ + end - it "accepts a 'size' argument" do - @object.alphanumeric(10).size.should == 10 - end + it "has a default size of 16 characters" do + @object.alphanumeric.size.should == 16 + end - it "uses the default size if 'nil' is given as size argument" do - @object.alphanumeric(nil).size.should == 16 - end + it "accepts a 'size' argument" do + @object.alphanumeric(10).size.should == 10 + end - it "raises an ArgumentError if the size is not numeric" do - -> { - @object.alphanumeric("10") - }.should raise_error(ArgumentError) - end + it "uses the default size if 'nil' is given as size argument" do + @object.alphanumeric(nil).size.should == 16 + end + + it "raises an ArgumentError if the size is not numeric" do + -> { + @object.alphanumeric("10") + }.should raise_error(ArgumentError) + end + + it "does not coerce the size argument with #to_int" do + size = mock("size") + size.should_not_receive(:to_int) + -> { + @object.alphanumeric(size) + }.should raise_error(ArgumentError) + end - it "does not coerce the size argument with #to_int" do - size = mock("size") - size.should_not_receive(:to_int) - -> { - @object.alphanumeric(size) - }.should raise_error(ArgumentError) + 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 - 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 "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 end diff --git a/library/rbconfig/unicode_emoji_version_spec.rb b/library/rbconfig/unicode_emoji_version_spec.rb index 3dc9900127..f96429695c 100644 --- a/library/rbconfig/unicode_emoji_version_spec.rb +++ b/library/rbconfig/unicode_emoji_version_spec.rb @@ -2,13 +2,7 @@ require 'rbconfig' describe "RbConfig::CONFIG['UNICODE_EMOJI_VERSION']" do - ruby_version_is ""..."3.1" do - it "is 12.1" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "12.1" - end - end - - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "is 13.1" do RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "13.1" end diff --git a/library/rbconfig/unicode_version_spec.rb b/library/rbconfig/unicode_version_spec.rb index 458f13bf03..df12abda0b 100644 --- a/library/rbconfig/unicode_version_spec.rb +++ b/library/rbconfig/unicode_version_spec.rb @@ -2,13 +2,7 @@ require 'rbconfig' describe "RbConfig::CONFIG['UNICODE_VERSION']" do - ruby_version_is ""..."3.1" do - it "is 12.1.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "12.1.0" - end - end - - ruby_version_is "3.1"..."3.2" do + ruby_version_is ""..."3.2" do it "is 13.0.0" do RbConfig::CONFIG['UNICODE_VERSION'].should == "13.0.0" end diff --git a/library/set/pretty_print_spec.rb b/library/set/pretty_print_spec.rb deleted file mode 100644 index ea9ead0df8..0000000000 --- a/library/set/pretty_print_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../spec_helper' -require 'set' - -ruby_version_is ""..."3.1" do - describe "Set#pretty_print" do - it "passes the 'pretty print' representation of self to the pretty print writer" do - pp = mock("PrettyPrint") - set = Set[1, 2, 3] - - pp.should_receive(:text).with("#") - - pp.should_receive(:nest).with(1).and_yield - pp.should_receive(:seplist).with(set) - - set.pretty_print(pp) - end - end -end diff --git a/optional/capi/fiber_spec.rb b/optional/capi/fiber_spec.rb index 357033f860..6c72869106 100644 --- a/optional/capi/fiber_spec.rb +++ b/optional/capi/fiber_spec.rb @@ -49,41 +49,39 @@ end end - ruby_version_is '3.1' do - describe "rb_fiber_raise" do - it "raises an exception on the resumed fiber" do - fiber = Fiber.new do - begin - Fiber.yield - rescue => error - error - end + describe "rb_fiber_raise" do + it "raises an exception on the resumed fiber" do + fiber = Fiber.new do + begin + Fiber.yield + rescue => error + error end + end - fiber.resume + fiber.resume - result = @s.rb_fiber_raise(fiber, "Boom!") - result.should be_an_instance_of(RuntimeError) - result.message.should == "Boom!" - end + result = @s.rb_fiber_raise(fiber, "Boom!") + result.should be_an_instance_of(RuntimeError) + result.message.should == "Boom!" + end - it "raises an exception on the transferred fiber" do - main = Fiber.current + it "raises an exception on the transferred fiber" do + main = Fiber.current - fiber = Fiber.new do - begin - main.transfer - rescue => error - error - end + fiber = Fiber.new do + begin + main.transfer + rescue => error + error end + end - fiber.transfer + fiber.transfer - result = @s.rb_fiber_raise(fiber, "Boom!") - result.should be_an_instance_of(RuntimeError) - result.message.should == "Boom!" - end + result = @s.rb_fiber_raise(fiber, "Boom!") + result.should be_an_instance_of(RuntimeError) + result.message.should == "Boom!" end end end diff --git a/optional/capi/io_spec.rb b/optional/capi/io_spec.rb index dbfaf556f6..ab7a7fc8f6 100644 --- a/optional/capi/io_spec.rb +++ b/optional/capi/io_spec.rb @@ -262,40 +262,38 @@ end end - ruby_version_is "3.1" do - describe "rb_io_maybe_wait_writable" do - it "returns mask for events if operation was interrupted" do - @o.rb_io_maybe_wait_writable(Errno::EINTR::Errno, @w_io, nil).should == IO::WRITABLE - end + describe "rb_io_maybe_wait_writable" do + it "returns mask for events if operation was interrupted" do + @o.rb_io_maybe_wait_writable(Errno::EINTR::Errno, @w_io, nil).should == IO::WRITABLE + end - it "returns 0 if there is no error condition" do - @o.rb_io_maybe_wait_writable(0, @w_io, nil).should == 0 - end + it "returns 0 if there is no error condition" do + @o.rb_io_maybe_wait_writable(0, @w_io, nil).should == 0 + end - it "raises an IOError if the IO is closed" do - @w_io.close - -> { @o.rb_io_maybe_wait_writable(0, @w_io, nil) }.should raise_error(IOError, "closed stream") - end + it "raises an IOError if the IO is closed" do + @w_io.close + -> { @o.rb_io_maybe_wait_writable(0, @w_io, nil) }.should raise_error(IOError, "closed stream") + end - it "raises an IOError if the IO is not initialized" do - -> { @o.rb_io_maybe_wait_writable(0, IO.allocate, nil) }.should raise_error(IOError, "uninitialized stream") - end + it "raises an IOError if the IO is not initialized" do + -> { @o.rb_io_maybe_wait_writable(0, IO.allocate, nil) }.should raise_error(IOError, "uninitialized stream") + end - it "can be interrupted" do - IOSpec.exhaust_write_buffer(@w_io) - start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + it "can be interrupted" do + IOSpec.exhaust_write_buffer(@w_io) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t = Thread.new do - @o.rb_io_maybe_wait_writable(0, @w_io, 10) - end + t = Thread.new do + @o.rb_io_maybe_wait_writable(0, @w_io, 10) + end - Thread.pass until t.stop? - t.kill - t.join + Thread.pass until t.stop? + t.kill + t.join - finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) - (finish - start).should < 9 - end + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 end end @@ -349,52 +347,50 @@ end end - ruby_version_is "3.1" do - describe "rb_io_maybe_wait_readable" do - it "returns mask for events if operation was interrupted" do - @o.rb_io_maybe_wait_readable(Errno::EINTR::Errno, @r_io, nil, false).should == IO::READABLE - end - - it "returns 0 if there is no error condition" do - @o.rb_io_maybe_wait_readable(0, @r_io, nil, false).should == 0 - end - - it "blocks until the io is readable and returns events that actually occurred" do - @o.instance_variable_set :@write_data, false - thr = Thread.new do - Thread.pass until @o.instance_variable_get(:@write_data) - @w_io.write "rb_io_wait_readable" - end + describe "rb_io_maybe_wait_readable" do + it "returns mask for events if operation was interrupted" do + @o.rb_io_maybe_wait_readable(Errno::EINTR::Errno, @r_io, nil, false).should == IO::READABLE + end - @o.rb_io_maybe_wait_readable(Errno::EAGAIN::Errno, @r_io, IO::READABLE, true).should == IO::READABLE - @o.instance_variable_get(:@read_data).should == "rb_io_wait_re" + it "returns 0 if there is no error condition" do + @o.rb_io_maybe_wait_readable(0, @r_io, nil, false).should == 0 + end - thr.join + it "blocks until the io is readable and returns events that actually occurred" do + @o.instance_variable_set :@write_data, false + thr = Thread.new do + Thread.pass until @o.instance_variable_get(:@write_data) + @w_io.write "rb_io_wait_readable" end - it "can be interrupted" do - start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @o.rb_io_maybe_wait_readable(Errno::EAGAIN::Errno, @r_io, IO::READABLE, true).should == IO::READABLE + @o.instance_variable_get(:@read_data).should == "rb_io_wait_re" - t = Thread.new do - @o.rb_io_maybe_wait_readable(0, @r_io, 10, false) - end + thr.join + end - Thread.pass until t.stop? - t.kill - t.join + it "can be interrupted" do + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) - finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) - (finish - start).should < 9 + t = Thread.new do + @o.rb_io_maybe_wait_readable(0, @r_io, 10, false) end - it "raises an IOError if the IO is closed" do - @r_io.close - -> { @o.rb_io_maybe_wait_readable(0, @r_io, nil, false) }.should raise_error(IOError, "closed stream") - end + Thread.pass until t.stop? + t.kill + t.join - it "raises an IOError if the IO is not initialized" do - -> { @o.rb_io_maybe_wait_readable(0, IO.allocate, nil, false) }.should raise_error(IOError, "uninitialized stream") - end + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + end + + it "raises an IOError if the IO is closed" do + @r_io.close + -> { @o.rb_io_maybe_wait_readable(0, @r_io, nil, false) }.should raise_error(IOError, "closed stream") + end + + it "raises an IOError if the IO is not initialized" do + -> { @o.rb_io_maybe_wait_readable(0, IO.allocate, nil, false) }.should raise_error(IOError, "uninitialized stream") end end end @@ -437,66 +433,64 @@ end end - ruby_version_is "3.1" do - describe "rb_io_maybe_wait" do - it "waits til an fd is ready for reading" do - start = false - thr = Thread.new do - start = true - sleep 0.05 - @w_io.write "rb_io_maybe_wait" - end - - Thread.pass until start - - @o.rb_io_maybe_wait(Errno::EAGAIN::Errno, @r_io, IO::READABLE, nil).should == IO::READABLE - - thr.join + describe "rb_io_maybe_wait" do + it "waits til an fd is ready for reading" do + start = false + thr = Thread.new do + start = true + sleep 0.05 + @w_io.write "rb_io_maybe_wait" end - it "returns mask for events if operation was interrupted" do - @o.rb_io_maybe_wait(Errno::EINTR::Errno, @w_io, IO::WRITABLE, nil).should == IO::WRITABLE - end + Thread.pass until start - it "raises an IOError if the IO is closed" do - @w_io.close - -> { @o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, nil) }.should raise_error(IOError, "closed stream") - end + @o.rb_io_maybe_wait(Errno::EAGAIN::Errno, @r_io, IO::READABLE, nil).should == IO::READABLE - it "raises an IOError if the IO is not initialized" do - -> { @o.rb_io_maybe_wait(0, IO.allocate, IO::WRITABLE, nil) }.should raise_error(IOError, "uninitialized stream") - end + thr.join + end - it "can be interrupted when waiting for READABLE event" do - start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + it "returns mask for events if operation was interrupted" do + @o.rb_io_maybe_wait(Errno::EINTR::Errno, @w_io, IO::WRITABLE, nil).should == IO::WRITABLE + end - t = Thread.new do - @o.rb_io_maybe_wait(0, @r_io, IO::READABLE, 10) - end + it "raises an IOError if the IO is closed" do + @w_io.close + -> { @o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, nil) }.should raise_error(IOError, "closed stream") + end - Thread.pass until t.stop? - t.kill - t.join + it "raises an IOError if the IO is not initialized" do + -> { @o.rb_io_maybe_wait(0, IO.allocate, IO::WRITABLE, nil) }.should raise_error(IOError, "uninitialized stream") + end - finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) - (finish - start).should < 9 + it "can be interrupted when waiting for READABLE event" do + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + t = Thread.new do + @o.rb_io_maybe_wait(0, @r_io, IO::READABLE, 10) end - it "can be interrupted when waiting for WRITABLE event" do - IOSpec.exhaust_write_buffer(@w_io) - start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + Thread.pass until t.stop? + t.kill + t.join - t = Thread.new do - @o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, 10) - end + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 + end - Thread.pass until t.stop? - t.kill - t.join + it "can be interrupted when waiting for WRITABLE event" do + IOSpec.exhaust_write_buffer(@w_io) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) - finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) - (finish - start).should < 9 + t = Thread.new do + @o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, 10) end + + Thread.pass until t.stop? + t.kill + t.join + + finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (finish - start).should < 9 end end