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!
http://relishapp.com/rspec/rspec-rails/v/2-1/dir/controller-specs/anonymous-controller
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users