0

With ScalaTest, it's straightforward enough to test that an object is of a particular class with something like:

myPet shouldBe a [Dog]

But what I would like to do is verify that a collection of some base type has at least one of a particular sub type. I imagine the syntax could look something like this but it doesn't work:

myPets should contain a [Cat]

I can achieve the same result with 'exists' and 'shouldBe true' but it's not quite as expressive.

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

Is this what I have to do or is there a feature of ScalaTest that I'm not aware of?

Thank you

Jason Nesbitt
  • 730
  • 1
  • 6
  • 15

1 Answers1

2

atLeast(1, myPets) shouldBe a [Cat] should work, I believe (can't test at the moment, based just on an example from http://www.scalatest.org/user_guide/using_matchers#inspectorShorthands).

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487