drewbourne / mockolate

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

Allow constructor args for mocks created by MockolateRule #35

Closed drewbourne closed 13 years ago

drewbourne commented 13 years ago

For vars marked with [Mock] if there is a constructorArgs attribute, try calling resolving and calling a function with the same name on the current test case to get the array of parameters to pass to the constructor.

[Mock(constructorArgs="exampleArgs")]
public var example:Example;
public function exampleArgs():Array { return ["Example", true, 3]; }
Amy-B-Vitrue commented 13 years ago

I tried this, and my function was never called. This resulted in "TypeError: Error #2007: Parameter type must be non-null."

I have the most recent version of Mockolate. Is this planned functionality, or is this supposed to be in there now?

drewbourne commented 13 years ago

I haven't yet implemented this feature.

You can pass constructor arguments manually using nice(), strict() or partial() like so:

var example1:Example = nice(Example, "example1", [ arg1, arg2 ]); var example2:Example = strict(Example, "example2", [ arg1, arg2 ]); var example3:Example = partial(Example, "example3", [ arg1, arg2 ]);

drewbourne commented 13 years ago

Pushed to master.

Implemented as:

[Mock(args="argsAsField")]
public var target1:ClassWithConstructorArgs;
public var argsAsField:Array = [ true ];

[Mock(args="argsAsFunction")]
public var target2:ClassWithConstructorArgs;
public function argsAsFunction():Array {
    return [ true ];
}