如何验证一个集合包含一个子类



使用ScalaTest,可以直接测试对象是否属于特定的类,例如:

myPet shouldBe a [Dog]

但是我想做的是验证某个基类型的集合至少有一个特定的子类型。我想语法应该是这样的,但它不起作用:

myPets should contain a [Cat]

我可以用'exists'和'shouldBe true'达到同样的结果,但它不是很有表现力。

myPets.exists(_.isInstanceOf[Cat]) shouldBe true

这是我必须做的还是ScalaTest有一个我不知道的功能?

谢谢

atLeast(1, myPets) shouldBe a [Cat]应该工作,我相信(目前无法测试,仅基于http://www.scalatest.org/user_guide/using_matchers#inspectorShorthands的一个例子)。