From 786a864900ceee6ed89d7df81698bbbe7e7bd6ae Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 22 Jun 2023 09:44:51 -0700 Subject: Make {Nil,True,False}Class#singleton_method always raise NameError {Nil,True,False}Class#singleton_methods always returns [] indicating that there are no singleton methods defined, so #singleton_method should be consistent with that. Fixes [Bug #11064] --- spec/ruby/core/false/singleton_method_spec.rb | 15 +++++++++++++++ spec/ruby/core/nil/singleton_method_spec.rb | 15 +++++++++++++++ spec/ruby/core/true/singleton_method_spec.rb | 15 +++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 spec/ruby/core/false/singleton_method_spec.rb create mode 100644 spec/ruby/core/nil/singleton_method_spec.rb create mode 100644 spec/ruby/core/true/singleton_method_spec.rb (limited to 'spec/ruby') diff --git a/spec/ruby/core/false/singleton_method_spec.rb b/spec/ruby/core/false/singleton_method_spec.rb new file mode 100644 index 0000000000..6cf29af411 --- /dev/null +++ b/spec/ruby/core/false/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "FalseClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether FalseClass defines the method" do + proc{false.singleton_method(:foo)}.should raise_error(NameError) + begin + def false.foo; end + proc{false.singleton_method(:foo)}.should raise_error(NameError) + ensure + FalseClass.send(:remove_method, :foo) + end + end + end +end diff --git a/spec/ruby/core/nil/singleton_method_spec.rb b/spec/ruby/core/nil/singleton_method_spec.rb new file mode 100644 index 0000000000..f9163da3f1 --- /dev/null +++ b/spec/ruby/core/nil/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "NilClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether NilClass defines the method" do + proc{nil.singleton_method(:foo)}.should raise_error(NameError) + begin + def nil.foo; end + proc{nil.singleton_method(:foo)}.should raise_error(NameError) + ensure + NilClass.send(:remove_method, :foo) + end + end + end +end diff --git a/spec/ruby/core/true/singleton_method_spec.rb b/spec/ruby/core/true/singleton_method_spec.rb new file mode 100644 index 0000000000..f765054c5f --- /dev/null +++ b/spec/ruby/core/true/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "TrueClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether TrueClass defines the method" do + proc{true.singleton_method(:foo)}.should raise_error(NameError) + begin + def true.foo; end + proc{true.singleton_method(:foo)}.should raise_error(NameError) + ensure + TrueClass.send(:remove_method, :foo) + end + end + end +end -- cgit v1.2.3