View Source Efx (Efx v0.1.1)

A module to be used to define effects.

An effect is a function that executes side effects and thus is hard to test or even untestable. With the effects abstraction we can define mockable effect-functions comfortably.

Since effects are used on a module level utilizing the use-macro, all effect-functions defined inside build a group. We can later either bind all or none of this functions.

This module provides macros for implementing effects that are expanded into a mockable behaviour, e.g.

defmodule MyEffect do
  use Efx

  @spec read_numbers(String.t()) :: integer()
  defeffect read_numbers(id) do
    :default_implementation
  end

  @spec write_numbers(String.t(), integer()) :: :ok
  defeffect read_numbers(id, numbers) do
    :default_implementation
  end
end

The above example generates a behaviour with the callbacks

@callback read_numbers(String.t()) :: integer()
@callback write_numbers(String.t(), integer()) :: :ok

This module is meant to be used in conjuction with the mocking test helpers found in EfxCase.

Summary

Functions

Link to this macro

defeffect(fun, do_block)

View Source (macro)