Repatch is a library for efficient, ergonomic and concise mocking/patching in tests (or not tests). It provides an efficient and async-friendly replacement for Mox, ProtoMock, Patch, Mock and all other similar libraries.
-
Patches any function or macro. Elixir or Erlang, private or public (except BIF/NIF).
-
Async friendly. With local, global, and allowances modes.
-
Boilerplate-free. But you still can leverage classic explicit DI with Repatch.
-
Call history.
-
Built-in async-friendly application env. See
Repatch.Application. -
Mock behaviour and protocol implementation generation. See
Repatch.Mock -
Supports expect-style mocking. See
Repatch.Expectations -
Testing framework agnostic. It even works in
iexand remote shells.
def deps do
[
{:repatch, "~> 1.5"}
]
endfor ExUnit users
-
Add
Repatch.setup()into yourtest_helper.exsfile after theExUnit.start() -
use Repatch.ExUnitin your test module -
Call
Repatch.patch/3to change implementation of any function in any module.
defmodule ThatsATest do
use ExUnit.Case, async: true
use Repatch.ExUnit
test "that's not a MapSet.new" do
Repatch.patch(MapSet, :new, fn _list ->
%{thats_not: :a_map_set}
end)
assert MapSet.new([1, 2, 3]) == %{thats_not: :a_map_set}
assert Repatch.called?(MapSet, :new, 1)
end
endPlease check out the docs for all available features.
To ihumanable for Patch library which was an inspiration and a good example for Repatch.