Created
October 17, 2012 16:47
-
-
Save rhyskeepence/3906667 to your computer and use it in GitHub Desktop.
specs2 beSomeMatching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.specs2.matcher | |
object ExtraOptionMatchers { | |
def beSomeMatching[T](someValueMatcher: =>Matcher[T]) = new Matcher[Option[T]] { | |
def apply[S <: Option[T]](value: Expectable[S]) = value.value match { | |
case Some(x) => matchSome(value) | |
case None => MatchFailure( | |
value.description + " is Some", | |
value.description + " is not Some", | |
value) | |
} | |
def matchSome[S <: Option[T]](expectable: Expectable[S]): MatchResult[S] = { | |
val value = expectable.value.get | |
val matchResult = someValueMatcher(Expectable(value)) | |
result(matchResult, expectable) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment