I recently added support for several introspection methods to the DoubleAgents test double library for VisualWorks Smalltalk.
While there are often better solutions, Smalltalk provides several methods for introspecting the class of an object or the inheritance hierarchy of a class. These methods include
#isMemberOf: for instances and
#isDirectSubclassOf: for classes.
Up until now, the DoubleAgents library didn’t do anything special with these methods. That would have been OK, but because of some internal implementation details it didn’t even allow mocking or stubbing
#isMemberOf: at all.
I ran into a situation where it made sense to use
isKindOf:. I wanted to be able to test the code using DoubleAgents, but found I was unable to.
I decided to make some changes to DoubleAgents to support these methods.
DoubleAgents has two kinds of test doubles:
Standalone doubles completely replace a collaborator.
In-place doubles (also known as partial doubles) are “normal” objects that have one or more methods replaced by a mock or a stub for a given test. In-place doubles can be instance-side doubles, class-side doubles, or “any instance” doubles.
With the latest changes to DoubleAgents:
All in-place doubles now respond properly to
#isMemberOf:by default. Since they are partial doubles, they should act like the original object or class they are doubling unless told to do otherwise by mocking or stubbing a method.
In-place class doubles also respond properly to
Standalone doubles DO NOT pretend to be
#isMemberOf:the class they are doubling. Standalone doubles only respond to messages that are explicitly mocked or stubbed.
It is now possible for any kind of double (in-place or standalone) to stub or mock these introspection messages. Previously, it was not possible to mock or stub
The latest version has also been included as a contributed package in the about-to-be-released VisualWorks Smalltalk 8.3.1.