New mock objects framework

Denis Kudriashov dionisiydk at gmail.com
Wed Sep 19 12:32:07 UTC 2007


2007/9/19, Robert Krahn <rksm at gmx.net>:
>
> Hello Denis,
>
> I dipped into your BehaviorMockup package and it seems really powerful. I
> like the block notation so that the expected behavior is stated after the
> exercised code. This way the tests can be more uniform (Four-Phase Test) and
> clearer.
>
> One thing I didn't found out is how to have the mocks ignore certain
> message calls.
> E.g. I want this to pass:
> [:mock | mock m1; m2] should lenient satisfy: [:mock | mock m1]
>
> I tried it the 'lenient way' as above but I get a SpecFailed:
> WrongMessageSelector. How can one do this?
>
> Best regards,
> Robert
>
> p.s.
> I wrote this mail to the squeak-dev mailing list first but forgot to add
> your mail address in the header so I am writing you an extra mail.
>

Hi Robert.

Expression

[:mock | mock m1; m2] should lenient satisfy: [:mock | mock m1]
>

creates and verifies LenientBehaviorSpec. It only defines arbitrary message
sends order.

If you want mock ignores any message sends you must write something like:

[:mock | mock m1; m2] should lenient satisfy: [:mock | mock anyMessage. mock
m1]

But it is not implemented yet. I think it takes a few hours work..

Possible implementation:

   - Create subclass MessageSemanticsSpec named like
   AnyMessageSemanticsSpec
   - Implement #validate: method like in MessageSemanticsSpec but without
   some testings for message selector and arguments
   - Change method BehaviorSpecBuilder>>evaluateBehavior:

 aMessageSend selector = #anyMessage ifTrue: [

 messageSendSpec := MessageSendSpec new.
messageSendSpec add: (AnyMessageSemanticsSpec from: aMessageSend).
spec add: messageSendSpec.
 ^MessageSendSpecBuilder on: messageSendSpec]

messageSendSpec := MessageSendSpec withMessageSemanticsLike: aMessageSend.
spec add: messageSendSpec.
 ^MessageSendSpecBuilder on: messageSendSpec

With that stuff you can write specification for ignoring any message any
times:

mock anyMessage useArbitrary

And use null object (with eating message sends):

mock anyMessage
useArbitrary
willReturn: Null new

Of course you can implement some nice helper messages for it.

Sorry for my english.

Best regards,
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070919/d35d9863/attachment.htm


More information about the Squeak-dev mailing list