When working through testing with FeatureSpec
and using scenario
, I have part of my code that sends a "failure" case class (i.e. ApplesNotAllowed
) and is used via a scalaz
disjunction.
Quick example:
val result = if (order.value != 10) {
-\/(ApplesNotSupported(orderNumber))
} else {
\/-Option.empty[Orange]
}
In my test suite, I can easily test for the case where I receive an Option.empty[Orange]
by expecting that it shouldBe None
. However, I do run into a problem when I want to test for the ApplesNotSupported
case class being returned. How would I expect this "failure" that will acknowledge the test as passing since we want the "failure" to happen? Whenever I try to run my scenario, I get the error:
Validation is not success ApplesNotSupported(orderNumber)
Tried using interrupt
does not solve the issue since it is not an exception, nor do we want to deliberately fail
the test. Could it be an issue with using scalaz
and ScalaTest
?
I am fairly new to functional programming and programming in Scala overall, so any resources or suggestions help as I do have trouble searching for documentation.