def test(a: Int, b: Int): Try[Int] = Try { a / b }
it.should("succeed").in { test(0, 1).map { res => assert(res === 1 / 2) /* assume more assertions are to be done and assertions can't be moved out */ } match { case Success(value) => value case Failure(exception) => fail(exception) } }
it.should("fail").in { test(1, 0).failure.exception.getClass.mustBe(classOf[java.lang.ArithmeticException]) }
Enter code here...class MiscTest extends WordSpecLike with Matchers {
"Divide" should {
"succeed" in { val result = divide(4, 2).toEither result should be('right) result.right.get should be(2) }
"fail" in { val result = divide(1, 0).toEither result should be('left) result.left.get should be(an[ArithmeticException]) } }