diff --git a/core/main/private_spec.rb b/core/main/private_spec.rb index 78c5d287d4..cac0645b40 100644 --- a/core/main/private_spec.rb +++ b/core/main/private_spec.rb @@ -32,8 +32,16 @@ end end - it "returns Object" do - eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object) + 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 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 bfc27a9e80..91f045dbab 100644 --- a/core/main/public_spec.rb +++ b/core/main/public_spec.rb @@ -32,10 +32,19 @@ end end - it "returns Object" do - eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object) + 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 + end + + it "raises a NameError when given an undefined name" do -> do eval "public :main_undefined_method", TOPLEVEL_BINDING diff --git a/core/module/module_function_spec.rb b/core/module/module_function_spec.rb index 407237d48f..0602e95ca9 100644 --- a/core/module/module_function_spec.rb +++ b/core/module/module_function_spec.rb @@ -38,14 +38,23 @@ def test3() end m.respond_to?(:test3).should == false end - it "returns the current module" do - x = nil - m = Module.new do - def test() end - x = module_function :test + 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 - x.should == m + 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 + end end it "creates an independent copy of the method, not a redirect" do @@ -160,13 +169,20 @@ def test2() end m.respond_to?(:test2).should == true end - it "returns the current module" do - x = nil - m = Module.new { - x = module_function - } + ruby_version_is ""..."3.1" do + it "returns self" do + Module.new do + module_function.should equal(self) + end + end + end - x.should == m + ruby_version_is "3.1" do + it "returns nil" do + Module.new do + module_function.should equal(nil) + end + end end it "stops creating module functions if the body encounters another toggle " \ diff --git a/core/module/private_spec.rb b/core/module/private_spec.rb index e893c24f38..ead806637c 100644 --- a/core/module/private_spec.rb +++ b/core/module/private_spec.rb @@ -38,11 +38,25 @@ class << obj :module_specs_public_method_on_object_for_kernel_private) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - private(:foo).should equal(self) - private.should equal(self) + 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 end end diff --git a/core/module/protected_spec.rb b/core/module/protected_spec.rb index aa04a42fb8..058d49d751 100644 --- a/core/module/protected_spec.rb +++ b/core/module/protected_spec.rb @@ -39,11 +39,25 @@ class << ModuleSpecs::Parent :module_specs_public_method_on_object_for_kernel_protected) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - protected(:foo).should equal(self) - protected.should equal(self) + 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 end end diff --git a/core/module/public_spec.rb b/core/module/public_spec.rb index e7059f6aa6..e3b183f228 100644 --- a/core/module/public_spec.rb +++ b/core/module/public_spec.rb @@ -27,12 +27,25 @@ :module_specs_private_method_on_object_for_kernel_public) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - private :foo - public(:foo).should equal(self) - public.should equal(self) + 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 end end