jjh42 / mock

Mocking library for Elixir language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to mock function called from function in same module

LLay opened this issue · comments

Expected Behavior

with_mocks successfully mocks a function in a module (separate from the testing module) that is called from a function in the same module.

Current Behavior

The function is not mocked

Steps to Reproduce

git clone https://github.com/LLay/mock_test.git
mix deps.get
mix test

Result should be:

$ mix test
.

  1) test bar is mocked when called from own module (MockerTest)
     test/mocker_test.exs:12
     Assertion with == failed
     code:  assert Mocker.foo() == :mocked
     left:  :bar
     right: :mocked
     stacktrace:
       test/mocker_test.exs:14: (test)



Finished in 0.06 seconds
2 tests, 1 failure

Context (Environment)

Demo (from above): https://github.com/LLay/mock_test

MacBook-Pro:mocker user1$  asdf current
elixir         1.6.5 
erlang         20.2.3 

Conversation

I'm guessing this behavior is occurring because the caller function (foo in my example) is compiled before the mocked version of function in question (bar) is. Is there any way around this?

Note that this is not an issue with :passthrough. Removing this option only leads to the caller (foo) being undefined

Would you say this is a duplicate of #71?

Yes looks like it is. You may close this as a duplicate.