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
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.