toThrow() cannot match empty message & cannot match detail

Description

ColdSpring throws coldspring.NoSuchBeanDefinition when you request a non-existent bean, e.g., Wibble, but it uses an empty message and a detail of "Bean definition for bean named: Wibble could not be found."

Assertion.throws() will not match any empty message: reFindNoCase( "", "" ) returns zero, as does reFindNoCase( "^$", "" ) so it seems that a special case is needed for e.message.

In addition, you can't match on the detail of an exception at all which means you can't differentiate between two similar exceptions.

I'm not quite sure what the best solution is here. I'd be tempted to change both calls of reFindNoCase( arguments.regex, e.message ) to ( reFindNoCase( arguments.regex, e.message ) || reFindNoCase( arguments.regex, e.detail ) ). That would solve the immediate problem insofar as you could then match on detail OR message.

Longer term, adding support for matching detail separately and special-casing for message / detail being empty strings would probably be a better solution.

Thoughts?

FWIW, I made the simple change locally of testing regex against message or detail and that's working nicely for me.

Activity

Show:
Luis Majano
January 9, 2014, 4:24 AM

Sorry. Trying to catch up from vacation. Coming back is more stressful than
leaving.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Social: twitter.com/ortussolutions | twitter.com/coldbox |
twitter.com/lmajano | twitter.com/gocontentbox

Luis Majano
January 14, 2014, 5:28 PM

I am going with Sean's suggestion at this point where it should match either the message or detail. I also changed it to match no case thanks to Adam's investigation.

Sean Corfield
January 14, 2014, 6:03 PM

Cool. Did you add .withDetail() as well? If not, should I raise a new ticket?

Luis Majano
January 14, 2014, 7:30 PM

No, you can raise a ticket so we can brainstorm on it. I have not really had a real-life scenario for this, using the toThrow() as is with the addition has good coverage. But yea, go for it.

Sean Corfield
January 14, 2014, 7:43 PM

Assignee

Luis Majano

Reporter

Sean Corfield

Labels

None

Components

Fix versions

Affects versions

Priority

Major
Configure