CustomAssertion

zio.test.CustomAssertion
See theCustomAssertion companion object
final class CustomAssertion[A, B]

CustomAssertion allows users to create their own custom assertions for use in assertTrue. They are constructed with CustomAssertion.make.

// Definition
sealed trait Pet
case class Dog(hasBone: Boolean) extends Pet
case class Fish(bubbles: Double) extends Pet
case class Cat(livesRemaining: Int) extends Color

val lives =
 CustomAssertion.make[Pet] {
   case Cat(livesRemaining) => Right(livesRemaining)
   case other => Left(s"Expected $$other to be Cat")
 }

// Usage
suite("custom assertions")(
 test("as even") {
   val pet: Option[Pet] = Some(Cat(8))
   assertTrue(pet.is(_.some.custom(lives)) == 8)
 }
)

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view