Spyanator v0.0.3 Spyanator

The main interface to starting and tracking the Spyanator agent and any Spyanator related agents.

This module is used with Spyanator.Macro to track calls, return values and arguments sent to spys.

To create a spy, you must use Spyanator and define functions like normal

  defmodule TestTheThing do
    use ExUnit.Case, async: true

    defmodule AgentSpy do
      use Spyanator

      def start(_fn, opts), do: {:ok, nil}
    end

    def start_spy(_context), do:
      {:ok, spy: Spyanator.start_spy(AgentSpy)}

      describe "when the thing is doing the thing" do
        setup [:start_spy]

        test "it does the thing" do
          #...
        end
      end
  end

Spyanator also provides helper functions to use within your tests. These functions live in Spyanator.Assertions

  defmodule TestAnotherThing do
    use ExUnit.Case, async: true
    use Spyanator.Assertions

    #...

    test "it calls :the_function" do
      assert Spy |> received(:the_function) |> once
    end
  end

For more detail, please see Spyanator.Assertions

Summary

Functions

Get the PID for a running spy module

Increments the number of calls to the given function for the given module

Starts the Spyanator process. The process is named Spyanator

Used to start a spy module. Required before any call tracking can be done

Tracks the arguments provided to the function

tracks the returned value for the given function on the given module. Assumes that the value was a result of the last call

Functions

get_pid_for_module(module)
get_pid_for_module(module) :: pid

Get the PID for a running spy module

increment_calls_to(module, func_name)
increment_calls_to(module, atom) :: integer

Increments the number of calls to the given function for the given module

start_link(opts \\ [])

Starts the Spyanator process. The process is named Spyanator

start_spy(spy_module)
start_spy(module) :: {:ok, pid}

Used to start a spy module. Required before any call tracking can be done.

track_arguments_to(module, func_name, args_list)
track_arguments_to(module, atom, [any]) :: :ok

Tracks the arguments provided to the function.

track_return_value_from(module, func_name, value)
track_return_value_from(module, atom, any) :: :ok

tracks the returned value for the given function on the given module. Assumes that the value was a result of the last call.