Repatch
Async-friendly Mocks and Patches in Elixir
Install / Use
/learn @hissssst/RepatchREADME
Repatch
<!-- MDOC -->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.
Features
-
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.
Installation
def deps do
[
{:repatch, "~> 1.5"}
]
end
One-minute intro
for 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.
For example
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
end
<!-- MDOC -->
Further reading
Please check out the docs for all available features.
Special thanks
To ihumanable for Patch library which was an inspiration and a good example for Repatch.
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
