https://github.com/hissssst/repatch
Async-friendly Mocks and Patches in Elixir
https://github.com/hissssst/repatch
Last synced: 2 months ago
JSON representation
Async-friendly Mocks and Patches in Elixir
- Host: GitHub
- URL: https://github.com/hissssst/repatch
- Owner: hissssst
- License: other
- Created: 2024-10-15T18:50:50.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T14:06:52.000Z (12 months ago)
- Last Synced: 2024-10-25T22:22:30.838Z (12 months ago)
- Language: Elixir
- Homepage:
- Size: 39.1 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Repatch
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 `iex` and remote shells.
## Installation
```elixir
def deps do
[
{:repatch, "~> 1.5"}
]
end
```## One-minute intro
> for ExUnit users
1. Add `Repatch.setup()` into your `test_helper.exs` file after the `ExUnit.start()`
2. `use Repatch.ExUnit` in your test module
3. Call `Repatch.patch/3` to change implementation of any function in any module.
### For example
```elixir
defmodule ThatsATest do
use ExUnit.Case, async: true
use Repatch.ExUnittest "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
```## Further reading
Please check out the [docs](https://hexdocs.pm/repatch) for all available features.
## Special thanks
To [`ihumanable`](https://github.com/ihumanable) for [`Patch`](https://hexdocs.pm/patch) library which was an inspiration and a good example for `Repatch`.