And the greatest of these is laziness

March 19, 2008 – 9:54 am

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

  1. 10 Responses to “And the greatest of these is laziness”

  2. Hi, I installed your plugin in my rails app. When I tried to start mongrel server, it gave me error related to ExceptionNotifier. Is it compulsory to have it?

    – Anil

    By Anil Wadghule on Mar 23, 2008

  3. Ah, sorry! If I had to say, I’d rate the plugin as being in early-alpha, so there are lots of bugs left to work out. I’m hoping to have any update for this later today.

    By Ben on Mar 23, 2008

  4. PATCH (not in svn yet, in git?)

    vendor/plugins/laziness/lib/laziness.rb

    begin
    module ExceptionNotifier
    ::ExceptionNotifier.sections

    By grosser on Mar 24, 2008

  5. arg at markup
    module Laziness
    begin
    module ExceptionNotifier
    ::ExceptionNotifier.sections << ‘laziness’
    end
    rescue
    end

    By grosser on Mar 24, 2008

  6. Thanks for the patch! I’d actually already updated the git version (with a different fix), but I forgot to do the same for the SVN copy. It’s updated now, and I’m hoping to find a better process for keeping them in sync in the future.

    By Ben on Mar 24, 2008

  7. How hard would it be to port this to rspec?

    By Will Sargent on Apr 2, 2008

  8. Actually, it already works with RSpec - if you install it on a project that has specs, you’ll get specs out from it instead of tests.

    By Ben on Apr 2, 2008

  9. slick little tool

    By Lucy on May 26, 2008

  1. 2 Trackback(s)

  2. Mar 20, 2008: Labnotes » Rounded Corners - 197 (Not a moment too soon)
  3. Mar 24, 2008: Instant Bug to Testcase « My Pragmatig life

Post a Comment