gpt4 book ai didi

compiler-errors - Specs2结果与MatchResult

转载 作者:行者123 更新时间:2023-12-02 10:46:54 25 4
gpt4 key购买 nike

我正在迁移到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

最佳答案

第一行返回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)

关于compiler-errors - Specs2结果与MatchResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25149606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com