Skip to content

Commit

Permalink
Disable display of detailed exceptions
Browse files Browse the repository at this point in the history
`@allow-rescue` permits rescuing exceptions by setting
`action_dispatch.show_exceptions` to true in the env hash. However,
this will render the detailed error page and not the public error page
you'd encounter in production.

Given that the feature enables testing of error pages, and seems to be
intended to mirror production behaviour as per the comment on
https://github.com/cucumber/cucumber-rails/blob/master/lib/generators/cucumber/install/templates/support/_rails_each_run.rb.erb#L6-L14,
this PR sets `action_dispatch.show_detailed_exceptions` to false, thus
enabling the public error page to be rendered.
  • Loading branch information
pedrosmmoreira authored and xtrasimplicity committed Apr 22, 2018
1 parent bf0ec80 commit dcc3b24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions features/allow_rescue.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ Feature: Allow Cucumber to rescue exceptions
Feature: posts
@allow-rescue
Scenario: See posts
When I look at the posts
When I look at the posts
Then I should see the public error page
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I look at the posts$/ do
visit '/posts'
end
Then /^I should see the public error page$/ do
expect(page).to have_content "We're sorry, but something went wrong. \
If you are the application owner check the logs for more information."
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec cucumber`
Then the feature run should pass with:
"""
1 scenario (1 passed)
1 step (1 passed)
2 steps (2 passed)
"""

Scenario: Don't allow rescue
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ActionDispatch::ShowExceptions

def call(env)
env['action_dispatch.show_exceptions'] = !!ActionController::Base.allow_rescue
env['action_dispatch.show_detailed_exceptions'] = !ActionController::Base.allow_rescue
__cucumber_orig_call__(env)
end
end

0 comments on commit dcc3b24

Please sign in to comment.