drewbourne / mockolate

fake chocolate, mock objects and test spies for AS3
http://mockolate.org/
MIT License
145 stars 26 forks source link

allow stubbing & mocking by RegExp or Matcher #16

Open drewbourne opened 14 years ago

drewbourne commented 14 years ago

As a convenience allow stubbing and mocking multiple methods or properties by providing a RegExp or Matcher as the method name.

// using a RegExp
stub(permissions).method(/can(Edit|Show|Delete)/).returns(true);

// using a Matcher
var eventDispatcherMethods:Array = ['addEventListener', 'dispatchEvent', 'hasEventListener', 'removeEventListener', 'willTrigger'];
stub(permissions).method(inArray(eventDispatcherMethods)).anyArgs().pass();
drewbourne commented 13 years ago

added support for matching method and property names with a RegExp:

mock(permissions).methods(/^can/)
stub(slotmachine).setters(/^slot\d/).arg(Number);
stub(slotmachine).getters(/^slot\d/).returns(10);
drewbourne commented 13 years ago

TODO add support to test spies

drewbourne commented 13 years ago

added support for matching methods, getters, and setters by RegExp to test spies.