Боль:scala specs2 - как совместить список шаблонов или критериев?
val someString = "how are you today?"
val expectedWordsInStringList = List("how", "you")
Как я могу соответствовать, что строка содержит все ожидаемые слова?
//would of liked to have: (there is no method containAllElements)
someString must containAllElements(expectedWordsInStringList)
Законченное писать этот тест (и не доволен результатом)
class HowToMatchListOfMatcher extends Specification {
"HowToMatchListOfMatcher" should {
"not use reduce to match on list of matchers" in {
val testString = "some string with 1 and 2"
val containList:List[String] = List("1", "2")
val matcherList:List[Matcher[String]] = List(contain("1"), contain("2"))
def matchAll(matcherList: List[Matcher[String]]) = matcherList.reduce((m1,m2)=> m1 and m2)
//how can i match this without reduce ? or with using the containList
testString must matchAll(matcherList)
}
}
}
я бы ожидал specs2 есть из коробки согласовани для списка элементов – Nimrod007
@ Nimrod007 Существует 'containAllOf [T ] (seq: Seq [T]) 'в признаке' org.specs2.matcher.TraversableBaseMatchers'. Однако я не уверен, что это полезно, поскольку существуют явные 'StringBaseMatchers' (такие как метод' contains', который вы используете), и я не могу найти что-то вроде 'containsAllOf'. –