Mix.install([:flame, :plug, :req])
defmodule Server do
use GenServer
def init(opts) do
{callers, opts} = Keyword.pop!(opts, :callers)
Process.put(:"$callers", callers)
Req.request!(opts) # more likely this would be a Repo call, failing with Ecto sandbox
{:ok, opts}
end
def start_link(opts) do
callers = Process.get(:"$callers", [])
opts = Keyword.put_new(opts, :callers, callers)
GenServer.start_link(__MODULE__, opts)
end
end
ExUnit.start(autorun: false)
defmodule ServerTest do
use ExUnit.Case, async: true
test "can start" do
Req.Test.stub(__MODULE__, &Req.Test.text(&1, "ok"))
_pid = start_supervised!({Server, plug: {Req.Test, __MODULE__}})
# Req.Test.allow(__MODULE__, self(), pid)
end
end
ExUnit.run()