public
Description: A Rails plugin to create tests for you when your app throws an unhandled exception
Homepage: http://www.culann.com/2008/03/and-the-greatest-of-these-is-laziness
Clone URL: git://github.com/bscofield/laziness.git
jnewland (author)
Wed Apr 30 06:26:46 -0700 2008
commit  a462b78209142604f9bbd718e7abd72f8c49c898
tree    7905f1e5124d7962c15d3bce81e066ec9d9d1fed
parent  6a04d53bd8b792111606c4fe564516395df5f01f
name age message
file MIT-LICENSE Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
file README Loading commit data...
file Rakefile Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
file TODO Fri Mar 21 05:23:06 -0700 2008 update README to reflect RSpec additions [bscofield]
file init.rb Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
file install.rb Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
directory lib/
directory tasks/ Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
directory test/ Wed Mar 19 06:43:06 -0700 2008 adding the laziness plugin - initial import gi... [ben]
directory views/
README
Laziness
========

Laziness does one thing: if your application throws an unhandled error, it will automatically create a failing test for 
you to copy into the appropriate test file - or if you're using RSpec, it'll write the appropriate spec for you.

Installation
============

If you're running ExceptionNotifier, you'll need to make sure that vendor/plugins/laziness/views/_laziness.rhtml is 
copied into vendor/plugins/exception_notification/views/exception_notifier - that will allow your exception notifier 
emails to include the generated test (or spec). The file is normally copied over by the plugin installation process, but 
if it doesn't make it there you can move it by hand.

Example
=======

Say you're browsing your site and you get a 500 error on /users/new, which is rendering the UsersController#new action. 
In the error page (or exception email, if you're using ExceptionNotifier), Laziness adds something like the following:

def test_get_users_new_should_not_raise_nameerror_exception
  assert_nothing_raised(NameError) do
    get :new, {[params from request]}, {[session from request]}, {[flash from request]}
  end
end

The exact exception asserted (in this case, NameError) will depend on what caused the 500 error in the first place.

If you're using RSpec, the generated code will look like this:

describe "Handling GET users new" do
  it "should not raise NameError" do
    lambda { 
      get :new, {[params from request]}, {[session from request]}, {[flash from request]}
    }.should_not raise_error(NameError)
  end
end

Catching Specific Exceptions
============================

You can customize the tests to be generated on an exception-by-exception basis; just add the appropriate file to 
lib/exceptions/what/ever.rb and make sure it defines ++test++ and ++spec++ methods; look at 
lib/exceptions/action_controller/unknown_view.rb for an example.


Copyright (c) 2008 Ben Scofield, released under the MIT license