public class ErrorRule extends MethodRuleBase implements IMethodRule {
override public function evaluate(parentToken:AsyncTestToken):void {
super.evaluate(parentToken);
proceedToNextStatement();
setTimeout(function():void {
myToken.sendResult(new IOError("asdf"));
}, 10);
}
override protected function
handleStatementComplete(result:ChildResult):void {
if (result.error)
super.handleStatementComplete(result);
}
}
And a test case which expects an error:
public class SomeTest {
[Rule]
public var errorRule:ErrorRule = new ErrorRule();
[Test(expects="flash.errors.IOError")]
public function testError(): void { /* all the work is done by
ErrorRule */ }
}
I get the result:
at org.flexunit.internals.runners.statements::MethodRuleBase/
proceedToNextStatement()[...statementsMethodRuleBase.as:50]
at org.flexunit.internals.runners.statements::ExpectException/
evaluate()[...statementsExpectException.as:152]
at org.flexunit.internals.runners.statements::InvokeMethod/evaluate()
[...statementsInvokeMethod.as:73]
at org.flexunit.token::AsyncTestToken/sendResult()[...
okenAsyncTestToken.as:119]
at org.flexunit.internals.runners.statements::ExpectException/
handleNextExecuteComplete()[...statementsExpectException.as:189]
Error: Expected exception: flash.errors.IOError
It seems like the problem is that the 'expects' is being checked soon
as the test case terminates instead of when the rule sends the result.
On 24-Jun-10, at 5:16 PM, Michael Labriola wrote:
> I don't think you are doing what you think you are doing :)
Obviously not :)
> First, let's pretend the expecting exception argument isn't there.
> ...
> Now, let's put your expecting exception argument back in.
> When you call proceedToNextStatement() it works all the way down the
> stack again, runs the test and then starts back up the stack. When it
> gets to expectingException your code hasn't run, there isn't an
> exception on the method, so it is going to throw an exception because
> there wasn't an error and you said their would be.
Ah, right — so that's the issue. I had expected the "expects" code to
be "higher up" the stack, so it would be triggered when I explicitly
send an error.
So, how do you think FlexUnit could make it easy for custom rules to
respect the "expects=" metadata?