Some more Matchers

We covered the most basic of the Matchers in the previous section. Further on, we have some more Matchers that are not as generic as the basic Matchers from last section.

Matchers for containers

We can test if a container has a particular element:

listOfNames should contain("Bob")

This can be used with any type T that has an implicit type org.scalatest.enabler.Containing[T]. In the Containing companion object, implicits are provided for types GenTraversable[E], java.util.Collection[E], java.util.Map[K, V], StringArray[E], and Option[E].

 (List("Hi", "Di", "Ho") should contain ("ho")) (after being lowerCased)

Note that when you use the explicitly DSL with contain, you need to wrap the entire contain expression in parentheses.

The ...

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.