Calling the same method with the same arguments but get different results.

50 views
Skip to first unread message

Theo

unread,
Jul 3, 2012, 8:32:03 AM7/3/12
to Mockolate
Hi I want to call the same method with the same arguments multiple
times and get different results. A basic example is:

[Rule]
public var mocks:MockolateRule = new MockolateRule();

[Mock(type="strict")]
public var list:IList;

[Test]
public function test():void{

var seq:Sequence = sequence();
expecting(function ():void {

expect(list.getItemAt(0)).returns("Item1").thrice().inSequence(seq);
expect(list.getItemAt(0)).returns("Item2").inSequence(seq);
expect(list.getItemAt(0)).returns("Item3").inSequence(seq);
});

trace(list.getItemAt(0));
trace(list.getItemAt(0));
trace(list.getItemAt(0));

verify(list);
}

This results in:

Item1
Item2
Item2

And and error '1 unmet Exception'

I've tried a few alternatives such as:
expecting(function ():void {
expect(list.getItemAt(0)).returns("Item1").inSequence(seq);
expect(list.getItemAt(0)).returns("Item2").inSequence(seq);
expect(list.getItemAt(0)).returns("Item3").inSequence(seq);
});

and others to no avail. Surely I'm missing something simple here. This
seems like something that should be easy.

Thanks guys,

Theo.


Theo

unread,
Jul 7, 2012, 7:32:29 AM7/7/12
to mock...@googlegroups.com
Also posted on http://stackoverflow.com/ and got the answer see:


Basically instead of: 

expect(list.getItemAt(0)).returns("Item1").thrice().inSequence(seq); 
expect(list.getItemAt(0)).returns("Item2").inSequence(seq); 
expect(list.getItemAt(0)).returns("Item3").inSequence(seq);  

We need:

expect(list.getItemAt(0)).returns("Item1", "Item2", "Item3").thrice().inSequence(seq);  

Kristopher Schultz

unread,
Oct 24, 2012, 7:44:40 PM10/24/12
to mock...@googlegroups.com
This was also driving me crazy, so thank you! Too bad this is buried in the API docs. Really should be in the general documentation. I'd volunteer to write it!
Reply all
Reply to author
Forward
0 new messages