Skip to content

Commit

Permalink
Inspect body in ConnTest.response/2 (phoenixframework#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
qcam authored and chrismccord committed Feb 15, 2019
1 parent 237031c commit 13111ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/phoenix/test/conn_test.ex
Expand Up @@ -370,7 +370,7 @@ defmodule Phoenix.ConnTest do
if given == status do
body
else
raise "expected response with status #{given}, got: #{status}, with body:\n#{body}"
raise "expected response with status #{given}, got: #{status}, with body:\n#{inspect(body)}"
end
end

Expand Down
9 changes: 7 additions & 2 deletions test/phoenix/test/conn_test.exs
Expand Up @@ -264,9 +264,14 @@ defmodule Phoenix.Test.ConnTest do
end

assert_raise RuntimeError,
"expected response with status 200, got: 404, with body:\noops", fn ->
"expected response with status 200, got: 404, with body:\n\"oops\"", fn ->
build_conn(:get, "/") |> resp(404, "oops") |> response(200)
end

assert_raise RuntimeError,
"expected response with status 200, got: 404, with body:\n<<192>>", fn ->
build_conn(:get, "/") |> resp(404, <<192>>) |> response(200)
end
end

test "html_response/2" do
Expand Down Expand Up @@ -313,7 +318,7 @@ defmodule Phoenix.Test.ConnTest do
|> json_response(200)
end

assert_raise RuntimeError, ~s(expected response with status 200, got: 400, with body:\n{"error": "oh oh"}), fn ->
assert_raise RuntimeError, ~s(expected response with status 200, got: 400, with body:\n) <> inspect(~s({"error": "oh oh"})), fn ->
build_conn(:get, "/")
|> put_resp_content_type("application/json")
|> resp(400, ~s({"error": "oh oh"}))
Expand Down

0 comments on commit 13111ad

Please sign in to comment.