Joe White’s Blog

Life, .NET, and Cats


New DUnitLite syntax: Should.Yield

No, I’m not adding Ruby-style blocks, more’s the pity. Just some syntactic sugar.

SpecifyThatInspecting('', Should.Yield(Apostrophes(2)));
SpecifyThatInspecting('a', Should.Yield(Apostrophe + 'a' + Apostrophe));
SpecifyThatInspecting(#13#10, Should.Yield('#13#10'));

The above samples are from the StringInspectorSpecs unit in DUnitLite. They specify parts of the contract for a method called Inspect, which takes a string and returns a string.

One of the requirements for TStringInspector is that when I call the Inspect method, and pass it #13#10, it should return '#13#10'. In other words,

Specify that inspecting #13#10 should yield '#13#10'.

As you can see, Should.Yield is nothing more than an alias for Should.Equal. Use whichever one makes your code most readable.

This is where I expect a lot of the work will be done with DUnitLite-style specifications: with custom assertion methods like SpecifyThatInspecting. Play with it and see what other readable assertions you can come up with. I’m certainly willing to tweak the framework, to add more things along the lines of Should.Yield, if it makes specifications more readable.

(The version with Should.Yield hasn’t been released as a ZIP yet. You can view StringInspectorSpecs.pas, browse all the latest source, anonymously check out the latest code, or wait for the next release.)

Update: This feature is included in the DUnitLite 0.2 download.

There are no responses to “New DUnitLite syntax: Should.Yield” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).