From 0e705fd54a4bd2d8cfc823cd8a9ca0d16accd873 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Thu, 8 Jan 2026 18:06:48 +0200 Subject: [PATCH 1/5] Polish specs for Range#to_set --- core/range/to_set_spec.rb | 51 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/core/range/to_set_spec.rb b/core/range/to_set_spec.rb index a57767c64..14e0ce1e3 100644 --- a/core/range/to_set_spec.rb +++ b/core/range/to_set_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require_relative '../enumerable/fixtures/classes' -describe "Enumerable#to_set" do +describe "Range#to_set" do it "returns a new Set created from self" do (1..4).to_set.should == Set[1, 2, 3, 4] (1...4).to_set.should == Set[1, 2, 3] @@ -11,37 +11,44 @@ (1..3).to_set { |x| x * x }.should == Set[1, 4, 9] end + it "raises a TypeError for a beginningless range" do + -> { + (..0).to_set + }.should raise_error(TypeError, "can't iterate from NilClass") + end + ruby_version_is "4.0" do - it "raises a RangeError if the range is infinite" do + it "raises a RangeError if the range is endless" do -> { (1..).to_set }.should raise_error(RangeError, "cannot convert endless range to a set") -> { (1...).to_set }.should raise_error(RangeError, "cannot convert endless range to a set") end end - ruby_version_is ""..."4.0" do - it "instantiates an object of provided as the first argument set class" do - set = (1..3).to_set(EnumerableSpecs::SetSubclass) - set.should be_kind_of(EnumerableSpecs::SetSubclass) - set.to_a.sort.should == [1, 2, 3] + context "given positional arguments" do + ruby_version_is ""..."4.0" do + it "instantiates an object of provided as the first argument set class" do + set = (1..3).to_set(EnumerableSpecs::SetSubclass) + set.should be_kind_of(EnumerableSpecs::SetSubclass) + set.to_a.sort.should == [1, 2, 3] + end end - end - ruby_version_is "4.0"..."4.1" do - it "instantiates an object of provided as the first argument set class and warns" do - set = nil - proc { - set = (1..3).to_set(EnumerableSpecs::SetSubclass) - }.should complain(/Enumerable#to_set/) - set.should be_kind_of(EnumerableSpecs::SetSubclass) - set.to_a.sort.should == [1, 2, 3] + ruby_version_is "4.0"..."4.1" do + it "instantiates an object of provided as the first argument set class and warns" do + -> { + set = (1..3).to_set(EnumerableSpecs::SetSubclass) + set.should be_kind_of(EnumerableSpecs::SetSubclass) + set.to_a.sort.should == [1, 2, 3] + }.should complain(/warning: passing arguments to Enumerable#to_set is deprecated/) + end end - end - ruby_version_is "4.1" do - it "does not accept any positional argument" do - -> { - (1..3).to_set(EnumerableSpecs::SetSubclass) - }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 0)') + ruby_version_is "4.1" do + it "does not accept any positional argument" do + -> { + (1..3).to_set(EnumerableSpecs::SetSubclass) + }.should raise_error(ArgumentError, "wrong number of arguments (given 1, expected 0)") + end end end end From de95d27218a1b3813069b903d7a4e49973bef7d0 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Thu, 8 Jan 2026 18:19:17 +0200 Subject: [PATCH 2/5] Polish core/builtin_constants/builtin_constants_spec.rb and remove a questionable context section --- .../builtin_constants_spec.rb | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/core/builtin_constants/builtin_constants_spec.rb b/core/builtin_constants/builtin_constants_spec.rb index 13e066cc7..2c71b4166 100644 --- a/core/builtin_constants/builtin_constants_spec.rb +++ b/core/builtin_constants/builtin_constants_spec.rb @@ -87,65 +87,63 @@ end ruby_version_is "4.0" do - context "The constant" do - describe "Ruby" do - it "is a Module" do - Ruby.should.instance_of?(Module) - end + describe "Ruby" do + it "is a Module" do + Ruby.should.instance_of?(Module) end + end - describe "Ruby::VERSION" do - it "is equal to RUBY_VERSION" do - Ruby::VERSION.should equal(RUBY_VERSION) - end + describe "Ruby::VERSION" do + it "is equal to RUBY_VERSION" do + Ruby::VERSION.should equal(RUBY_VERSION) end + end - describe "RUBY::PATCHLEVEL" do - it "is equal to RUBY_PATCHLEVEL" do - Ruby::PATCHLEVEL.should equal(RUBY_PATCHLEVEL) - end + describe "RUBY::PATCHLEVEL" do + it "is equal to RUBY_PATCHLEVEL" do + Ruby::PATCHLEVEL.should equal(RUBY_PATCHLEVEL) end + end - describe "Ruby::COPYRIGHT" do - it "is equal to RUBY_COPYRIGHT" do - Ruby::COPYRIGHT.should equal(RUBY_COPYRIGHT) - end + describe "Ruby::COPYRIGHT" do + it "is equal to RUBY_COPYRIGHT" do + Ruby::COPYRIGHT.should equal(RUBY_COPYRIGHT) end + end - describe "Ruby::DESCRIPTION" do - it "is equal to RUBY_DESCRIPTION" do - Ruby::DESCRIPTION.should equal(RUBY_DESCRIPTION) - end + describe "Ruby::DESCRIPTION" do + it "is equal to RUBY_DESCRIPTION" do + Ruby::DESCRIPTION.should equal(RUBY_DESCRIPTION) end + end - describe "Ruby::ENGINE" do - it "is equal to RUBY_ENGINE" do - Ruby::ENGINE.should equal(RUBY_ENGINE) - end + describe "Ruby::ENGINE" do + it "is equal to RUBY_ENGINE" do + Ruby::ENGINE.should equal(RUBY_ENGINE) end + end - describe "Ruby::ENGINE_VERSION" do - it "is equal to RUBY_ENGINE_VERSION" do - Ruby::ENGINE_VERSION.should equal(RUBY_ENGINE_VERSION) - end + describe "Ruby::ENGINE_VERSION" do + it "is equal to RUBY_ENGINE_VERSION" do + Ruby::ENGINE_VERSION.should equal(RUBY_ENGINE_VERSION) end + end - describe "Ruby::PLATFORM" do - it "is equal to RUBY_PLATFORM" do - Ruby::PLATFORM.should equal(RUBY_PLATFORM) - end + describe "Ruby::PLATFORM" do + it "is equal to RUBY_PLATFORM" do + Ruby::PLATFORM.should equal(RUBY_PLATFORM) end + end - describe "Ruby::RELEASE_DATE" do - it "is equal to RUBY_RELEASE_DATE" do - Ruby::RELEASE_DATE.should equal(RUBY_RELEASE_DATE) - end + describe "Ruby::RELEASE_DATE" do + it "is equal to RUBY_RELEASE_DATE" do + Ruby::RELEASE_DATE.should equal(RUBY_RELEASE_DATE) end + end - describe "Ruby::REVISION" do - it "is equal to RUBY_REVISION" do - Ruby::REVISION.should equal(RUBY_REVISION) - end + describe "Ruby::REVISION" do + it "is equal to RUBY_REVISION" do + Ruby::REVISION.should equal(RUBY_REVISION) end end end From 290f03b6185bfa4749b452844954f4ec494a2102 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 10 Jan 2026 17:47:12 +0200 Subject: [PATCH 3/5] Improve specs for it parameter in language/block_spec.rb --- language/block_spec.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/language/block_spec.rb b/language/block_spec.rb index cc003b894..54e511548 100644 --- a/language/block_spec.rb +++ b/language/block_spec.rb @@ -1106,12 +1106,18 @@ def o.it eval("proc { it * 2 }").call(5).should == 10 end + it "acts as the first argument if multiple arguments given" do + eval("proc { it * 2 }").call(5, 1, 2, 3).should == 10 + end + it "can be reassigned to act as a local variable" do eval("proc { tmp = it; it = tmp * 2; it }").call(21).should == 42 end it "can be used in nested calls" do - eval("proc { it.map { it * 2 } }").call([1, 2, 3]).should == [2, 4, 6] + it_values = [] + eval("proc { it.each { it_values << it } }").call([1, 2, 3]) + it_values.should == [1, 2, 3] end it "cannot be mixed with numbered parameters" do @@ -1123,6 +1129,21 @@ def o.it eval "proc { _1 + it }" }.should raise_error(SyntaxError, /numbered parameter is already used in|'it' is not allowed when a numbered parameter is already used/) end + + it "is available before re-assigning" do + a = nil + proc { a = it; it = 42 }.call(0) + a.should == 0 + end + + it "does not call the method `it` if defined" do + o = Object.new + def o.it + 21 + end + + o.instance_eval("proc { it * 2 }").call(1).should == 2 + end end end From 913d92f45b0528a462b5019d7ee05d1d255ef5e7 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 10 Jan 2026 18:11:01 +0200 Subject: [PATCH 4/5] Move it parameter related specs from language/block_spec.rb to language/it_parameter_spec.rb --- language/block_spec.rb | 56 +++-------------------------------- language/it_parameter_spec.rb | 44 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 54 deletions(-) diff --git a/language/block_spec.rb b/language/block_spec.rb index 54e511548..c8cffb62f 100644 --- a/language/block_spec.rb +++ b/language/block_spec.rb @@ -1041,7 +1041,7 @@ def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, ** end end -describe "`it` calls without arguments in a block with no ordinary parameters" do +describe "`it` calls without arguments in a block" do ruby_version_is "3.3"..."3.4" do it "emits a deprecation warning" do -> { @@ -1094,59 +1094,11 @@ def o.it end end end - - ruby_version_is "3.4" do - it "does not emit a deprecation warning" do - -> { - eval "proc { it }" - }.should_not complain - end - - it "acts as the first argument if no local variables exist" do - eval("proc { it * 2 }").call(5).should == 10 - end - - it "acts as the first argument if multiple arguments given" do - eval("proc { it * 2 }").call(5, 1, 2, 3).should == 10 - end - - it "can be reassigned to act as a local variable" do - eval("proc { tmp = it; it = tmp * 2; it }").call(21).should == 42 - end - - it "can be used in nested calls" do - it_values = [] - eval("proc { it.each { it_values << it } }").call([1, 2, 3]) - it_values.should == [1, 2, 3] - end - - it "cannot be mixed with numbered parameters" do - -> { - eval "proc { it + _1 }" - }.should raise_error(SyntaxError, /numbered parameters are not allowed when 'it' is already used|'it' is already used in/) - - -> { - eval "proc { _1 + it }" - }.should raise_error(SyntaxError, /numbered parameter is already used in|'it' is not allowed when a numbered parameter is already used/) - end - - it "is available before re-assigning" do - a = nil - proc { a = it; it = 42 }.call(0) - a.should == 0 - end - - it "does not call the method `it` if defined" do - o = Object.new - def o.it - 21 - end - - o.instance_eval("proc { it * 2 }").call(1).should == 2 - end - end end +# Duplicates specs in language/it_parameter_spec.rb +# Need them here to run on Ruby versions prior 3.4 +# TODO: remove when the minimal supported Ruby version is 3.4 describe "if `it` is defined as a variable" do it "treats `it` as a captured variable if defined outside of a block" do it = 5 diff --git a/language/it_parameter_spec.rb b/language/it_parameter_spec.rb index 72023180d..c27e8344a 100644 --- a/language/it_parameter_spec.rb +++ b/language/it_parameter_spec.rb @@ -17,9 +17,28 @@ -> { it + -> { it * it }.call(2) }.call(3).should == 7 end + it "can be reassigned to act as a local variable" do + proc { tmp = it; it = tmp * 2; it }.call(21).should == 42 + end + it "is a regular local variable if there is already a 'it' local variable" do - it = 0 - proc { it }.call("a").should == 0 + it = 0 + proc { it }.call("a").should == 0 + end + + it "is a regular local variable if there is a method `it` defined" do + o = Object.new + def o.it + 21 + end + + o.instance_eval("proc { it * 2 }").call(1).should == 2 + end + + it "is not shadowed by an reassignment in a block" do + a = nil + proc { a = it; it = 42 }.call(0) + a.should == 0 # if `it` were shadowed its value would be nil end it "raises SyntaxError when block parameters are specified explicitly" do @@ -36,6 +55,16 @@ -> { eval("['a'].map { |x| it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/) end + it "cannot be mixed with numbered parameters" do + -> { + eval("proc { it + _1 }") + }.should raise_error(SyntaxError, /numbered parameters are not allowed when 'it' is already used|'it' is already used in/) + + -> { + eval("proc { _1 + it }") + }.should raise_error(SyntaxError, /numbered parameter is already used in|'it' is not allowed when a numbered parameter is already used/) + end + it "affects block arity" do -> {}.arity.should == 0 -> { it }.arity.should == 1 @@ -62,5 +91,16 @@ def obj.foo; it; end -> { obj.foo("a") }.should raise_error(ArgumentError, /wrong number of arguments/) end + + context "given multiple arguments" do + it "provides it in a block and assigns the first argument for a block" do + proc { it }.call("a", "b").should == "a" + end + + it "raises ArgumentError for a proc" do + -> { -> { it }.call("a", "b") }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)") + -> { lambda { it }.call("a", "b") }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)") + end + end end end From f7afa48ec52a96dca146150c76b385c8b8ee2818 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sat, 10 Jan 2026 18:25:23 +0200 Subject: [PATCH 5/5] Polish spec titles in library/socket/addrinfo/initialize_spec.rb --- library/socket/addrinfo/initialize_spec.rb | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/library/socket/addrinfo/initialize_spec.rb b/library/socket/addrinfo/initialize_spec.rb index 1f16531aa..c556bd758 100644 --- a/library/socket/addrinfo/initialize_spec.rb +++ b/library/socket/addrinfo/initialize_spec.rb @@ -53,11 +53,11 @@ @addrinfo.ip_port.should == 25 end - it "returns the INET6 pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET6 end @@ -83,11 +83,11 @@ @addrinfo.ip_port.should == 25 end - it "returns the INET6 pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET6 end @@ -113,11 +113,11 @@ @addrinfo.ip_port.should == 25 end - it "returns the INET6 pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET6 end - it "returns the INET6 afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET6 end @@ -147,11 +147,11 @@ @addrinfo.ip_port.should == 46102 end - it "returns the INET pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET end @@ -217,11 +217,11 @@ @addrinfo.ip_port.should == 46102 end - it "returns the INET pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET end @@ -247,11 +247,11 @@ @addrinfo.ip_port.should == 46102 end - it "returns the INET pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET end @@ -311,11 +311,11 @@ @addrinfo.ip_port.should == 46102 end - it "returns the INET pfamily" do + it "returns the specified family" do @addrinfo.pfamily.should == Socket::PF_INET end - it "returns the INET afamily" do + it "returns the specified family" do @addrinfo.afamily.should == Socket::AF_INET end @@ -514,13 +514,13 @@ @sockaddr = Socket.sockaddr_in(80, '127.0.0.1') end - it 'returns an Addrinfo with :PF_INET family' do + it 'returns an Addrinfo with the specified family' do addr = Addrinfo.new(@sockaddr, :PF_INET) addr.pfamily.should == Socket::PF_INET end - it 'returns an Addrinfo with :INET family' do + it 'returns an Addrinfo with the specified family' do addr = Addrinfo.new(@sockaddr, :INET) addr.pfamily.should == Socket::PF_INET @@ -544,13 +544,13 @@ @sockaddr = Socket.sockaddr_in(80, '127.0.0.1') end - it 'returns an Addrinfo with "PF_INET" family' do + it 'returns an Addrinfo with the specified family' do addr = Addrinfo.new(@sockaddr, 'PF_INET') addr.pfamily.should == Socket::PF_INET end - it 'returns an Addrinfo with "INET" family' do + it 'returns an Addrinfo with the specified family' do addr = Addrinfo.new(@sockaddr, 'INET') addr.pfamily.should == Socket::PF_INET