【发布时间】:2016-11-25 05:40:43
【问题描述】:
我使用的是 specs2,我的理解是 must 和 should 是等效的(请参阅 What is the difference between should and must in scala testing?),使用其中一个只是个人喜好。
但是,在比较字符串时,使用must 的以下测试有效:
import org.specs2.mutable._
class StringEqualWithMust extends Specification {
"string comp " should {
"abc" must beEqualTo("abc")
}
}
但使用 should 的相同测试无法编译:
import org.specs2.mutable._
class StringEqualWithShould extends Specification {
"string comp " should {
"abc" should beEqualTo("abc")
}
}
编译错误是:
StringEqualWithShould.scala:7: overloaded method value should with alternatives:
[error] (fs: => org.specs2.specification.core.Fragments)(implicit p1: org.specs2.control.ImplicitParameters.ImplicitParam1)org.specs2.specification.core.Fragments <and>
[error] (f: => org.specs2.specification.core.Fragment)org.specs2.specification.core.Fragment
[error] cannot be applied to (org.specs2.matcher.BeEqualTo)
[error] "abc" should beEqualTo("abc")
[error] ^
[error] one error found
为什么比较字符串时must 和should 有区别?
我正在使用 sbt 0.13.8、scala 2.12.0 和 specs2 3.8.6
【问题讨论】:
-
可变规范的预期结构是
should(>>>) >in和must带有匹配器 -
您使用的是哪个版本的 specs2?你可以试试
3.8.6吗? -
与 3.8.6 版结果相同