expect and allow

72 views
Skip to first unread message

Camille Reynders

unread,
Nov 15, 2012, 4:09:28 AM11/15/12
to mock...@googlegroups.com
I'm struggling a bit with `expect` and `allow`. Looking at the docs, I'd say `expect` is for mocking and `allow` is for stubbing, however I don't seem to get them to work as I expect.
For instance: I've got the following:

[Before]
public function setup():void{
allow( mockLoaderFactory.createURLLoader( arg( anything( ) ) ) )
.returns( mockLoader );

stub( mockLoader ).asEventDispatcher();
instance = new BaseLoaderServiceImpl();
instance.urlLoaderFactory = mockLoaderFactory;
}

 There are tests that will be calling mockLoaderFactory.createURLLoader and others will not, so I'd think I have to use `allow` here and not `expect`, otherwise the tests that don't call that method will complain.

However 

[Test]
public function test_loadRequest_setsIsBusyToTrue() : void{
instance.loadRequest( new URLRequest( 'http://mock' ) );
assertTrue( instance.isBusy );
}

instance.loadRequest does call mockLoaderFactory.createURLLoader but it doesn't appear to return anything. So, if I assume correctly, `allow` just literally allows the call on the method, but it doesn't _do_ anything?

How would I be able to do this then? I just want to replace a stub, so I don't have to use the methodname as string approach.

Drew Bourne

unread,
Nov 19, 2012, 10:06:21 AM11/19/12
to mock...@googlegroups.com
You are correct that `expect` is for mocking, and `allow` is for stubbing. 

Does the mockLoaderFactory.createURLLoader method have any optional arguments? If so then you also need to provide them with calls to `arg()`. If not then we'll need to dig deeper. 

cheers, 
Drew
Reply all
Reply to author
Forward
0 new messages