smalltalkpharosqueakpharo-5

Pharo Smalltalk test failure because message not understood


I am starting to learn Smalltalk, using Pharo 5. I am now following a tutorial from the squeak guys to get some proper grip on the syntax, etc.

I am in the beginning, I have only two classes (a class BlankCell and a BlanCellTestCase class for the unit test). The Blankcell has some messages implemented already, I am at the very end of section 1.9.

The beahavior is well implemented, because on the playground:

| cell exit |
cell := BlankCell new.
exit := cell exitSideFor: #north.
exit = #south
"the last statement properly returns a true or false"

On the testcase there are three tests, only one fails (related to the exitSide):

testCellExitSides
   "Test the exit sides."
    | cell exit |
    cell := BlankCell new.
    exit := cell exitSideFor: #north.
    self assert: [ exit = #south ].
    exit := cell exitSideFor: #east. 
    self assert: [ exit = #west ].
    exit := cell exitSideFor: #south.
    self assert: [ exit = #north ].
    exit := cell exitSideFor: #west.
    self assert: [ exit = #east ].

The error message is

MessageNotUnderstood:BlockClosure>>ifFalse:

The doesNotUnderstand message is sent an argument pointing to the sentence [ exit = #south ]

Does anyone understand what may be going on here?


Solution

  • TestCase>>assert: expects a boolean, not a block.

    So

    self assert: [ exit = #south ].

    should be written as

    self assert: exit = #south

    For string comparisons the preferable way is to use the following:

    self assert: exit equals: #south

    Because that way you will a see diff of the strings and just a boolean failure.


    BUT

    Object>>assert: expects a block, not a boolean.

    However you would use this assert inside your regular code, not for code testing.