Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for specs2's CatsResource #160

Merged
merged 1 commit into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ override val Timeout = 5.seconds

If you need an `ExecutionContext`, one is available in the `executionContext` val.

And if you need to share Cats Effect's Resource between test examples you can extend `CatsResource`, like so:

```scala
import cats.effect.{IO, Ref, Resource}
import org.specs2.mutable.SpecificationLike

class CatsResourceSpecs extends CatsResource[IO, Ref[IO, Int]] with SpecificationLike {
sequential

val resource: Resource[IO, Ref[IO, Int]] =
Resource.make(Ref[IO].of(0))(_.set(Int.MinValue))

"cats resource support" should {
"run a resource modification" in withResource { ref =>
ref.modify{ a =>
(a + 1, a)
}.map(
_ must_=== 0
)
}

"be shared between tests" in withResource { ref =>
ref.modify{ a =>
(a + 1, a)
}.map(
_ must_=== 1
)
}
}
}
```

The Resource is acquired before the tests are run and released afterwards. A more realistic example would be to share a Resource that takes a long time to start up.

### Usage

```sbt
Expand Down