O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required