I have just upgraded Specs2 on my project and now some specs won't compile and it isn't clear why they're not, here's the spec:
"fail validation if a connection is disconnected" in {
val connection = factory.create
awaitFuture(connection.disconnect)
factory.validate(connection) match {
case Failure(e) => ok("Connection successfully rejected")
case Success(c) => failure("should not have come here")
}
}
(The whole file can be seen here)
And the compiler says:
could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[Product with Serializable] "fail validation if a connection is disconnected" in { ^
And while I understand what it is saying, it doesn't make any sense given I am returning ok
or failure
and I'm covering all cases on my match.
Any idea what could be wrong here?
The compiler is trying to find the common type of the 2 match branches. The first line is using
ok
which is aMatchResult
and the second line is usingfailure
which is returning aResult
. Their only common type isProduct with Serializable
.The fix is simply to use the opposite value of
ok
which isko
:You could also write
There is however no
success(message: String)
method available to match the correspondingfailure
. I will add it to the next specs2 version for better symmetry.