Format match? failures more elegantly

[#144]
This commit is contained in:
Jay Hayes
2016-12-23 08:19:30 -06:00
parent 08973f4b54
commit 4bb0b06471
2 changed files with 18 additions and 0 deletions

View File

@@ -26,6 +26,12 @@ defmodule Display.Failure do
defp format_inequality(message, %{left: @no_value, right: @no_value}) do
message
end
defp format_inequality(message, %{left: @no_value, right: match_value}) do
"""
#{message}
value does not match: #{match_value |> inspect |> Paint.yellow}
"""
end
defp format_inequality(message, %{left: left, right: right}) do
"""
#{message}

View File

@@ -25,6 +25,18 @@ defmodule FailureTests do
right: :wat
"""
end
test "match failure" do
error = error(%ExUnit.AssertionError{expr: quote(do: match?(:lol,:wat)), right: :wat})
assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42
match?(:lol, :wat)
value does not match: :wat
"""
end
defp error(error) do
%{
error: error,