The trick is to declare an implicit class to consider "reflect" as a method of the result of ("False"
should
not
) of type ResultOfNotWordForAny[String]
.
def parseB(string : String)(implicit context : Context) : Float = parseAll(gexp, string).get.eval(context).left.get
implicit var context = Context()
parseB("False") should be(false)
parseB("False") should not be(true)
// Declares an implicit class for applying after not. Note the use of '!='
implicit class ReflectShouldMatcher(s: ResultOfNotWordForAny[String]) {
def reflect(value: Boolean) = s be(BeMatcher[String] {
left => MatchResult(parseB(left) != value, "", "")
})
}
// Declares an explicit method for applying after should. Note the use of '=='
def reflect(right: Boolean) = Matcher[String]{ left =>
MatchResult(parseB(left) == right, "", "")}
// Now it works. Note that the second example can be written with or wo parentheses.
"False" should reflect(false)
"False" should not reflect true