public abstract class Specification
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Object |
_
The wildcard symbol.
|
| Constructor and Description |
|---|
Specification() |
| Modifier and Type | Method and Description |
|---|---|
void |
interaction(groovy.lang.Closure block)
Encloses one or more interaction definitions in a then block.
|
java.lang.Object |
Mock()
Creates a mock object whose name and type are inferred from the variable
that the mock object is assigned to.
|
<T> T |
Mock(java.lang.Class<T> type)
Creates a mock object of the given type.
|
void |
noExceptionThrown()
Specifies that no exception should be thrown.
|
void |
notThrown(java.lang.Class<? extends java.lang.Throwable> type)
Specifies that in particular, no exception of the given type should be
thrown.
|
<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> |
thrown()
Specifies that the preceding when block should throw an exception.
|
<T extends java.lang.Throwable> |
thrown(java.lang.Class<T> type)
Specifies that the preceding when block should throw an exception
of the given type.
|
public static final java.lang.Object _
public <T extends java.lang.Throwable> T thrown()
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(...)
public <T extends java.lang.Throwable> T thrown(java.lang.Class<T> type)
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)
T - the expected exception typetype - the expected exception typepublic void notThrown(java.lang.Class<? extends java.lang.Throwable> type)
type - an exception typepublic void noExceptionThrown()
public java.lang.Object Mock()
public <T> T Mock(java.lang.Class<T> type)
T - the type of the mock object to be createdtype - the type of the mock object to be createdpublic void interaction(groovy.lang.Closure block)
Regular interaction definition:
def "published messages are received at least once"() {
when:
publisher.send(msg)
then:
(1.._) * subscriber.receive(msg)
}
Equivalent definition that uses a helper variable:
def "published messages are received at least once"() {
when:
publisher.send(msg)
then:
interaction {
def num = (1.._)
num * subscriber.receive(msg)
}
}
Equivalent definition that uses a helper method:
def "published messages are received at least once"() {
when:
publisher.send(msg)
then:
interaction {
messageReceived(msg)
}
}
def messageReceived(msg) {
(1.._) * subscriber.receive(msg)
}
block - a block of code containing one or more interaction definitionspublic <T> T old(T expression)
T - the expression's typeexpression - an arbitrary expression, except that it may not
reference variables defined in the then-blockCopyright © 2013. All rights reserved