btakita/rr — pull request #70 by etiennebarrie (2011-11-02 16:34:25+00:00)
Title: any_instance_of stubs failing with class hierarchies

We’re seeing issues with the way `any_instance_of` stubs are reset.

These stubs apparently work by using on `method_missing` on the class, but the code (`RR::Injections::MethodMissingInjection#reset` line 44 called from `RR::Space#reset_method_missing_injection`) seems to be trying to remove `method_missing` even when it’s not defined on the subject class, but only on its parent class. `RR::Injections::Injection#subject_has_method_defined?` checks for all methods, even inherited ones, which then makes it fail when trying to remove the method.

Included is a failing spec showing the issue as a user of the lib. We also have a workaround that first orders the injections by `@subject_class.ancestors.size` before `reset`ting them, which ensures that the parent classes’ `method_missing`s are removed before those in inherited classes but it’s super ugly, so I’d rather not push that.