Seq empty test with specs2

孤街浪徒 提交于 2019-12-05 06:08:24

I think the type mismatch error is caused by another bit of code than that which you've posted.

Your example should just work with:

ret must not be empty

I've tried and confirmed to be working correctly:

 "Seq beEmpty test" should {
    "just work" in {
      Seq("foo") must not be empty
    }
  }

You could run into trouble if you use multiple assertions per test, for example the following doesn't compile:

"Seq beEmpty test" should {
  "just work" in {
    List() must be empty
    Seq("foo") must not be empty
  }
}

Which is unexpected, but easily fixed by helping the compiler:

"Seq beEmpty test" should {
  "just work" in {
    List() must beEmpty
    Seq("foo") must not beEmpty
  }
}

Try using the specs2 matcher have size. Since the size can't be negative, if it's not zero, it must be greater than zero. Therefore, we could use:

ret must not have size (0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!