我正在迁移到Specs2 2。
这用于编译
if(foo) {
bar mustBe equalTo(1)
} else {
skipped("foo was false")
}
但不再
could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[Object]
我该怎么办?
版本2.3.13
答案 0 :(得分:1)
第一行返回Matcher[T]
,第二行返回Result
。这两种类型统一为Object
,这就是你得到这样一个编译信息的原因。
要解决此问题,您可以使用以下辅助函数:
def skipWhen[R : AsResult](condition: Boolean, message)(r: =>R): Result =
if (condition) skipped(message)
else AsResult(r)
"my example" >> skipWhen(serverIsDown, "server is down") {
1 must_== 1
}
还有其他方法可以跳过User Guide中描述的示例:
"my example is skipped" >> skipped {
sys.error("boom")
ok
}
"this will skip if the expectation is false" >> {
1 must beEqualTo(2).orSkip
}
"this will succeed if the condition is false" >> {
1 must beEqualTo(2).unless(condition)
}
// this will skip all the examples in the specification if the condition is true
skipAllIf(condition)