Search code examples
stringscalascalatestmatcher

String includes many substrings in ScalaTest Matchers


I need to check that one string contains many substrings. The following works

string should include ("seven")
string should include ("eight")
string should include ("nine")

but it takes three almost duplicated lines. I'm looking for something like

string should contain allOf ("seven", "eight", "nine")

however this doesn't work... The assertion just fails while string contains these substrings for sure.

How can I perform such assertion in one line?


Solution

  • Try this:

    string should (include("seven") and include("eight") and include("nine"))