@@ -38,6 +38,16 @@ defmodule ExUnit.AssertionError do
|
||||
@no_value
|
||||
end
|
||||
|
||||
@impl true
|
||||
def exception(opts) do
|
||||
with {:ok, message} when not is_binary(message) <- Keyword.fetch(opts, :message) do
|
||||
raise ArgumentError,
|
||||
":message in ExUnit.Assertion must be a binary, got: #{inspect(message)}"
|
||||
end
|
||||
|
||||
struct(__MODULE__, opts)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def message(exception) do
|
||||
"\n\n" <> ExUnit.Formatter.format_assertion_error(exception)
|
||||
|
||||
@@ -857,6 +857,22 @@ defmodule ExUnit.AssertionsTest do
|
||||
"assertion" = error.message
|
||||
end
|
||||
|
||||
test "assert operator with custom options" do
|
||||
assert 1 > 2, message: "assertion"
|
||||
flunk("This should never be tested")
|
||||
rescue
|
||||
error in [ExUnit.AssertionError] ->
|
||||
"assertion" = error.message
|
||||
end
|
||||
|
||||
test "assert operator with invalid options" do
|
||||
assert 1 > 2, message: 123
|
||||
flunk("This should never be tested")
|
||||
rescue
|
||||
error in [ArgumentError] ->
|
||||
":message in ExUnit.Assertion must be a binary, got: 123" = error.message
|
||||
end
|
||||
|
||||
test "assert lack of equality" do
|
||||
try do
|
||||
assert "one" != "one"
|
||||
|
||||
Reference in New Issue
Block a user