2

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?

rll
  • 5,509
  • 3
  • 31
  • 46

1 Answers1

6

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.

Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
  • Thanks, the tutorial actually uses the message `should:` which expects a block. The compiler suggested using assert instead and I did not notice that difference in the argument. – rll Apr 19 '17 at 21:33
  • `#south` is a ByteObject and as such does not implement the `equals:` message. (or does this depend on the ST implementation?). – rll Apr 19 '17 at 21:34
  • @rll `#south` is a `Symbol`; but why would it need understand `equals:` message? The whole message is `assert:equals:` (with two arguments) – Peter Uhnak Apr 19 '17 at 22:18
  • Ok, I was looking at it as two messages, hence the confusion. – rll Apr 19 '17 at 22:53