Skip to content

Commit 89e22d7

Browse files
Clarify Mox.allow/3 usage with deferred functions (#166)
1 parent 20e3ac9 commit 89e22d7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/mox.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,13 @@ defmodule Mox do
760760
761761
allow(MyMock, self(), fn -> GenServer.whereis(Deferred) end)
762762
763+
This means that if the process isn’t started yet, you can pass a function
764+
that resolves to the pid later. When the mock is invoked,
765+
Mox will call this function. If it returns a pid, the call is allowed.
766+
If it doesn’t, the expectation fails.
767+
768+
This is especially useful when testing a `GenServer` that calls the mock during `init/1`,
769+
since the server’s pid is not available until after `start_link/1`.
763770
"""
764771
@spec allow(mock, pid(), term()) :: mock when mock: t()
765772
def allow(mock, owner_pid, allowed_via) when is_atom(mock) and is_pid(owner_pid) do

0 commit comments

Comments
 (0)