Matcher

trait Matcher[-T]

The Matcher trait is the base trait for any Matcher.

This trait can be extended to provide an appropriate apply method that will check an expectable value a: Expectable[T].

The result of a match is a Result

Matchers can be composed.

Implementation notes:

  • the parameter to the apply method must be a by-name parameter. This allows some values to be evaluated only when necessary.

  • However in the implementation of the apply function, it must be taken care of not evaluating the parameter twice. Assigning it to a val is the solution to this issue.

Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def apply[S <: T](t: Expectable[S]): Result

apply this matcher to an Expectable

apply this matcher to an Expectable

Returns:

a Result describing the outcome of the match

Concrete methods

def ^^[S](f: S => T): Matcher[S]

Adapt a matcher to another. ex: be_==("message") ^^ (_.getMessage) can be applied to an exception

Adapt a matcher to another. ex: be_==("message") ^^ (_.getMessage) can be applied to an exception

def ^^[S](f: S => Expectable[T], dummy: Int): Matcher[S]

Adapt a matcher to another. ex: be_==("message") ^^ (_.getMessage aka "trimmed") can be applied to an exception

Adapt a matcher to another. ex: be_==("message") ^^ (_.getMessage aka "trimmed") can be applied to an exception

The dummy value is used to help to disambiguate with the overloaded ^^ function

infix def and[S <: T](m: => Matcher[S]): Matcher[S]

the logical and between 2 matchers

the logical and between 2 matchers

See also:

Result.and

Returns:

a matcher that needs to eventually match, after 40 retries and a sleep time of 100 milliseconds

def eventually(retries: Int, sleep: Duration): Matcher[T]
Returns:

a matcher that needs to eventually match, after a given number of retries and a sleep time

def eventually(retries: Int, sleep: Int => Duration): Matcher[T]
Value parameters:
sleep

the function applied on the retry number (first is 1)

Returns:

a matcher that needs to eventually match, after a given number of retries and a sleep time

(aResult === expected).eventually(retries = 2, _ * 100.milliseconds)
def iff(b: Boolean): Matcher[T]

when the condition is true the matcher is applied, when it's false, the matcher must fail

when the condition is true the matcher is applied, when it's false, the matcher must fail

def lazily: Matcher[() => T]

The lazily operator returns a Matcher which will match a function returning the expected value

The lazily operator returns a Matcher which will match a function returning the expected value

def mute: Matcher[T]
Returns:

a Matcher with no messages

def not: Matcher[T]

negate a Matcher

negate a Matcher

See also:

Result.not

infix def or[S <: T](m: => Matcher[S]): Matcher[S]

the logical or between 2 matchers

the logical or between 2 matchers

See also:

Result.or

Returns:

a Pending Result if this matcher fails

def orPending(m: String): Matcher[T]
Returns:

a Pending Result if this matcher fails, prefixing the failure message with a pending message. If the pending message is empty, only the failure message is printed

def orPending(message: String => String): Matcher[T]
Returns:

a Pending Result if this matcher fails, modifying the failure message with a pending message.

def orSkip: Matcher[T]
Returns:

a Skipped result if this matcher fails

def orSkip(m: String): Matcher[T]
Returns:

a Skipped Result if this matcher fails, prefixing the failure message with a skip message. If the skip message is empty, only the failure message is printed

def orSkip(message: String => String): Matcher[T]
Returns:

a Skipped Result if this matcher fails, modifying the failure message with a skip message.

throw a FailureException if this matcher fails

throw a FailureException if this matcher fails

def orThrow(m: String): Matcher[T]

throw a FailureException if this matcher fails prefixing the failure message with a message. If the message is empty, only the failure message is printed

throw a FailureException if this matcher fails prefixing the failure message with a message. If the message is empty, only the failure message is printed

def orThrow(message: String => String): Matcher[T]

throw a FailureException if this matcher fails, modifying the failure message with a message.

throw a FailureException if this matcher fails, modifying the failure message with a message.

def setMessage(message: String): Matcher[T]
Returns:

set a new failure message of a matcher

def test: T => Boolean
Returns:

a test function corresponding to this matcher

def unless(b: Boolean, m: String): Matcher[T]

only apply this matcher if the condition is false

only apply this matcher if the condition is false

def updateMessage(f: String => String): Matcher[T]
Returns:

update the failure message of a matcher

def when(b: Boolean, m: String): Matcher[T]

only apply this matcher if the condition is true

only apply this matcher if the condition is true