ExceptionMatchers

org.specs2.matcher.ExceptionMatchers
See theExceptionMatchers companion object

These matchers can be used to check if exceptions are thrown or not

Attributes

Companion
object
Graph
Supertypes
trait ResultChecks
class Object
trait Matchable
class Any
Show all
Known subtypes
object ExceptionMatchers.type
trait Matchers
object Matchers.type
trait MustMatchers
object MustMatchers.type
object MustThrownMatchers.type
object ShouldMatchers.type
object ShouldThrownMatchers.type
Show all

Members list

Type members

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

Supertypes
trait Matcher[Any]
class Object
trait Matchable
class Any
Self type

Value members

Concrete 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

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

Attributes

Returns

a matcher checking the type of an Exception

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)

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

Attributes

Returns

a matcher checking the value of an Exception

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

alias for throwA

alias for throwA

Attributes

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

alias for throwA

alias for throwA

Attributes

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

alias for throwA

alias for throwA

Attributes

Inherited methods

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