compiler-errors - Specs2结果与MatchResult

标签 compiler-errors specs2

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

相关文章:

specs2 - 为什么 ScalaCheck 在我的规范中丢弃这么多生成的值?

scala - 在 sbt 0.10 中为 specs2 测试配置 junitxml 输出

xcode - 字符串在Swift中没有名为 'text'的成员错误

javascript - HTML 元素数组的类型错误

vue.js - 使用 "v-if"指令时,控制台出现错误。无限循环

c - 为什么缺少终止“字符是一个警告?

scala - 使用测试配置玩 2.0 FakeApplication 设置

scala specs2 错误 : anon is not equal scala. collection.immutable

scala - specs2 验收测试中的案例类上下文 : "must is not a member of Int"

c++ - "error: invalid conversion from ' int' 到 'int (*)[8]' [-fpermissive] 的含义是什么?