ExceptionMatchers

org.specs2.matcher.ExceptionMatchers$
See theExceptionMatchers companion trait

Attributes

Companion
trait
Graph
Supertypes
trait ResultChecks
class Object
trait Matchable
class Any
Show all
Self type

Members list

Type members

Inherited classlikes

class ExceptionMatcher[E <: Throwable](klass: Class[_], pf: Option[PartialFunction[E, Result]]) extends Matcher[Any]

An exception matcher checks if an expression throws some specified exceptions:

An exception matcher checks if an expression throws some specified exceptions:

  • by checking the type of exception
    • if no exception is thrown it returns a success
    • if an exception is thrown with with a subtype of java.lang.Error and we expect an Exception then it is re-thrown
    • if an exception is thrown with a different type it returns a failure
  • by checking the exception message
  • by checking a condition on the exception

Attributes

Inherited from:
ExceptionMatchers
Supertypes
trait Matcher[Any]
class Object
trait Matchable
class Any

Value members

Inherited methods

def beException[T](message: String)(using evidence$1: ClassTag[T]): Matcher[Throwable]

check if a Throwable has a specific class and error message The message must be a regular expression, for example (new IllegalArgumentException("incorrect arguments"): Throwable) must beExceptionIllegalArgumentException

check if a Throwable has a specific class and error message The message must be a regular expression, for example (new IllegalArgumentException("incorrect arguments"): Throwable) must beExceptionIllegalArgumentException

Attributes

Inherited from:
ExceptionMatchers
protected def checkResultFailure(r: => Result): Result

this method can be overridden to throw exceptions when checking a result

this method can be overridden to throw exceptions when checking a result

Attributes

Inherited from:
ResultChecks
def createExpectable[T](t: => T, alias: String => String): Expectable[T]

Attributes

Returns

an Expectable with a description function

Inherited from:
ExpectationsCreation
def createExpectable[T](t: => T, alias: => String): Expectable[T]

Attributes

Returns

an Expectable with a description

Inherited from:
ExpectationsCreation
def createExpectable[T](t: => T): Expectable[T]

Attributes

Returns

an Expectable

Inherited from:
ExpectationsCreation
def createExpectable[T](t: => T, alias: Option[String => String]): Expectable[T]

Attributes

Returns

an Expectable with a description function

Inherited from:
ExpectationsCreation
def createExpectableWithShowAs[T](t: => T, showAs: => String): Expectable[T]

Attributes

Returns

an Expectable with a function to show the element T

Inherited from:
ExpectationsCreation
protected def mapResult(r: Result): Result

this method can be overridden to intercept a Result and modify it. It is used for example to set a stacktrace providing the location of a failure

this method can be overridden to intercept a Result and modify it. It is used for example to set a stacktrace providing the location of a failure

Attributes

Inherited from:
ResultChecks
protected def sandboxResult(r: => Result): Result

Attributes

Returns

the result without any side-effects

Inherited from:
ResultChecks
protected def setStacktrace(m: Result): Result

this method can be overridden to avoid filling-in a stacktrace indicating the location of the result

this method can be overridden to avoid filling-in a stacktrace indicating the location of the result

Attributes

Inherited from:
MatchResultStackTrace
def theBlock(t: => Nothing): Expectable[Nothing]

Attributes

Inherited from:
ExpectationsCreation
def theValue[T](t: => T): Expectable[T]

Attributes

Inherited from:
ExpectationsCreation
def throwA[E <: Throwable](e: E)(using m: ClassTag[E]): ExceptionMatcher[E]

Attributes

Returns

a matcher checking the value of an Exception

Inherited from:
ExceptionMatchers
def throwA[E <: Throwable](message: String)(using m: ClassTag[E]): ExceptionMatcher[E]

Attributes

Returns

a matcher checking the type of an Exception and its message (as a regexp)

Inherited from:
ExceptionMatchers
def throwA[E <: Throwable](using m: ClassTag[E]): ExceptionMatcher[E]

Attributes

Returns

a matcher checking the type of an Exception

Inherited from:
ExceptionMatchers
def throwAn[E <: Throwable](e: E)(using m: ClassTag[E]): ExceptionMatcher[E]

alias for throwA

alias for throwA

Attributes

Inherited from:
ExceptionMatchers
def throwAn[E <: Throwable](message: String)(using m: ClassTag[E]): ExceptionMatcher[E]

alias for throwA

alias for throwA

Attributes

Inherited from:
ExceptionMatchers
def throwAn[E <: Throwable](using m: ClassTag[E]): ExceptionMatcher[E]

alias for throwA

alias for throwA

Attributes

Inherited from:
ExceptionMatchers