Skip to content

Instantly share code, notes, and snippets.

@rhyskeepence
Created October 17, 2012 16:47
Show Gist options
  • Save rhyskeepence/3906667 to your computer and use it in GitHub Desktop.
Save rhyskeepence/3906667 to your computer and use it in GitHub Desktop.
specs2 beSomeMatching
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