Skip to content

Commit

Permalink
Expand docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Aug 2, 2023
1 parent 8cac3ec commit bcb6259
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/phoenix/test/conn_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ defmodule Phoenix.ConnTest do
Useful for testing actions that you expect raise an error and have
the response wrapped in an HTTP status, with content usually rendered
by your MyApp.ErrorView.
by your MyAppWeb.ErrorHTML view.
The function accepts a status either as an integer HTTP status or
atom, such as `500` or `:internal_server_error`. The list of allowed atoms is available
Expand All @@ -658,6 +658,19 @@ defmodule Phoenix.ConnTest do
get(build_conn(), "/broken/route")
end
assert {500, [_h | _t], "Internal Server Error"} = response
This can also be used to test a route resulted in an error that was translated to a
specific response by the `Plug.Status` protocol, such as `Ecto.NoResultsError`:
assert_error_sent :not_found, fn ->
get(build_conn(), "/something-that-raises-no-results-error")
end
*Note*: for routes that don't raise an error, but instead return a status, you should test the
response directly:
conn = get(build_conn(), "/users/not-found")
assert response(conn, 404)
"""
@spec assert_error_sent(integer | atom, function) :: {integer, list, term}
def assert_error_sent(status_int_or_atom, func) do
Expand Down

0 comments on commit bcb6259

Please sign in to comment.