This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -139,8 +139,11 @@ def method_owned_by_klass?
139
139
# The owner of M.b is the raw Module object, instead of the expected
140
140
# singleton class of the module
141
141
return true if RUBY_VERSION < '1.9' && owner == @object
142
+
142
143
owner == @klass ||
143
- owner . singleton_class == @klass || # When `extend self` is used
144
+ # When `extend self` is used, and not under any instance of
145
+ ( owner . singleton_class == @klass &&
146
+ !Mocks . space . any_instance_recorder_for ( owner , true ) ) ||
144
147
!( method_defined_on_klass? ( owner ) )
145
148
end
146
149
end
Original file line number Diff line number Diff line change @@ -363,6 +363,21 @@ class << self; public :hello; end;
363
363
expect ( mod . hello ) . to eq ( :hello )
364
364
end
365
365
366
+ it "correctly restores from allow_any_instance_of for self extend" do
367
+ mod = Module . new {
368
+ extend self
369
+ def hello ; :hello ; end
370
+ }
371
+
372
+ allow_any_instance_of ( mod ) . to receive ( :hello ) { :stub }
373
+
374
+ expect ( mod . hello ) . to eq ( :stub )
375
+
376
+ reset_all
377
+
378
+ expect ( mod . hello ) . to eq ( :hello )
379
+ end
380
+
366
381
it "correctly handles stubbing inherited mixed in class methods" do
367
382
mod = Module . new do
368
383
def method_a
You can’t perform that action at this time.
0 commit comments