Convert ErrorIgnorer tests to doctests

This commit is contained in:
Claudio Ortolina
2026-04-19 07:50:39 +01:00
parent 06ae5f8271
commit 45236e4b10
2 changed files with 24 additions and 18 deletions
+23
View File
@@ -12,6 +12,29 @@ defmodule MusicLibrary.ErrorIgnorer do
to_string(Phoenix.Router.NoRouteError)
]
@doc """
Returns `true` when the error kind should not be tracked.
## Examples
iex> MusicLibrary.ErrorIgnorer.ignore?(
...> %ErrorTracker.Error{kind: "Elixir.Phoenix.Router.NoRouteError"},
...> %{}
...> )
true
iex> MusicLibrary.ErrorIgnorer.ignore?(
...> %ErrorTracker.Error{kind: "Elixir.RuntimeError"},
...> %{}
...> )
false
iex> MusicLibrary.ErrorIgnorer.ignore?(
...> %ErrorTracker.Error{kind: "Elixir.Ecto.NoResultsError"},
...> %{}
...> )
false
"""
@impl true
def ignore?(%ErrorTracker.Error{kind: kind}, _context) when kind in @ignored_kinds, do: true
def ignore?(_error, _context), do: false
+1 -18
View File
@@ -1,22 +1,5 @@
defmodule MusicLibrary.ErrorIgnorerTest do
use ExUnit.Case, async: true
alias MusicLibrary.ErrorIgnorer
describe "ignore?/2" do
test "ignores Phoenix.Router.NoRouteError" do
error = %ErrorTracker.Error{kind: "Elixir.Phoenix.Router.NoRouteError"}
assert ErrorIgnorer.ignore?(error, %{}) == true
end
test "does not ignore other error kinds" do
error = %ErrorTracker.Error{kind: "Elixir.RuntimeError"}
assert ErrorIgnorer.ignore?(error, %{}) == false
end
test "does not ignore Ecto.NoResultsError" do
error = %ErrorTracker.Error{kind: "Elixir.Ecto.NoResultsError"}
assert ErrorIgnorer.ignore?(error, %{}) == false
end
end
doctest MusicLibrary.ErrorIgnorer
end