Mau*_*res 2 compiler-construction unit-testing scala type-inference specs2
我刚刚在我的项目上升级了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")
}
}
Run Code Online (Sandbox Code Playgroud)
(这里可以看到整个文件)
编译器说:
无法找到类型为org.specs2.execute.AsResult [带序列化的产品]的证据参数的隐含值"如果连接断开连接则验证失败"{^
虽然我理解它的意思,但是在我回来的时候没有任何意义ok,failure而且我在比赛中覆盖了所有情况.
知道这里有什么不对吗?
编译器正在尝试查找2个匹配分支的公共类型.第一行使用的ok是a MatchResult,第二行使用的failure是返回a 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")
}
Run Code Online (Sandbox Code Playgroud)
你也可以写
import org.specs2.execute._
...
factory.validate(connection) match {
case Failure(e) => Success("Connection successfully rejected")
case Success(c) => failure("should not have come here")
}
Run Code Online (Sandbox Code Playgroud)
但是没有success(message: String)可用的方法来匹配相应的failure.我将它添加到下一个specs2版本以获得更好的对称性.
| 归档时间: |
|
| 查看次数: |
3323 次 |
| 最近记录: |