drewbourne / mockolate

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

Ease interception of flash_proxy methods #59

Open drewbourne opened 12 years ago

drewbourne commented 12 years ago

For classes that extend Proxy Mockolate should intercept all the flash_proxy methods in order to allow use of expect().

Currently users have to do this:

mock(proxyObject).nsMethod(flash_proxy, "callProperty").args("actualMethodName", arg1, arg2).returns(result);
mock(proxyObject).nsMethod(flash_proxy, "getProperty").args("actualPropertyName", arg1, arg2).returns(result);
mock(proxyObject).nsMethod(flash_proxy, "setProperty").args("actualPropertyName", value);
mock(proxyObject).nsMethod(flash_proxy, "hasProperty").args("actualPropertyName").returns(true);

When they should be able to do this:

expect(proxyObject.actualMethodName(arg1, arg2)).returns(result);
expect(proxyObject.actualPropertyName).returns(result);
expect(proxyObject.actualPropertyName = value).returns(result);
expect("actualPropertyName" in proxyObject).returns(true);

Support for property access should also be added.

expect(proxyObject[0]).returns(indexValue);
expect(proxyObject["propertyName"]).returns(propertyvalue);

Support for property iteration should also be added.

mock(proxyObject).asProxy().withItems([ 1, 2, 3 ]);
for each (var item:* in proxyObject) { ... }
mock(proxyObject).asProxy().withProperties({ one: 1, two: 2, three: 3 });
for (var key:* in proxyObject) {  
   var value:* = proxyObject[key];
}
weltraumpirat commented 12 years ago

I just ran into a related problem while testing: If you pass a proxy object to args(), Mockolate throws an Error: Error #2090: The Proxy class does not implement callProperty. It must be overridden by a subclass.

I was able to work around it by using instanceOf( MyProxySubclass ) for now, but verifying against an actual instance would be preferable.