misprintt/mockatoo — pull request #2 by misprintt (2012-10-23 05:30:05+00:00)
Title: Stubbing

### Basic Stubbing

Mockatoo allows the behaviour of methods to be stubbed

Mockatoo.when(mock.foo("bar")).thenReturn("hello");

You can also specify an execption

Mockatoo.when(mock.foo("not bar")).thenThrow(new SomeApplicationException("not a bar"));

### Chained stubbing

Stubbing is chainable, so you can specify the behaviour each time a method is called. Values are defined in order.

Mockatoo.when(mock.foo("bar")).thenReturn("hello", "goodbye");

Exceptions and returns can be chained together.

Mockatoo.when(mock.foo("bar")).thenReturn("hello").thenThrow("all gone");

Once all stubs have been used, then the method defaults back to the default value for that return type.

You can also set a custom callback when a method is invoked

var f = function(args:Array)
{
if(Std.is(args[0], String) return args[0].charAt(0) == "b";
}

Mockatoo.when(mock.foo("bar")).thenCall(f);