And the greatest of these is laziness
March 19, 2008 – 9:54 amThe three virtues of excellent programmers are well-known - laziness, impatience, and hubris. Last night, I had an epiphany related to the first of these… and thus was born the laziness plugin.
You know how, when you find a bug in your app, you’re supposed to write a failing test before fixing it? Well, laziness makes this a bit easier by writing the test for you. If you’re running in development mode, laziness will add a test like the following to the bottom of your error page:
def test_get_sessions_new_should_not_raise_exception
assert_nothing_raised do
get :new, {}, {:return_to=>"/"}, {:notice=>"You cannot access that page"}, {}
end
end
The first step to fixing the bug, then, is to paste that into your functional test file and run it; if it passes, you’re most likely looking at a data issue (since the params, session, flash, and cookies are specified in the test). If it fails, you’ve got a starting point for debugging.
Laziness isn’t just helpful in development mode, though - it also comes into play in production. If you’ve installed the exception_notification plugin (and you really should have - if not, go ahead; I’ll wait), then laziness will add its generated test to the email you receive whenever your production app throws an unexpected exception.
If you can’t wait to be lazy, you can grab the plugin from Viget’s SVN repository (at http://svn.extendviget.com/lab/laziness/trunk) or GitHub. Patches are welcome through either mode (git slightly preferred).


