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.
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]
, String
, Array[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 other DSLs we can use with contain is one of
, atLeastOneOf
, and noneOf
. Here are some examples:
List(1, 2, 3, 4, 5) should contain oneOf (5, 7, 9) List(1, 2, 3, 4, 5) should contain noneOf (7, 8, 9) Some(0) should contain noneOf (7, 8, 9)&...