45 lines
1.5 KiB
Elixir
45 lines
1.5 KiB
Elixir
defmodule Blogex.LinkErrorTest do
|
|
@moduledoc """
|
|
Pins the rendered exception message, not just the struct.
|
|
|
|
The message is what a compile-time failure shows a human: the indentation and
|
|
the newline between errors are load-bearing. This is a characterization test
|
|
written before `message/1` was rewritten (`Enum.map/2 |> Enum.join/2` ->
|
|
`Enum.map_join/3`), so it passes on both sides of that change by design - it
|
|
exists to make the rewrite safe, not to prove new behaviour.
|
|
"""
|
|
use ExUnit.Case, async: true
|
|
|
|
test "message/1 renders one indented line per error" do
|
|
error = %Blogex.LinkError{
|
|
blog: :engineering,
|
|
post_id: "my-post",
|
|
errors: [
|
|
{1, "/blog/unknown/broken", "unknown blog ID: unknown", [post_id: "my-post"]},
|
|
{7, "/blog/engineering/", "empty slug", [post_id: "my-post"]}
|
|
]
|
|
}
|
|
|
|
assert Exception.message(error) == """
|
|
invalid internal blog links in engineering (post: my-post)
|
|
|
|
line 1: /blog/unknown/broken — unknown blog ID: unknown
|
|
line 7: /blog/engineering/ — empty slug
|
|
"""
|
|
end
|
|
|
|
test "message/1 omits the post label when there is no post id" do
|
|
error = %Blogex.LinkError{
|
|
blog: :engineering,
|
|
post_id: nil,
|
|
errors: [{3, "/blog/unknown/broken", "unknown blog ID: unknown", []}]
|
|
}
|
|
|
|
assert Exception.message(error) == """
|
|
invalid internal blog links in engineering
|
|
|
|
line 3: /blog/unknown/broken — unknown blog ID: unknown
|
|
"""
|
|
end
|
|
end
|