Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package zio.test

import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test.environment.TestEnvironment
import zio.{Ref, ZIO}

object MutableRunnableSpecSpec
extends MutableRunnableSpec(
TestEnvironment.any ++ Ref.make(0).toLayer,
sequential >>> samples(10) >>> before(ZIO.service[Ref[Int]].flatMap(_.update(_ + 1)))
) {
testM("ref 1") {
assertM(ZIO.service[Ref[Int]].flatMap(_.get))(equalTo(1))
}

testM("ref 2") {
assertM(ZIO.service[Ref[Int]].flatMap(_.get))(equalTo(2))
}

testM("check samples") {
for {
ref <- ZIO.service[Ref[Int]]
_ <- checkM(Gen.anyInt.noShrink)(_ => assertM(ref.update(_ + 1))(anything))
value <- ref.get
} yield assert(value)(equalTo(13))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ import zio.test.environment.TestEnvironment
* }
* }}}
*/
class DefaultMutableRunnableSpec extends MutableRunnableSpec(ZLayer.identity[TestEnvironment])
class DefaultMutableRunnableSpec extends MutableRunnableSpec(ZLayer.identity[TestEnvironment], TestAspect.identity)
10 changes: 6 additions & 4 deletions test/shared/src/main/scala/zio/test/MutableRunnableSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.util.control.NoStackTrace
/**
* Syntax for writing test like
* {{{
* object MySpec extends MutableRunnableSpec(layer) {
* object MySpec extends MutableRunnableSpec(layer, aspect) {
* suite("foo") {
* testM("name") {
* } @@ ignore
Expand All @@ -23,8 +23,10 @@ import scala.util.control.NoStackTrace
* }
* }}}
*/
class MutableRunnableSpec[R <: Has[_]](layer: ZLayer[TestEnvironment, Throwable, R])
extends RunnableSpec[TestEnvironment, Any] {
class MutableRunnableSpec[R <: Has[_]](
layer: ZLayer[TestEnvironment, Throwable, R],
aspect: TestAspect[R, R, Any, Any]
) extends RunnableSpec[TestEnvironment, Any] {
self =>

private class InAnotherTestException(`type`: String, label: String)
Expand Down Expand Up @@ -127,7 +129,7 @@ class MutableRunnableSpec[R <: Has[_]](layer: ZLayer[TestEnvironment, Throwable,

final override def spec: ZSpec[Environment, Failure] = {
specBuilt = true
stack.head.toSpec.provideLayerShared(layer.mapError(TestFailure.fail))
(stack.head @@ aspect).toSpec.provideLayerShared(layer.mapError(TestFailure.fail))
}

override def aspects: List[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
Expand Down