ScriptedResponder
class ScriptedResponder<Request, Response>(outcomes: List<Result<Response>>, fallback: Result<Response>? = null)(source)
A scripted fake that records each request and answers it with the next scripted outcome.
Forward each call of an injected dependency to respond. Calls are numbered from zero in arrival order, and call n always receives outcome n, even when an earlier call is held and finishes later. hold returns a gate that suspends one call after it is recorded and before it is answered, so a test can observe in-flight state deterministically.
val responder = ScriptedResponder<String, Int>(listOf(Result.failure(TestError()), Result.success(42)))
val fetch: suspend (String) -> Int = responder::respondContent copied to clipboard
Parameters
outcomes
Successes and failures, indexed by call number.
fallback
The outcome for calls after the script is used; null throws Exhausted.