diff options
Diffstat (limited to 'spec/ruby/core/basicobject')
-rw-r--r-- | spec/ruby/core/basicobject/singleton_method_added_spec.rb | 59 |
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 |