From 7439a71959f8cbefdfe2bab3e24a8e9e6f032069 Mon Sep 17 00:00:00 2001 From: Alexis Ruccius Date: Tue, 26 Aug 2025 19:32:56 +0200 Subject: [PATCH] Clarify Mox.allow/3 usage with deferred functions --- lib/mox.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/mox.ex b/lib/mox.ex index 8a8ae4c..2ae708b 100644 --- a/lib/mox.ex +++ b/lib/mox.ex @@ -760,6 +760,13 @@ defmodule Mox do allow(MyMock, self(), fn -> GenServer.whereis(Deferred) end) + This means that if the process isn’t started yet, you can pass a function + that resolves to the pid later. When the mock is invoked, + Mox will call this function. If it returns a pid, the call is allowed. + If it doesn’t, the expectation fails. + + This is especially useful when testing a `GenServer` that calls the mock during `init/1`, + since the server’s pid is not available until after `start_link/1`. """ @spec allow(mock, pid(), term()) :: mock when mock: t() def allow(mock, owner_pid, allowed_via) when is_atom(mock) and is_pid(owner_pid) do