Package spock.lang
Class Specification
- java.lang.Object
-
- org.spockframework.lang.SpecInternals
-
- spock.lang.MockingApi
-
- spock.lang.Specification
-
public abstract class Specification extends MockingApi
Base class for Spock specifications. All specifications must inherit from this class, either directly or indirectly.- Author:
- Peter Niederwieser
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object
_
The wildcard symbol.
-
Constructor Summary
Constructors Constructor Description Specification()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
noExceptionThrown()
Specifies that no exception should be thrown, failing with aUnallowedExceptionThrownError
otherwise.void
notThrown(java.lang.Class<? extends java.lang.Throwable> type)
Specifies that no exception of the given type should be thrown, failing with aUnallowedExceptionThrownError
otherwise.<T> T
old(T expression)
Used in a then-block to access an expression's value at the time just before the previous where-block was entered.<T extends java.lang.Throwable>
Tthrown()
Specifies that the preceding when block should throw an exception.<T extends java.lang.Throwable>
Tthrown(java.lang.Class<T> type)
Specifies that the preceding when block should throw an exception of the given type.void
with(java.lang.Object object, groovy.lang.Closure closure)
-
Methods inherited from class spock.lang.MockingApi
GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, interaction, Mock, Mock, Mock, Mock, Mock, Mock, Mock, Mock, Spy, Spy, Spy, Spy, Spy, Spy, Spy, Spy, Stub, Stub, Stub, Stub, Stub, Stub, Stub, Stub
-
Methods inherited from class org.spockframework.lang.SpecInternals
createMock, getSpecificationContext
-
-
-
-
Method Detail
-
thrown
public <T extends java.lang.Throwable> T thrown()
Specifies that the preceding when block should throw an exception. May only occur as the initializer expression of a typed variable declaration in a then block; the expected exception type is inferred from the variable type.This form of exception condition is typically used if the thrown exception instance is used in subsequent conditions.
Example:
when: "".charAt(0) then: IndexOutOfBoundsException e = thrown() e.message.contains(...)
- Returns:
- the thrown exception instance
-
thrown
public <T extends java.lang.Throwable> T thrown(java.lang.Class<T> type)
Specifies that the preceding when block should throw an exception of the given type. May only occur in a then block.This form of exception condition is typically used if the thrown exception instance is not used in subsequent conditions.
Example:
when: "".charAt(0) then: thrown(IndexOutOfBoundsException)
- Type Parameters:
T
- the expected exception type- Parameters:
type
- the expected exception type- Returns:
- the thrown exception instance
-
notThrown
public void notThrown(java.lang.Class<? extends java.lang.Throwable> type)
Specifies that no exception of the given type should be thrown, failing with aUnallowedExceptionThrownError
otherwise.- Parameters:
type
- the exception type that should not be thrown
-
noExceptionThrown
public void noExceptionThrown()
Specifies that no exception should be thrown, failing with aUnallowedExceptionThrownError
otherwise.
-
old
public <T> T old(T expression)
Used in a then-block to access an expression's value at the time just before the previous where-block was entered.- Type Parameters:
T
- the expression's type- Parameters:
expression
- an arbitrary expression, except that it may not reference variables defined in the then-block- Returns:
- the expression's value at the time the previous where-block was entered
-
with
@Beta public void with(java.lang.Object object, groovy.lang.Closure closure)
-
-