test "verify something from a token", %{conn: conn} do
{:ok, agent_pid} = Agent.start_link(fn -> nil end)
capture_token = fn token ->
Agent.update(agent_pid, fn _ -> token end)
end
MyApp.SomeContext.send_verification_email(&capture_token.(&1))
token = Agent.get(token_agent, & &1)
assert something(token)
end
Here is a neat little trick when you need to test a verification flow in #PhoenixFramework: gist.github.com/wmnnd/cb80d4...
It's a common pattern to pass a URL generator to a context function. But you can pass a function that captures the token with an Agent instead.
#elixirlang #myelixirstatus