aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/module/undef_method_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/module/undef_method_spec.rb')
-rw-r--r--spec/ruby/core/module/undef_method_spec.rb33
1 files changed, 31 insertions, 2 deletions
diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb
index 9b2c9240f4..b101778962 100644
--- a/spec/ruby/core/module/undef_method_spec.rb
+++ b/spec/ruby/core/module/undef_method_spec.rb
@@ -56,8 +56,37 @@ describe "Module#undef_method" do
@module.send(:undef_method, :method_to_undef).should equal(@module)
end
- it "raises a NameError when passed a missing name" do
- -> { @module.send :undef_method, :not_exist }.should raise_error(NameError) { |e|
+ it "raises a NameError when passed a missing name for a module" do
+ -> { @module.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for module `#{@module}'/) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a class" do
+ klass = Class.new
+ -> { klass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for class `#{klass}'/) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a singleton class" do
+ klass = Class.new
+ obj = klass.new
+ sclass = obj.singleton_class
+
+ -> { sclass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for class `#{sclass}'/) { |e|
+ e.message.should include('`#<Class:#<#<Class:')
+
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a metaclass" do
+ klass = String.singleton_class
+ -> { klass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for class `String'/) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}