misprintt/mockatoo — pull request #1 by misprintt (2012-10-23 02:21:12+00:00)
Title: Added verification, verification modes and verification matchers

### Basic Verification

Verification refers to validation of of if, and how often a method has been
called (invoked) with particular argument values.

To verify that a method *foo* has been invoked:

Mockatoo.verify(mock).foo();
Mockatoo.verify(mock).foo("bar");
Mockatoo.verify(mock).foo("foo");
Mockatoo.verify(mock).foo("foo", true);

Once created, mock will remember all interactions. Then you can selectively verify whatever interaction you are interested in.

### Argument Matchers

Mockatoo verifies argument values in natural syntax: by using an equals() method. Sometimes, when extra flexibility is required then you might use argument matchers:

To verify fuzzy matching on arguments, import Matchers:

import mockatoo.Matchers;

Matching against a type:

Mockatoo.verify(mock).foo(anyString);
Mockatoo.verify(mock).foo(anyInt);
Mockatoo.verify(mock).foo(anyFloat);
Mockatoo.verify(mock).foo(anyBool);
Mockatoo.verify(mock).foo(anyObject);	//anonymous data structures only (not class instances)
Mockatoo.verify(mock).foo(anyIterator); // any Iterator or Iterable (e.g. Array, Hash, etc)
Mockatoo.verify(mock).foo(anyEnum);	// any enum value of any enum;

Matching against a specific class or enum:

Mockatoo.verify(mock).foo(enumOf(Color));	// any enum value of Enum Colour
Mockatoo.verify(mock).foo(instanceOf(SomeClass));	// any instance of SomeClass (or it's subclasses)

Wildcard matches

Mockatoo.verify(mock).foo(any);	//any value (including null)
Mockatoo.verify(mock).foo(isNotNull);	// any non null value
Mockatoo.verify(mock).foo(isNull);	// same as verifying 'null')

Custom matching function

var f = function(value:Dynamic):Bool
{
...
}

Mockatoo.verify(mock).foo(customMatcher(f));

### Verifying exact number of invocations

To verify the number of times a method was invoked, import VerificationMode

import mockatoo.VerificationMode;

Verifications use natural language to specify the minimum and maximum times a method was invoked with specific arguments

Mockatoo.verify(mock, times(2)).foo();
Mockatoo.verify(mock, atLeast(2)).foo();
Mockatoo.verify(mock, atLeastOnce).foo();
Mockatoo.verify(mock, never).foo();
Mockatoo.verify(mock, between(2,3)).foo();

> Note: Default mode is times(1);