In a specs2 test, how to validate the type of the return value of a function?
Say, the function:
trait P
trait C1 extends P
trait C2 extends P
def test(n:Int): P = if(n%2==0) new C1 else new C2
Test:
"test" should {
"return C1 when n is even" in {
val result = test(2)
// how to assert
// 'result' should have type of C1?
}
}
I want to know how to assert the type of value result
?
there is a haveClass
matcher:
class FooSpec extends Specification {
trait P
class C1 extends P
class C2 extends P
def test(n:Int): P = if(n%2==0) new C1 else new C2
"test" should {
"return C1 when n is even" in {
val result = test(2)
result must haveClass[C1]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With