The following section describes common
scenarios during Smalltalk development, and illustrates how method spies
can be used to assist. In particular, the examples show the use of the
thisSpy pseudo variable, and the context and activationContext
dictionaries.
-
You want to
step-through a method which is being invoked repeatedly by a
background process, however placing ‘self halt’ in the method
would cause multiple walkbacks to occur. Using a method spy, it is
straightforward to interrupt only the first invocation by inserting
the following spy code at the start of the method:
thisSpy activationCount
= 1
ifTrue:
[self halt]
This scenario is quite
common and so the
following shorthand form can also be used:
thisSpy isVirgin ifTrue:
[self halt]
Following the initial
activation, the activationCount of the spy can be reset to zero via the
Reset button of the Spy Inspector.
thisSpy activationContext
at: #argument
put:
anObject
…the arguments from
each activation of the spy can then be examined in the Spy Inspector.
|