mockolate icon indicating copy to clipboard operation
mockolate copied to clipboard

Ease interception of flash_proxy methods

Open drewbourne opened this issue 13 years ago • 1 comments

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];
}

drewbourne avatar Feb 22 '12 22:02 drewbourne

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.

weltraumpirat avatar Apr 27 '12 10:04 weltraumpirat