2

I'm using meck and it works great in most cases. However, I encountered the following error: elixir (ErlangError) erlang error: {:undefined_function, {OAuth2.Strategy.AuthCode, :new, 2}}

I found that :new was a function defined in OAuth2.Strategy's __using__ macro. That means :new wasn't defined OAuth2.Strategy.AuthCode. How do I mock out :new in this case?

Gjaldon
  • 5,534
  • 24
  • 32
  • Can't you mock the module where it was defined on? Maybe OAuth2.Strategy.new? – José Valim Mar 05 '15 at 17:47
  • Tried that but it doesn't work. I guess it's cos `new` is defined only when `OAuth2.Strategy` is used. Had to rely on creating another module and placed all the relevant code in a function there and mocking it out in my tests. – Gjaldon Mar 06 '15 at 10:34

1 Answers1

2

Meck creates mocks in runtime, thus it will never be able to mock macros in Elixir. If your macro eventually creates a function, that is then compiled into a module, you should be able to mock that (provided that you know the name of the function).

Adam Lindberg
  • 16,447
  • 6
  • 65
  • 85