I’m working with elixir and am seeing confusing/undesirable behavior when using Mox.
I just want to use a mock for a single test module. Let’s say I have 2 tests. Here is sample code:
defmodule MyTest do
setup_all do
defmock(DateTimeMock, for: DateTimeApi)
:ok
end
test "test1" do
{:ok, expected_datetime, _} = DateTime.from_iso8601("2019-09-08T00:00:00.000000Z")
expect(DateTimeMock, :utc_now, fn _ -> expected_datetime end)
end
test "test2" do
expect(something else)
end
end
defmodule MyTest2 do
setup_all do
defmock(DateTimeMock, for: DateTimeApi)
:ok
end
test "test1" do
end
test "test2" do
end
end
When MyTest2 runs I will see the error: (Mox.UnexpectedCallError) no expectation defined
Defining a mock for a single test ‘leaks’ out and affects all tests.
Does Mox have a way to revert the mocked module back to the original module after the test has finished?