MatchResult

org.specs2.matcher.MatchResult
See theMatchResult companion object
sealed trait MatchResult[+T] extends ResultLike

Result of a Match.

A MatchResult contains several information about a match on an expectable:

  • the expectable value, to allow the chaining of matches
  • a pair of messages ok message / ko message to allow the easy creation of the negation of a match

A MatchResult can be transformed to a simple Result object to be the body of an Example.

There are different kinds of MatchResults, some of them being only created to support English-like combination of Matchers:

1 must be equalTo(1) and not be equalTo(2)

In an Expectation like the one above, there is a left to right evaluation:

  1. be is a NeutralMatcher, returning a NeutralMatch doing nothing yet, just storing the expectable

  2. equalTo(1) is a real Matcher which is applied to the NeutralMatch MatchResult thanks to an implicit definition in the BeHaveAnyMatchers trait. This yields a MatchSuccess result

  3. not creates a NotMatcher and can be and-ed with the previous MatchSuccess to yield a AndMatch(MatchSuccess, NotMatch), with NotMatch being the result of applying the NotMatcher to the expectable. This AndMatch is evaluated to create a AndNotMatch(MatchSuccess, MatchSkip)

    Basically this is like forming an evaluation structure which will be resolved when the next 'real' matcher will arrive

  4. the AndNotMatch get nows it be method called with the equalTo Matcher. This results in equalTo being applied to the AndNotMatch, effectively doing: MatchSuccess and MatchSkip.apply(equalTo(2).not), which is MatchSuccess and expectable.applyMatcher(equalTo(2).not) which is MatchSuccess

Attributes

See also

org.specs2.matcher.BeHaveMatchersSpec for examples

Companion
object
Graph
Supertypes
trait ResultLike
class Object
trait Matchable
class Any
Known subtypes
class AndMatch[T]
class AndNotMatch[T]
class MatchFailure[T]
class MatchPending[T]
class MatchSkip[T]
class MatchSuccess[T]
class NeutralMatch[T]
class NotMatch[T]
class OrMatch[T]
class OrNotMatch[T]
Show all

Members list

Value members

Abstract methods

Attributes

Returns

the negation of this result

def setExpectable[S >: T](e: Expectable[S]): MatchResult[S]

set a different expectable for this matcher

set a different expectable for this matcher

Attributes

Concrete methods

alias for the apply method, to be used outside specs2

alias for the apply method, to be used outside specs2

Attributes

def be(m: Matcher[T]): MatchResult[T]

apply the matcher

apply the matcher

Attributes

def be[S >: T <: AnyRef](s: S): MatchResult[S]
def filterTrace(f: List[StackTraceElement] => List[StackTraceElement]): MatchResult[T]

filter the trace of this result (if there is one)

filter the trace of this result (if there is one)

Attributes

def have(m: Matcher[T]): MatchResult[T]

apply the matcher

apply the matcher

Attributes

def isSuccess: Boolean
def message: String
def mute: MatchResult[T]

Attributes

Returns

the MatchResult with no messages

def setMessage(message: String): MatchResult[T]

set a new failure message on this match result

set a new failure message on this match result

Attributes

def toResult: Result
def updateMessage(f: String => String): MatchResult[T]

update the failure message of this match result

update the failure message of this match result

Attributes

Abstract fields

the value being matched

the value being matched

Attributes