diff --git a/lib/splode/error.ex b/lib/splode/error.ex index 2160496..4c8567c 100644 --- a/lib/splode/error.ex +++ b/lib/splode/error.ex @@ -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 diff --git a/test/splode/error_test.exs b/test/splode/error_test.exs new file mode 100644 index 0000000..26965f7 --- /dev/null +++ b/test/splode/error_test.exs @@ -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