Skip to content

TestResourceScope

A scope to combine Arrow's ResourceScope with Prepared's TestDsl.

This scope is used within tests that declare resources.

Resources declared in this scope are released at the end of the test.

Instances of this type can be obtained:

Additionally:

  • The install functions allows binding a resource directly within a test.

  • The asPrepared function converts a Resource into a Prepared value, Prepared's equivalent concept.

Properties

environment

Functions

autoClose

open fun <A> autoClose(acquire: () -> A, release: (A, Throwable?) -> Unit): A

bind

open suspend fun <A> Resource<A>.bind(): A

immediate

open suspend fun <T> PreparedProvider<T>.immediate(name: String): T

install

@IgnorableReturnValue
open fun <A : AutoCloseable> install(autoCloseable: A): A
open suspend fun <A> install(acquire: suspend AcquireStep.() -> A, release: suspend (A, ExitCase) -> Unit): A

install

suspend fun <A> TestDsl.install(acquire: suspend TestDsl.() -> A, release: suspend TestDsl.(A, ExitCase) -> Unit): A

Installs an acquire action and its matching release action.

This is a convenience equivalent of ResourceScope.install directly on the test. The behavior is identical to calling ResourceScope.install on the test's resourceScope.

External resources

Parameters

  • acquire: The acquire action, executed immediately.

  • release: The release action, executed at the end of the test.

See also

suspend fun <A> TestDsl.install(resource: Resource<A>): A

Installs a Resource into the test's lifecycle scope.

The resource is immediately installed. It is released at the end of the test.

This method has identical behavior to ResourceScope.bind on the test's resourceScope. It cannot be called .bind() because this would require two receivers, and context parameters are not yet stable.

External resources

See also

invoke

open suspend operator fun <T> Prepared<T>.invoke(): T

onClose

open override fun onClose(release: (Throwable?) -> Unit)

onRelease

abstract infix fun onRelease(release: suspend (ExitCase) -> Unit)

release

open infix suspend fun <A> Resource<A>.release(release: suspend (A) -> Unit): A

releaseCase

open infix suspend fun <A> Resource<A>.releaseCase(release: suspend (A, ExitCase) -> Unit): A

resourceScope

Allows accessing the test lifecycle as an Arrow's ResourceScope.

Resources installed in the returned scope are released at the end of the test.

External resources

See also