Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to mock function called from function in same module #95

Closed
LLay opened this issue Dec 11, 2018 · 2 comments
Closed

Fails to mock function called from function in same module #95

LLay opened this issue Dec 11, 2018 · 2 comments

Comments

@LLay
Copy link

LLay commented Dec 11, 2018

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

@Olshansk
Copy link
Collaborator

Would you say this is a duplicate of #71?

@LLay
Copy link
Author

LLay commented Dec 14, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants