Expects with Message

18 views
Skip to first unread message

Ben Johnson

unread,
Feb 10, 2011, 1:28:31 AM2/10/11
to Flexunit Contributors
I'd like to add a feature to FlexUnit that allows me to assert the
message of an error. Right now I can only use
[Test(expects="MyError")] to specify the type of error thrown.

I would like to add an optional "message" argument so that it looks
like this:

[Test(expects="MyError", message="Value cannot be xyz")]

The reason I would like this is that I typically use standard Flash
errors such as ArgumentError and IllegalOperationError in my code and
I need to be able to differentiate between errors by their message and
not their class.

Any suggestions are appreciated. I'll code it up and submit a Pull
Request on GitHub if there are no objections.


Ben Johnson

Michael Labriola

unread,
Feb 10, 2011, 11:34:50 AM2/10/11
to Flexunit Contributors

I like the idea.

Thoughts on making it more specific?

[Test(expects="MyError", expectsMessage="Value cannot be xyz")]

Mike

Kris

unread,
Feb 10, 2011, 11:36:26 AM2/10/11
to flexunit-c...@googlegroups.com
expectsMessage should be a regexp

Regards,
Kris

Ben Johnson

unread,
Feb 10, 2011, 12:42:53 PM2/10/11
to flexunit-c...@googlegroups.com
Mike-

I was thinking of using "errorMessage" but I like "expectsMessage" better.


Ben


From: Michael Labriola <malab...@gmail.com>
To: Flexunit Contributors <flexunit-c...@googlegroups.com>
Sent: Thu, February 10, 2011 9:34:50 AM
Subject: Re: Expects with Message

Ben Johnson

unread,
Feb 10, 2011, 12:50:18 PM2/10/11
to flexunit-c...@googlegroups.com
Kris-

I think regex is an edge case. Most of the time I want to match a specific a message thrown from a test. The only time I could see using regex is when an error message includes a time or when your methods are non-deterministic. In those cases you can still catch the error in a test and do an assertTrue() against a regex on the error's message.

A regex would also increase the complexity of using "expectsMessage" since you would have to escape all the regex special characters.


Ben Johnson



From: Kris <kris.kar...@gmail.com>
To: flexunit-c...@googlegroups.com
Sent: Thu, February 10, 2011 9:36:26 AM

Subject: Re: Expects with Message

Michael Labriola

unread,
Feb 10, 2011, 3:25:41 PM2/10/11
to Flexunit Contributors

Ben,

Let's look at both. Go ahead and fork and commit the string matching
version (and give me some tests to go with it if you can)

Then let's look at the regex version. I do see where this could be
quite useful though,
Mike

On Feb 10, 11:50 am, Ben Johnson <benbjohn...@yahoo.com> wrote:
> Kris-
>
> I think regex is an edge case. Most of the time I want to match a specific a
> message thrown from a test. The only time I could see using regex is when an
> error message includes a time or when your methods are non-deterministic. In
> those cases you can still catch the error in a test and do an assertTrue()
> against a regex on the error's message.
>
> A regex would also increase the complexity of using "expectsMessage" since you
> would have to escape all the regex special characters.
>
> Ben Johnsonhttps://github.com/benbjohnson
>
> ________________________________
> From: Kris <kris.karczmarc...@gmail.com>
Reply all
Reply to author
Forward
0 new messages