Skip to content
A teachable object for Pharo
Smalltalk HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.project
README.md

README.md

Pharo-Teachable

A teachable object for Pharo.

Intro

Using the small project you can easily create objects responding to specific messages. This is useful for mocking in unit tests and other. The code goes back to an early idea of Ernest Micklei with an implementation for Pharo by Torsten Bergmann (astares).

Quick Start

Metacello new 
	repository: 'github://astares/Pharo-Teachable/src';
	baseline: 'Teachable';
	load 	

Documentation

It's an implementation of a Teachable class who's instances can be taught to respond to messages. It's usefull for creating mocks who should behave like other objects (for instance inside of a test case) without actually implementing a real mock class. Here is an example how it can be used:

|teachable|
teachable := Teachable new.
teachable
    whenSend: #help return: 'ok';
    whenSend: #doit evaluate: [1 inspect];
    acceptSend: #noDebugger;
    whenSend: #negate: evaluate: [:num | num negated].

After teaching the object we can use it as if it had a normal implementation in a class:

teachable help. "this will return the string 'ok'"
teachable doit. "this will open the inspector on the SmallInteger 1"
teachable noDebugger. "this will accept the send of #noDebugger and return the teachable"
teachable negate: 120 "this will return -120"

see https://astares.blogspot.com/2005/04/teaching-behavior.html

Video

Watch the video

You can’t perform that action at this time.