Skip to content

Commit a1e95f9

Browse files
committed
Improve Module#undef_method spec to check the message and module name
1 parent a2db171 commit a1e95f9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

spec/ruby/core/module/undef_method_spec.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,36 @@ def another_method_to_undef() 1 end
5757
end
5858

5959
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|
6161
# a NameError and not a NoMethodError
6262
e.class.should == NameError
6363
}
6464
end
6565

6666
it "raises a NameError when passed a missing name for a class" do
6767
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|
6990
# a NameError and not a NoMethodError
7091
e.class.should == NameError
7192
}

0 commit comments

Comments
 (0)