[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).

	| teachable |
	teachable := Teachable new.
		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

        | testObject teachable |
        teachable := Teachable new.
                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

-------------- 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