我刚刚在我的项目上升级了 Specs2,现在有些规范无法编译,不清楚为什么不能编译,这是规范:
"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")
}
}
(整个文件可以在这里看到)
编译器说:
找不到类型证据参数的隐式值 org.specs2.execute.AsResult[可序列化的产品] {中的“如果连接断开则验证失败” ^虽然我明白它在说什么,但考虑到我要返回
ok
或
failure
并且我要涵盖比赛中的所有情况,这没有任何意义。知道这里可能出了什么问题吗?
ok
,它是一个
MatchResult
,第二行使用
failure
,它返回一个
Result
。他们唯一常见的类型是
Product with Serializable
。修复方法只是使用
ok
的相反值,即
ko
:
factory.validate(connection) match {
case Failure(e) => ok("Connection successfully rejected")
case Success(c) => ko("should not have come here")
}
你也可以写
import org.specs2.execute._
...
factory.validate(connection) match {
case Failure(e) => Success("Connection successfully rejected")
case Success(c) => failure("should not have come here")
}
但是没有可用的
success(message: String)
方法来匹配相应的
failure
。我会将其添加到下一个specs2版本中以获得更好的对称性。