jjh42 / mock

Mocking library for Elixir language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot mock Logger.error/1

opened this issue · comments

Considering this code:

    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.

Yea, the limitation you mentioned is correct.

Could you send a PR to update the documentation?