summaryrefslogtreecommitdiff
path: root/spec/ruby/core/basicobject
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-02-27 13:00:26 +0100
committerBenoit Daloze <eregontp@gmail.com>2021-02-27 13:00:26 +0100
commit36dde35e029c7a6607e6c674062ce6fc7a51c0bd (patch)
tree47f9c820a93d5b9a68f7e903cc01ee607913e2dd /spec/ruby/core/basicobject
parentdbea0be13dc1f44833eca43a73f3ab898fa27c15 (diff)
Update to ruby/spec@37e52e5
Diffstat (limited to 'spec/ruby/core/basicobject')
-rw-r--r--spec/ruby/core/basicobject/singleton_method_added_spec.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/ruby/core/basicobject/singleton_method_added_spec.rb b/spec/ruby/core/basicobject/singleton_method_added_spec.rb
index 8d256e22db..ab6b2a2d10 100644
--- a/spec/ruby/core/basicobject/singleton_method_added_spec.rb
+++ b/spec/ruby/core/basicobject/singleton_method_added_spec.rb
@@ -83,4 +83,63 @@ describe "BasicObject#singleton_method_added" do
end
ScratchPad.recorded.should == [:singleton_method_added, :new_method_with_define_method]
end
+
+ describe "when singleton_method_added is undefined" do
+ it "raises NoMethodError for a metaclass" do
+ class BasicObjectSpecs::NoSingletonMethodAdded
+ class << self
+ undef_method :singleton_method_added
+ end
+
+ -> {
+ def self.foo
+ end
+ }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for/)
+ end
+ end
+
+ it "raises NoMethodError for a singleton instance" do
+ object = Object.new
+ class << object
+ undef_method :singleton_method_added
+
+ -> {
+ def foo
+ end
+ }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
+
+ -> {
+ define_method(:bar) {}
+ }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
+ end
+
+ -> {
+ object.define_singleton_method(:baz) {}
+ }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
+ end
+
+ it "calls #method_missing" do
+ ScratchPad.record []
+ object = Object.new
+ class << object
+ def method_missing(*args)
+ ScratchPad << args
+ end
+
+ undef_method :singleton_method_added
+
+ def foo
+ end
+
+ define_method(:bar) {}
+ end
+ object.define_singleton_method(:baz) {}
+
+ ScratchPad.recorded.should == [
+ [:singleton_method_added, :foo],
+ [:singleton_method_added, :bar],
+ [:singleton_method_added, :baz],
+ ]
+ end
+ end
end