首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Specs2结果与MatchResult

Specs2结果与MatchResult
EN

Stack Overflow用户
提问于 2014-08-05 22:53:13
回答 1查看 157关注 0票数 1

我要迁移到Specs2 2。

这用于编译

代码语言:javascript
复制
if(foo) {
    bar mustBe equalTo(1)
} else {
    skipped("foo was false")
}

但现在不再是

代码语言:javascript
复制
could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[Object]

我该怎么办?

版本2.3.13

EN

回答 1

Stack Overflow用户

发布于 2014-08-06 23:04:15

第一行返回Matcher[T],第二行返回Result。这两个类型统一为Object,这就是您获得这样一个编译消息的原因。

要解决这个问题,您可以使用以下助手函数:

代码语言:javascript
复制
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
}

还有其他方法可以跳过用户指南中描述的示例

代码语言:javascript
复制
"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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25149606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档