[rspec-users] Specs for controllers and rescue_from

David Chelimsky dchelimsky at gmail.com
Sun Nov 21 17:02:57 EST 2010

On Nov 20, 2010, at 10:12 PM, Nick Hoffman wrote:

> Hey guys. My ApplicationController rescues
> Mongoid::Errors::DocumentNotFound errors like this:
> class ApplicationController < ActionController::Base
>  rescue_from Mongoid::Errors::DocumentNotFound,
>    :with => :resource_not_found
>  protected
>  def resource_not_found(error)
>    flash[:alert] = t('errors.resource_not_found')
>    redirect_to root_url
>  end
> end
> Obviously, I need specs for this. However, I can't figure out how this
> should be specced.
> Should I create a shared example group that expects the flash-alert
> and redirect, and use it in every controller action that could
> potentially raise this error? This seems right, but will be verbose.
> Or, in each controller that could raise this error, should I create
> one example group that raises this error and expects the flash-alert
> and redirect? This seems right because the rescuing behaviour exists
> within the controller rather than each action. However, it ignores the
> possibility of an action rescuing the error.
> Should I create a dummy controller with an action that raises this
> error, and spec that? This would be akin to speccing
> ApplicationController, though indirectly. This method was my first
> inclination, but fails to provide specs for the other controllers that
> inherit the rescuing behaviour.
> How would you spec this? I'm all ears!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101121/5285c8ad/attachment.html>

More information about the rspec-users mailing list