Correction: dSpec does have the optional Message parameter

In my last post, I incorrectly said that dSpec doesn’t have the Message parameter. Jody corrected me. Here’s the syntax:

Specify.That(FRate, 'Tax rate').Should.Equal(0.10);

I kinda like this syntax — it puts the label right next to the thing it’s labeling, rather than putting the label last like DUnitLite does now. What do you guys think? Which of the following syntaxes would be best for DUnitLite?

Specify.That(FRate, Should.Equal(0.10), 'Tax rate'); // (a)
Specify.That(FRate, 'Tax rate', Should.Equal(0.10)); // (b)
Specify.That('Tax rate', FRate, Should.Equal(0.10)); // (c)

Currently DUnitLite uses (a). (b) is more like dSpec.

The advantage to (c) would be when your expressions are long enough to line-wrap. If the label is likely to be shorter than the expression being tested (and, therefore, more likely to fit on the first line without wrapping), then this kind of formatting might work really well:

Specify.That('State tax rate',
TInvoiceCalculator.CreateForState(FCustomer.State).TaxRate,
Should.Equal(0.10));

But without wrapping, having a label as the first parameter might get in the way of readability. I’m not sure.

Which syntax seems most readable to you?

Leave a Reply

Your email address will not be published. Required fields are marked *