fix: Splode.Error.message/1 (#7)

This commit is contained in:
Jechol Lee 2024-04-29 20:28:01 +09:00 committed by GitHub
parent 4008406973
commit 61d76e5be3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -123,7 +123,7 @@ defmodule Splode.Error do
Enum.reduce(List.wrap(vars), string, fn {key, value}, acc ->
if String.contains?(acc, "%{#{key}}") do
String.replace(acc, "%{#{key}}", to_string(value))
String.replace(acc, "%{#{key}}", inspect(value))
else
acc
end

View file

@ -0,0 +1,12 @@
defmodule Splode.ErrorTest do
use ExUnit.Case
defmodule InvalidAttribute do
use Splode.Error, fields: [:message], class: :invalid
end
test "message" do
invalid = %InvalidAttribute{message: "must be in %{list}", vars: [list: [:foo, :bar]]}
assert "must be in [:foo, :bar]" == invalid |> Exception.message()
end
end