Can someone recommend a good read on how to use proxy objects in Smalltalk?
I'm trying to verify expectations about the messages that classes are receiving (as is done in rSpec, the Ruby BDD framework) and I think proxy objects may be the right pattern.
Thanks,
Chad
"cnantais" == cnantais cnantais@gmail.com writes:
cnantais> Can someone recommend a good read on how to use proxy objects in cnantais> Smalltalk?
cnantais> I'm trying to verify expectations about the messages that classes cnantais> are receiving (as is done in rSpec, the Ruby BDD framework) and I cnantais> think proxy objects may be the right pattern.
See the ObjectTracer class under "Kernel-Objects". Here's the class comment:
An ObjectTracer can be wrapped around another object, and then give you a chance to inspect it whenever it receives messages from the outside. For instance...
(ObjectTracer on: Display) flash: (50@50 extent: 50@50)
will give control to a debugger just before the message flash is sent. Obviously this facility can be embellished in many useful ways. See also the even more perverse subclass, ObjectViewer, and its example.
On Jan 11, 2008 12:19 PM, cnantais cnantais@gmail.com wrote:
Can someone recommend a good read on how to use proxy objects in Smalltalk?
I'm trying to verify expectations about the messages that classes are receiving (as is done in rSpec, the Ruby BDD framework) and I think proxy objects may be the right pattern.
Typically you'd make a subclass of ProtoObject and write a doesNotUnderstand: method that does what you want. However, this is fraught with many dangers and crashed images. Another way is to modify the virtual machine, which is the approach taken by Craig Latta's Spoon project.
Try my MessageCapture package, from http://www.squeaksource.com/DPON. It contains a MessageCapture class. I can't remember exactly how it's used, but it's something like:
m := MessageCapture captureFrom: anObject forwardTo: aReceiver.
And then you implement a reciever object which implements some method like "handleMessage: m". You'll have to read the source; it's been hours since I've touched this stuff so I can't remember what the actual methods were.
This package contains a bunch of things which make it much easier to manage these message capturing objects, such as (mostly) being able to use the debugger and inspector on them.
A message capture can't easily be stored in a dictionary, because the dictionary calls "hash" on it. As an effect of this, you can't use them in a workspace. Also, don't try using an Object Explorer on them. Sometimes alt-. may help, sometimes it won't.
Also, save your code often and keep backups.
Gulik.
beginners@lists.squeakfoundation.org