defmodule Foo
def bar(x), do: x
end
defmodule FooTest do
use ExUnit.Case, async: true
use MecksUnit.Case
# defmock Foo do
# def bar(_x), do: 1
# end
defmock Foo, preserve: true do
def bar(_x), do: 1
end
mocked_test "this should work" do
assert Foo.bar(nil) == 1
end
mocked_test "this should work as well" do
assert Foo.bar(nil) == 1
end
end
mix test test/foo_test.exs
FooTest
* test this should work as well (2.9ms)
1) test this should work as well (FooTest)
test/foo_test.exs:17
Assertion with == failed
code: assert Foo.bar(nil) == 1
left: nil
right: 1
stacktrace:
test/foo_test.exs:18: (test)
* test this should work (0.02ms)
2) test this should work (FooTest)
test/foo_test.exs:13
Assertion with == failed
code: assert Foo.bar(nil) == 1
left: nil
right: 1
stacktrace:
test/foo_test.exs:14: (test)
Finished in 0.04 seconds
2 tests, 2 failures
Randomized with seed 711881
By activating the first mock, the second one actually starts working.