升级后寻找 Matcher[String] 的 ScalaCheck 规范

ScalaCheck spec seeking Matcher[String] after upgrade

从规范 2.4.13 升级到 3.7.1 后

"foo" should {
  "bar" >> prop((i: Int) =>
    i % 50 must be>= 0
  )
}

不再编译。它失败了

type mismatch;
[error]  found   : org.specs2.specification.core.Fragment
[error]  required: org.specs2.matcher.Matcher[String]
[error]     "bar" >> prop((i: Int) =>
[error]           ^

改成

  "foo" >> {
    "bar" >> prop((i: Int) =>
      i % 50 must be>= 0
    )
  }

将允许它编译通过。

should 的行为是否已更改?

我在 3.8.8 中没有遇到这样的错误。然而,这可能是 should 用于示例块和 should 作为匹配器构造 (a should be_>=(0)) 的结果。

您可以通过 mixing-in org.specs2.matcher.NoShouldExpectations

删除后一种用法