Mocking library for elixir
- Supports concurrent mocking across process boundaries using :seq_trace
- Supports a decorator to swap code for test builds, using arjan/decorator
Mark code as mockable
using the decorator.
defmodule Module do
use CSwap.Decorator
@decorate mockable()
def exec(), do: :original
# Not mockable
def exec2(), do: :original
end
Use CSwap.mock(module, function_name, mock_fn)
to mock
defmodule ModuleTest do
use ExUnit.Case
test "mocks" do
assert_raise CSwap.NotMockedError, fn -> Module.exec() end
ref = make_ref()
:ok = CSwap.mock(Module, :exec, fn -> ref end)
assert Module.exec() == ref
end
end
If available in Hex, the package can be installed
by adding cswap
to your list of dependencies in mix.exs
:
def deps do
[
{:cswap, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/cswap.