Skip to content
Browse files

Match multiple substrings

  • Loading branch information...
1 parent 3136dd0 commit 5360de07e237759713805aa570462070c68658e5 @jqno jqno committed Mar 17, 2012
View
6 boite-test/src/main/scala/com/nummulus/boite/scalatest/BoiteMatchers.scala
@@ -12,14 +12,14 @@ object BoiteMatchers {
def apply(left: Box[_]) =
BePropertyMatchResult(left.isInstanceOf[Failure], "failure")
- def saying(message: String) =
+ def saying(messages: String*) =
new BePropertyMatcher[Box[_]] {
def apply(left: Box[_]) = {
val matches = left match {
- case Failure(e) => e.getMessage contains message
+ case Failure(e) => messages forall { e.getMessage contains _ }
case _ => false
}
- BePropertyMatchResult(matches, "failure with message \"" + message + "\"")
+ BePropertyMatchResult(matches, "failure saying " + messages.mkString("\"", "\", \"", "\""))
}
}
}
View
14 boite-test/src/test/scala/com/nummulus/boite/scalatest/FailMatcherTest.scala
@@ -46,14 +46,22 @@ class FailMatcherTest extends FlatSpec with ShouldMatchers {
anEmpty should not be a (failure saying aMessage)
}
- it should "match a partial message" in {
+ it should "match a substring" in {
aFailure should be a (failure saying "message")
}
+ it should "match several substrings" in {
+ aFailure should be a (failure saying ("this", "exception", "message"))
+ }
+
+ it should "not match if one substring doesn't match" in {
+ aFailure should not be a (failure saying ("this", "exception", "does not match"))
+ }
+
it should "give an appropriate error message" in {
val thrown = intercept[TestFailedException] {
- anEmpty should be a (failure saying aMessage)
+ anEmpty should be a (failure saying ("this", "exception", "message"))
}
- thrown.getMessage should include ("failure with message \"" + aMessage + "\"")
+ thrown.getMessage should include ("failure saying \"this\", \"exception\", \"message\"")
}
}

0 comments on commit 5360de0

Please sign in to comment.
Something went wrong with that request. Please try again.