@@ -57,15 +57,36 @@ def another_method_to_undef() 1 end
57
57
end
58
58
59
59
it "raises a NameError when passed a missing name for a module" do
60
- -> { @module . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for module/ ) { |e |
60
+ -> { @module . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for module ` #{ @module } ' / ) { |e |
61
61
# a NameError and not a NoMethodError
62
62
e . class . should == NameError
63
63
}
64
64
end
65
65
66
66
it "raises a NameError when passed a missing name for a class" do
67
67
klass = Class . new
68
- -> { klass . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for class/ ) { |e |
68
+ -> { klass . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for class `#{ klass } '/ ) { |e |
69
+ # a NameError and not a NoMethodError
70
+ e . class . should == NameError
71
+ }
72
+ end
73
+
74
+ it "raises a NameError when passed a missing name for a singleton class" do
75
+ klass = Class . new
76
+ obj = klass . new
77
+ sclass = obj . singleton_class
78
+
79
+ -> { sclass . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for class `#{ sclass } '/ ) { |e |
80
+ e . message . should include ( '`#<Class:#<#<Class:' )
81
+
82
+ # a NameError and not a NoMethodError
83
+ e . class . should == NameError
84
+ }
85
+ end
86
+
87
+ it "raises a NameError when passed a missing name for a metaclass" do
88
+ klass = String . singleton_class
89
+ -> { klass . send :undef_method , :not_exist } . should raise_error ( NameError , /undefined method `not_exist' for class `String'/ ) { |e |
69
90
# a NameError and not a NoMethodError
70
91
e . class . should == NameError
71
92
}
0 commit comments