Tuesday, September 04, 2007

Ruby: Creating Custom Assertions

I've previously written about creating custom assertions for delegation and Validatable validations. Both solutions followed the same pattern, which is very similar to the example below.

Model.verify do

I do like the readability provided by the pattern; however, it isn't a practical solution.

My colleague and friend, John Hume, also created a solution for testing delegation: Handoff. The thing I really like about Handoff is that it follows the traditional test definition pattern.

def test_description

At first glance this might not seem like a big deal; however, following the traditional pattern is crucial when you want to run a test in isolation.

A large problem with my delegation custom assertion is that you must run all the tests in a file if you want the delegation tests to run. It's possible to create ways to run the individual lines; however, with each custom assertion a new way to run it in isolation must be devised. A far simpler solution is to stick to the common test definition pattern and leverage existing tools that know how to run one test at a time.

The next release of Validatable will include custom assertions that follow the traditional test definition pattern.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.