test "test mock" do
with_mock Logger, [enable: fn(_) -> 42 end] do
assert Logger.enable("msg") == 42
end
with_mock Logger, [error: fn(_) -> 42 end] do
assert Logger.error("msg") == 42
end
end
The first assertion will pass but the second one will fail with Erlang error: {:undefined_function, {Logger, :error, 1}}. I suspect this is because Logger.error/1 is macro while Logger.enable/1 is a regular function. However I didn't see any mention of this limitation in the doc so I'm wondering if I might be missing something.
I can work around this by defining a wrapper function in my code that just calls Logger.error/1 and call/mock that wrapper function instead.
Considering this code:
The first assertion will pass but the second one will fail with
Erlang error: {:undefined_function, {Logger, :error, 1}}
. I suspect this is becauseLogger.error/1
is macro whileLogger.enable/1
is a regular function. However I didn't see any mention of this limitation in the doc so I'm wondering if I might be missing something.I can work around this by defining a wrapper function in my code that just calls
Logger.error/1
and call/mock that wrapper function instead.