Skip to content

rahuljayaraman/cswap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSwap

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

Usage

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

Installation

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.

About

Mocking library for elixir

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages