diff --git a/compat/compat-arrow/README.md b/compat/compat-arrow/README.md index f62b930..318c908 100644 --- a/compat/compat-arrow/README.md +++ b/compat/compat-arrow/README.md @@ -1,10 +1,12 @@ # Module Compatibility with Arrow -Helpers to fail tests when a function raises. +Helpers to fail tests when a function raises and to use resources. -### Example +# Package opensavvy.prepared.compat.arrow.core + +Helpers to integrate Arrow's Raise DSL into tests. Let's assume we want to test a function which raises when it receives a negative number: @@ -43,3 +45,36 @@ test("√-1 raises") { } } ``` + +# Package opensavvy.prepared.compat.arrow.coroutines + +Helpers to use Arrow's Resource DSL in tests. + +Let's assume that we want to test a service we own that is already encapsulated in a resource within your production code: + +```kotlin +val userProcessor: Resource = resource({ + UserProcessor().also { it.start() } +}) { p, _ -> p.shutdown() } + +val dataSource: Resource = resource({ + DataSource().also { it.connect() } +}) { ds, exitCase -> + println("Releasing $ds with exit: $exitCase") + withContext(Dispatchers.IO) { ds.close() } +} + +val service: Resource = resource { + Service(dataSource.bind(), userProcessor.bind()) +} +``` + +We can use [asPrepared][opensavvy.prepared.compat.arrow.coroutines.asPrepared] to convert that resource into Prepared's native [prepared values][opensavvy.prepared.suite.Prepared]: + +```kotlin +val preparedService by service.asPrepared() + +test("create() should not return null") { + check(preparedService().create() != null) +} +```