Friday, May 19, 2006

flunk, my autotest friend

You use autotest, right? (gem install ZenTest and get on it if you don't). Well, then you know autotest auto-focuses on failing tests. You probably also love this and rely on it all the time. Well, leverage flunk and take your relationship with autotest to the next level.
test_some_silly_thing
blah, blah, blah, blah
this is a test that should be much smaller but isn't
or is mystifying me with its strange behavior or something
and I want to debug what the F@#! is going on, and
I don't want to run the other 4800 tests that take more
than the 8 milliseconds attention span I am willing to
wait for my tests to run or, ... you get the idea
end

Now, lets make autotest focus on test_some_silly_thing. Add the following line as the last line of the test:

flunk "Passed!"

Cool! Now, even if our test passes, we fail. This means autotest will stay focused while we play. You can now do things like check the database after your test runs (because it is the only test that was run and no other tests had a chance to muck things up).

By the way, if you don't already know, flunk is the equivalent of assert false. It is so much easier to read and understand than assert false is though.

A few links you might find useful:
ZenTest
Using autotest with Rails
article on ZenTest in Linux Journal
Dr. Brain rails against his own creation
Everything else Dr. Brain said about ZenTest in his blog

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home