From 04615d7ccc15e49150ea2742d395a9f8c52dd493 Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Wed, 3 Jun 2015 16:38:32 +0100 Subject: [PATCH 1/3] Disable display of detailed exceptions `@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. --- features/allow_rescue.feature | 9 +++++++-- lib/cucumber/rails/action_controller.rb | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/features/allow_rescue.feature b/features/allow_rescue.feature index 3c0c183b..bba79f78 100644 --- a/features/allow_rescue.feature +++ b/features/allow_rescue.feature @@ -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 diff --git a/lib/cucumber/rails/action_controller.rb b/lib/cucumber/rails/action_controller.rb index 36af2ab8..705089b1 100644 --- a/lib/cucumber/rails/action_controller.rb +++ b/lib/cucumber/rails/action_controller.rb @@ -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 From b019ac0c33be4754a6fdae74f67593bbcb4504ec Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Thu, 4 Jun 2015 10:38:35 +0100 Subject: [PATCH 2/3] Do not rely on current public error message There are slight changes in the error message displayed in the public error pages across Rails versions. Checking for "We're sorry, but something went wrong." seems to be the safest option. --- features/allow_rescue.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/allow_rescue.feature b/features/allow_rescue.feature index bba79f78..002b2de9 100644 --- a/features/allow_rescue.feature +++ b/features/allow_rescue.feature @@ -32,8 +32,7 @@ Feature: Allow Cucumber to rescue exceptions 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." + expect(page).to have_content "We're sorry, but something went wrong." end """ And I run `bundle exec rake db:migrate` From a090efc7ea377827b048a020fe4c031891a9e995 Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Mon, 7 Mar 2016 12:50:57 +0000 Subject: [PATCH 3/3] Make check conditional to Rails version This PR depends on action_dispatch.show_detailed_exceptions being set, which was only introduced in Rails 3.2.1. Here we introduce a conditional check based on the required Rails version in order to ensure backwards compatibility. --- lib/cucumber/rails/action_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cucumber/rails/action_controller.rb b/lib/cucumber/rails/action_controller.rb index 705089b1..9a93ca28 100644 --- a/lib/cucumber/rails/action_controller.rb +++ b/lib/cucumber/rails/action_controller.rb @@ -7,7 +7,9 @@ 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 + if Rails.version >= "3.2.1" + env['action_dispatch.show_detailed_exceptions'] = !ActionController::Base.allow_rescue + end __cucumber_orig_call__(env) end end