Test helpers for stubbing Twilio HTTP requests.
Uses NimbleOwnership for per-process stub isolation,
enabling async: true tests.
Usage
setup do
Twilio.Test.stub(fn method, url, headers, body ->
{200, [], ~s({"sid": "SM123"})}
end)
client = Twilio.client("ACtest", "token")
{:ok, client: client}
end
test "sends a message", %{client: client} do
assert {:ok, msg} = Twilio.Api.V2010.MessageService.create(client, params)
assert msg["sid"] == "SM123"
end
Summary
Functions
Allow another process to use the current process's stub.
Start the ownership server. Called from test_helper.exs.
Register a stub function for the current test process.
Functions
@spec allow(pid()) :: :ok
Allow another process to use the current process's stub.
Start the ownership server. Called from test_helper.exs.
@spec stub((String.t(), String.t(), list(), String.t() | nil -> {integer(), list(), String.t()})) :: :ok
Register a stub function for the current test process.
The function receives (method, url, headers, body) and must return
{status, headers, body}.