dashbitco / mox

Mocks and explicit contracts in Elixir
1.35k stars 77 forks source link

Mock only some tests #47

Closed tielur closed 6 years ago

tielur commented 6 years ago

Is there a way to use a Mock for only some tests?

I've seen the suggestion of calling Mox.defmock and Application.put_env in the test_helper.exs.

My problem is that I want to mock my behavior for some tests but when I test the actual implementation of the behavior I don't want to mock it.

I've tried moving the Mox.defmock and Application.put_env into a setup block for specific tests but it seems like calling Mox.defmock anywhere causes all tests to use the mock?

josevalim commented 6 years ago

Mox.defmock only defines the mock. Unless you are defining the mock with the name of an existing module, it should not affect your application at all. But not the Application.put_env call is global, so if you change it, you need to remember to revert its value back.

tielur commented 6 years ago

That makes sense, thanks José