[GOODIE] Teachable Object
Torsten.Bergmann at phaidros.com
Torsten.Bergmann at phaidros.com
Thu Apr 18 07:55:48 UTC 2002
Attached is a squeak port of Ernest Micklei's VW code for
a teachable object. You can teach these objects how to respond
to messages. It's usefull for creating mocks who should behave
like other objects (for instance inside of a test case).
examples:
| teachable |
teachable := Teachable new.
teachable
whenSend: #help return: 'ok';
whenSend: #doit evaluate: [1 inspect];
acceptSend: #noDebugger;
whenSend: #negate: evaluate: [:num | num negated].
teachable help.
teachable doit.
teachable noDebugger.
teachable negate: 120
use inside of a test (we mock a web page without an internet
connection):
testParsing
| testObject teachable |
teachable := Teachable new.
teachable
whenSend: #class return: Webpage;
whenSend: #url return: 'www.test.com';
whenSend: #contents return: '<HTML></HTML>'.
testObject := HTMLParser onPage: teachable.
self assert: testObject validHTML
Have fun
Torsten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Teachable.1.cs
Type: application/octet-stream
Size: 1509 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020418/89059bf3/Teachable.1.obj
More information about the Squeak-dev
mailing list
|