Delx v1.0.1 Delx.TestAssertions View Source

A module that contains assertions for ExUnit to test function delegation.

Note that you need to activate stubbing for your test environment in order to make the assertions work. In your config/text.exs file:

config :delx, :stub, true

Link to this section Summary

Functions

Asserts whether the function specified by MFA (module-function-arity tuple) is delegated to the the given target module. Accepts the same options as the Kernel.defdelegate/2 macro.

Refutes whether the function specified by MFA (module-function-arity tuple) is delegated to the the given target module. Accepts the same options as the Kernel.defdelegate/2 macro.

Link to this section Functions

Link to this function

assert_delegate(arg, opts \\ []) View Source
assert_delegate(mfa(), Keyword.t()) :: no_return()

Asserts whether the function specified by MFA (module-function-arity tuple) is delegated to the the given target module. Accepts the same options as the Kernel.defdelegate/2 macro.

Options

  • :to - The module to which the function delegates to.
  • :as - The name of the function in the target module.

Example

defmodule GreeterTest do
  use ExUnit.Case

  import Delx.TestAssertions

  describe "hello/1" do
    test "delegate to Greeter.StringGreeter" do
      assert_delegate {Greeter, :hello, 1}, to: Greeter.StringGreeter
    end
  end
end
Link to this function

refute_delegate(arg, opts \\ []) View Source

Refutes whether the function specified by MFA (module-function-arity tuple) is delegated to the the given target module. Accepts the same options as the Kernel.defdelegate/2 macro.

Options

  • :to - The module to which the function delegates to.
  • :as - The name of the function in the target module.

Example

defmodule GreeterTest do
  use ExUnit.Case

  import Delx.TestAssertions

  describe "hello/1" do
    test "delegate to Greeter.StringGreeter" do
      refute_delegate {Greeter, :hello, 1}, to: Greeter.StringGreeter
    end
  end
end