Permalink
Browse files

rename feature to bypass_rescue and tweak it a bit

  • Loading branch information...
1 parent e028626 commit b4da358d4fa662d84be1bcdd08b773c6db505ce1 @dchelimsky dchelimsky committed Aug 16, 2011
Showing with 76 additions and 75 deletions.
  1. +1 −0 features/.nav
  2. +75 −0 features/controller_specs/bypass_rescue.feature
  3. +0 −75 features/controller_specs/error_handling.feature
View
@@ -15,6 +15,7 @@
- isolation_from_views.feature
- render_views.feature
- anonymous_controller.feature
+ - bypass_rescue.feature
- helper_specs:
- helper_spec.feature
- mailer_specs:
@@ -0,0 +1,75 @@
+Feature: bypass rescue
+
+ Use `bypass_rescue` to bypass both Rails' default handling of errors in
+ controller actions, and any custom handling declared with a `rescue_from`
+ statement.
+
+ This lets you specify details of the exception being raised, regardless of
+ how it might be handled upstream.
+
+ Background:
+ Given a file named "spec/controllers/gadgets_controller_spec_context.rb" with:
+ """
+ class AccessDenied < StandardError; end
+
+ class ApplicationController < ActionController::Base
+ rescue_from AccessDenied, :with => :access_denied
+
+ private
+
+ def access_denied
+ redirect_to "/401.html"
+ end
+ end
+ """
+
+ Scenario: standard exception handling using `rescue_from`
+ Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
+ """
+ require "spec_helper"
+
+ require 'controllers/gadgets_controller_spec_context'
+
+ describe GadgetsController do
+ before do
+ def controller.index
+ raise AccessDenied
+ end
+ end
+
+ describe "index" do
+ it "redirects to the /401.html page" do
+ get :index
+ response.should redirect_to("/401.html")
+ end
+ end
+ end
+ """
+ When I run `rspec spec/controllers/gadgets_controller_spec.rb`
+ Then the examples should all pass
+
+ Scenario: bypass `rescue_from` handling with `bypass_rescue`
+ Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
+ """
+ require "spec_helper"
+
+ require 'controllers/gadgets_controller_spec_context'
+
+ describe GadgetsController do
+ before do
+ def controller.index
+ raise AccessDenied
+ end
+ end
+
+ describe "index" do
+ it "raises AccessDenied" do
+ bypass_rescue
+ expect { get :index }.to raise_error(AccessDenied)
+ end
+ end
+ end
+ """
+ When I run `rspec spec/controllers/gadgets_controller_spec.rb`
+ Then the examples should all pass
+
@@ -1,75 +0,0 @@
-Feature: Default Rails error handling can be overridden using :bypass_rescue
-
- Errors from a controller action will normally be handled by the
- default Rails exception handling mechanism (i.e. they will not
- propagate out). If handling of particular exceptions
- is implemented outside of the controller under test(e.g. an inherited :rescue_from),
- it may be preferred to assert only that the expected exception was raised.
- This can be accomplished using :bypass_rescue
-
- Background:
- Given a file named "spec/controllers/gadgets_controller_spec_context.rb" with:
- """
- class ErrorHandlingAccessDenied < StandardError; end
-
- class ApplicationController < ActionController::Base
- rescue_from ErrorHandlingAccessDenied, :with => :access_denied
-
- private
-
- def access_denied
- redirect_to "/401.html"
- end
- end
- """
-
- Scenario: Standard Rails exception handling (the default)
- Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
- """
- require "spec_helper"
-
- require 'controllers/gadgets_controller_spec_context'
-
- describe GadgetsController do
- before do
- def controller.index
- raise ErrorHandlingAccessDenied
- end
- end
-
- describe "index" do
- it "redirects to the /401.html page" do
- get :index
- response.should redirect_to("/401.html")
- end
- end
- end
- """
- When I run `rspec spec/controllers/gadgets_controller_spec.rb`
- Then the examples should all pass
-
- Scenario: Rails exception rescuing can be bypassed with :bypass_rescue
- Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
- """
- require "spec_helper"
-
- require 'controllers/gadgets_controller_spec_context'
-
- describe GadgetsController do
- before do
- def controller.index
- raise ErrorHandlingAccessDenied
- end
- end
-
- describe "index" do
- it "raises AccessDenied" do
- bypass_rescue
- expect { get :index }.to raise_error(ErrorHandlingAccessDenied)
- end
- end
- end
- """
- When I run `rspec spec/controllers/gadgets_controller_spec.rb`
- Then the examples should all pass
-

0 comments on commit b4da358

Please sign in to comment.