[testbox v1.1] assert failure messages in BDD

Hello,

Was just writing some tests and wondered if it’s possible to provide a custom failure message when doing the BDD style of testing.

For example using the $assert syntax I can do this in my tests:

$assert.isEqual(12, mock.$callLog().startSubscription[1].months, “Should be 12 months”);
$assert.isEqual(12, mock.$callLog().startSubscription[1].fee, “Should have a fee of 12”);
$assert.isEqual(12, mock.$callLog().startSubscription[1].optionid, “Should be option id 12”);

With BDD (although I can use the asserts syntax above) the syntax is more like:

expect(mock.$callLog().startSubscription[1].months).toBe(12);
expect(mock.$callLog().startSubscription[1].fee).toBe(12);
expect(mock.$callLog().startSubscription[1].optionid).toBe(12);

The issue I have with using the ‘toBe’ style is that if any of the above asserts fail, the message I get is:

Expected [12] but received [11]

From that I don’t know which assert failed. I didn’t know if there was (or could be added) something like:

expect(mock.$callLog().startSubscription[1].months).toBe(12).onFail(“Should be 12 months”);
expect(mock.$callLog().startSubscription[1].fee).toBe(12).onFail(“Should have a fee of 12”);
expect(mock.$callLog().startSubscription[1].optionid).toBe(12).onFail(“Should be option id 12”);

Thanks!

John

John, every toBe() function has a ‘message’ argument, if you see the API Docs :slight_smile:

signature0.jpg

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

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Ah - found it - thanks Luis!

I didn’t see that on the wiki under the matchers section: http://wiki.coldbox.org/wiki/TestBox.cfm#Matchers

Although having looked again I can see that the toBeTypeOf method supports it so should have figured it out.

For anyone else in reading this in the future you can do this:

expect(something).toBe(12, “expected 12 months”);

I think I should get an award for finding something you haven’t documented :slight_smile:

Thanks again Luis - testbox / mockbox and general *box is awesome!

Cheers,

John

signature0.jpg

Lol.

Technically they are documented in the API docs. But note taken for the main docs.

signature0.jpg