I have some modules that I want to implement a protocol for:
defmodule A do
end
defmodule B do
end
defmodule Foo do
def all(), do: [A, B]
end
defprotocol Fooer do
def x(f)
end
defimpl Fooer, for: A do
def x(_), do: ""
end
defimpl Fooer, for: B do
def x(_), do: ""
end
and a simple test
defmodule FooerTest do
use ExUnit.Case, async: false
for fooer <- Foo.all() do
test "protocol implemented for #{inspect(fooer)}" do
assert "" == Fooer.x(unquote(fooer))
end
end
end
but running this test, I get:
1) test protocol implemented for A (FooerTest)
test/foo_test.exs:5
** (Protocol.UndefinedError) protocol Fooer not implemented for A of
type Atom. This protocol is implemented for the following type(s): B, A
code: assert "" == Fooer.x(unquote(fooer))
stacktrace:
(dashboard) lib/foo.ex:11: Fooer.impl_for!/1
(dashboard) lib/foo.ex:12: Fooer.x/1
test/foo_test.exs:6: (test)
2) test protocol implemented for B (FooerTest)
test/foo_test.exs:5
** (Protocol.UndefinedError) protocol Fooer not implemented for B of
type Atom. This protocol is implemented for the following type(s): B, A
code: assert "" == Fooer.x(unquote(fooer))
stacktrace:
(dashboard) lib/foo.ex:11: Fooer.impl_for!/1
(dashboard) lib/foo.ex:12: Fooer.x/1
test/foo_test.exs:6: (test)
I guess I’m running into some issues with the dynamic generation of the test or something similar? Anyone has an idea on how to fix this?