You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/configuring.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2020,6 +2020,25 @@ The default value depends on the `config.load_defaults` target version:
2020
2020
Enables logging those unhandled exceptions configured in`rescue_responses`. It
2021
2021
defaults to `true`.
2022
2022
2023
+
#### `config.action_dispatch.show_exceptions`
2024
+
2025
+
The`config.action_dispatch.show_exceptions` configuration controls how ActionPack (specifically the [`ActionDispatch::ShowExceptions`](/configuring.html#actiondispatch-showexceptions) middleware) handles exceptions raised while responding to requests.
2026
+
2027
+
Setting the value to `:all`or`true` configures ActionPack to rescue from exceptions and render corresponding error pages. For example, ActionPack would rescue from an `ActiveRecord::RecordNotFound` exception and render the contents of `public/404.html` with a `404 Not found` status code.
2028
+
2029
+
Setting the value to `:rescueable` configures ActionPackrescue from exceptions defined in [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses), and raise all others. For example, Action Pack would rescue from `ActiveRecord::RecordNotFound`, but would raise a `NoMethodError`.
2030
+
2031
+
Setting the value to `:none`or`false` configures ActionPackraise all exceptions.
2032
+
2033
+
*`:all`, `true`- render error pages for all exceptions
2034
+
*`:rescuable`- render error pages for exceptions declared by [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses)
Copy file name to clipboardExpand all lines: guides/source/testing.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -857,6 +857,8 @@ By default, system tests are run with the Selenium driver, using the Chrome
857
857
browser, and a screen size of 1400x1400. The next section explains how to
858
858
change the default settings.
859
859
860
+
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
861
+
860
862
### Changing the Default Settings
861
863
862
864
Rails makes changing the default settings for system tests very simple. All
@@ -1112,6 +1114,8 @@ end
1112
1114
1113
1115
Here the test is inheriting from `ActionDispatch::IntegrationTest`. This makes some additional helpers available for us to use in our integration tests.
1114
1116
1117
+
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
1118
+
1115
1119
### Helpers Available for Integration Tests
1116
1120
1117
1121
In addition to the standard testing helpers, inheriting from `ActionDispatch::IntegrationTest` comes with some additional helpers available when writing integration tests. Let's get briefly introduced to the three categories of helpers we get to choose from.
@@ -1311,6 +1315,8 @@ NOTE: If you followed the steps in the [Basic Authentication](getting_started.ht
By default, Rails will attempt to rescue from exceptions raised during tests and respond with HTML error pages. This behavior can be controlled by the [`config.action_dispatch.show_exceptions`](/configuring.html#config-action-dispatch-show-exceptions) configuration.
1319
+
1314
1320
### Available Request Types for Functional Tests
1315
1321
1316
1322
If you're familiar with the HTTP protocol, you'll know that `get` is a type of request. There are 6 request types supported in Rails functional tests:
If you are working with encrypted data, please carefully review the above.
380
380
381
+
### New ways to handle exceptions in Controller Tests, Integration Tests, and System Tests
382
+
383
+
The`config.action_dispatch.show_exceptions` configuration controls how ActionPack handles exceptions raised while responding to requests.
384
+
385
+
Prior to Rails7.1, setting `config.action_dispatch.show_exceptions = true` configured ActionPack to rescue exceptions and render appropriate HTML error pages, like rendering `public/404.html` with a `404 Not found` status code instead of raising an `ActiveRecord::RecordNotFound` exception. Setting`config.action_dispatch.show_exceptions = false` configured ActionPack to notrescue the exception. Prior to Rails7.1, new applications were generated with a line in`config/environments/test.rb` that set `config.action_dispatch.show_exceptions = false`.
386
+
387
+
Rails7.1 changes the acceptable values from `true`and`false` to `:all`, `:rescuable`, and`:none`.
388
+
389
+
*`:all`- render HTML error pages for all exceptions (equivalent to `true`)
390
+
*`:rescuable`- render HTML error pages for exceptions declared by [`config.action_dispatch.rescue_responses`](/configuring.html#config-action-dispatch-rescue-responses)
391
+
*`:none` (equivalent to `false`) -donotrescue from any exceptions
392
+
393
+
Applications generated by Rails7.1or later set `config.action_dispatch.show_exceptions = :rescuable`in their `config/environments/test.rb`. When upgrading, existing applications can change `config.action_dispatch.show_exceptions = :rescuable` to utilize the new behavior, or replace the old values with the corresponding new ones (`true` replaces `:all`, `false` replaces `:none`).
0 commit comments