Testing instance methods in a Module with Object.extend()
A common type of mixin I’ve encountered involves a Module with instance methods which is included into a Class.
Writing an orthogonal test for a target Class is easy enough, you simply mock/stub any methods the Module provides.
Testing the Module elegantly however is less obvious, atleast it wasn’t obvious to me.
One approach I’ve used is to create a fake class for the test, include the Module and finally instantiate this for the test. But there’s the issue of testing the Module’s interaction with the including Class. For this you could partially mock/stub the test class instance, but there’s a simpler approach that avoids the test class altogether: create an ordinary rSpec mock instance and extend it with the Module.