Skip to content

Commit

Permalink
Merge pull request #160 from LLCampos/patch-1
Browse files Browse the repository at this point in the history
Add docs for specs2's CatsResource
  • Loading branch information
djspiewak authored May 23, 2021
2 parents 3739744 + 4977acc commit 14a6d8c
Showing 1 changed file with 34 additions and 0 deletions.
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

0 comments on commit 14a6d8c

Please sign in to comment.