Skip to content

Commit

Permalink
switch to assert_raise
Browse files Browse the repository at this point in the history
  • Loading branch information
msutkowski committed Dec 18, 2023
1 parent 81a7fc5 commit 3dc3fad
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions test/test_assertions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,11 @@ defmodule OpenApiSpex.TestAssertionsTest do
conn = OpenApiSpexTest.Router.call(conn, [])
assert conn.status == 200

try do
TestAssertions.assert_operation_response(conn, "not_a_real_operation_id")
raise RuntimeError, "Should flunk"
rescue
e in ExUnit.AssertionError ->
assert e.message =~
"Failed to resolve a response schema for operation_id: not_a_real_operation_id for status code: 200"
end
assert_raise(
ExUnit.AssertionError,
~r/Failed to resolve a response schema for operation_id: not_a_real_operation_id for status code: 200/,
fn -> TestAssertions.assert_operation_response(conn, "not_a_real_operation_id") end
)
end

test "invalid schema" do
Expand All @@ -149,14 +146,11 @@ defmodule OpenApiSpex.TestAssertionsTest do

assert conn.status == 200

try do
TestAssertions.assert_operation_response(conn, "showPetById")
raise RuntimeError, "Should flunk"
rescue
e in ExUnit.AssertionError ->
assert e.message =~
"Value does not conform to schema PetResponse: Failed to cast value to one of: no schemas validate at"
end
assert_raise(
ExUnit.AssertionError,
~r/Value does not conform to schema PetResponse: Failed to cast value to one of: no schemas validate at/,
fn -> TestAssertions.assert_operation_response(conn, "showPetById") end
)
end

test "returns an error when the response content-type does not match the schema" do
Expand All @@ -170,14 +164,11 @@ defmodule OpenApiSpex.TestAssertionsTest do

assert conn.status == 200

try do
TestAssertions.assert_operation_response(conn, "showPetById")
raise RuntimeError, "Should flunk"
rescue
e in ExUnit.AssertionError ->
assert e.message =~
"Failed to resolve a response schema for operation_id: showPetById for status code: 200 and content type: unexpected-content-type"
end
assert_raise(
ExUnit.AssertionError,
~r/Failed to resolve a response schema for operation_id: showPetById for status code: 200 and content type: unexpected-content-type/,
fn -> TestAssertions.assert_operation_response(conn, "showPetById") end
)
end
end
end

0 comments on commit 3dc3fad

Please sign in to comment.