CustomAssertion allows users to create their own custom assertions for use in
assertTrue. They are constructed with CustomAssertion.make.
// Definitionsealedtrait Pet
caseclass Dog(hasBone: Boolean) extends Pet
caseclass Fish(bubbles: Double) extends Pet
caseclass 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)
}
)
CustomAssertion allows users to create their own custom assertions for use in
assertTrue
. They are constructed withCustomAssertion.make
.