A dependency-free Finitomata.Listener implementation for tests.
Declaring listener: Finitomata.ExUnit.Listener on an FSM lets Finitomata.ExUnit
drive and assert transitions without Mox. On every successful transition it
forwards a {:on_transition, fsm_name, state, payload} message — the exact shape the
Finitomata.ExUnit assertions expect — to the test process that registered itself for
that FSM.
The test process is looked up through the per-id Finitomata Registry that
setup_finitomata/1 (via init_finitomata/6) already starts, so no extra process or
global state is involved, and the registration is dropped automatically when the test
process exits.
Usage
defmodule MyFSM do
use Finitomata, fsm: @fsm, listener: Finitomata.ExUnit.Listener
endIn :test/:dev only, pick the listener conditionally to keep production lean:
@listener if Mix.env() == :test, do: Finitomata.ExUnit.Listener
use Finitomata, fsm: @fsm, listener: @listenerThen write the test exactly as with the :mox listener, but without import Mox:
import Finitomata.ExUnit
describe "MyFSM" do
setup_finitomata do
[fsm: [implementation: MyFSM, payload: %{}]]
end
test_path "happy path", _ctx do
:go -> assert_state :done
end
end
Summary
Functions
Registers the calling (test) process to receive {:on_transition, fsm_name, state, payload}
notifications for the FSM identified by fsm_name (its fully-qualified :via tuple).
Functions
@spec register(Finitomata.fsm_name()) :: :ok
Registers the calling (test) process to receive {:on_transition, fsm_name, state, payload}
notifications for the FSM identified by fsm_name (its fully-qualified :via tuple).