@@ -83,4 +83,63 @@ class << self
83
83
end
84
84
ScratchPad . recorded . should == [ :singleton_method_added , :new_method_with_define_method ]
85
85
end
86
+
87
+ describe "when singleton_method_added is undefined" do
88
+ it "raises NoMethodError for a metaclass" do
89
+ class BasicObjectSpecs ::NoSingletonMethodAdded
90
+ class << self
91
+ undef_method :singleton_method_added
92
+ end
93
+
94
+ -> {
95
+ def self . foo
96
+ end
97
+ } . should raise_error ( NoMethodError , /undefined method `singleton_method_added' for/ )
98
+ end
99
+ end
100
+
101
+ it "raises NoMethodError for a singleton instance" do
102
+ object = Object . new
103
+ class << object
104
+ undef_method :singleton_method_added
105
+
106
+ -> {
107
+ def foo
108
+ end
109
+ } . should raise_error ( NoMethodError , /undefined method `singleton_method_added' for #<Object:/ )
110
+
111
+ -> {
112
+ define_method ( :bar ) { }
113
+ } . should raise_error ( NoMethodError , /undefined method `singleton_method_added' for #<Object:/ )
114
+ end
115
+
116
+ -> {
117
+ object . define_singleton_method ( :baz ) { }
118
+ } . should raise_error ( NoMethodError , /undefined method `singleton_method_added' for #<Object:/ )
119
+ end
120
+
121
+ it "calls #method_missing" do
122
+ ScratchPad . record [ ]
123
+ object = Object . new
124
+ class << object
125
+ def method_missing ( *args )
126
+ ScratchPad << args
127
+ end
128
+
129
+ undef_method :singleton_method_added
130
+
131
+ def foo
132
+ end
133
+
134
+ define_method ( :bar ) { }
135
+ end
136
+ object . define_singleton_method ( :baz ) { }
137
+
138
+ ScratchPad . recorded . should == [
139
+ [ :singleton_method_added , :foo ] ,
140
+ [ :singleton_method_added , :bar ] ,
141
+ [ :singleton_method_added , :baz ] ,
142
+ ]
143
+ end
144
+ end
86
145
end
0 commit comments