|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object spock.lang.Specification
public abstract class Specification
Base class for Spock specifications. All specifications must inherit from this class, either directly or indirectly.
Field Summary | |
---|---|
static Object |
_
The wildcard symbol. |
Constructor Summary | |
---|---|
Specification()
|
Method Summary | ||
---|---|---|
void |
interaction(Closure block)
Encloses one or more interaction definitions in a then block. |
|
Object |
Mock()
Creates a mock object whose name and type are inferred from the variable that the mock object is assigned to. |
|
|
Mock(Class<T> type)
Creates a mock object of the given type. |
|
void |
noExceptionThrown()
Specifies that no exception should be thrown. |
|
void |
notThrown(Class<? extends Throwable> type)
Specifies that in particular, no exception of the given type should be thrown. |
|
|
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. |
|
|
thrown()
Specifies that the preceding when block should throw an exception. |
|
|
thrown(Class<T> type)
Specifies that the preceding when block should throw an exception of the given type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Object _
Constructor Detail |
---|
public Specification()
Method Detail |
---|
public <T extends 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 Throwable> T thrown(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 type
public void notThrown(Class<? extends Throwable> type)
type
- an exception typepublic void noExceptionThrown()
public Object Mock()
public <T> T Mock(Class<T> type)
T
- the type of the mock object to be createdtype
- the type of the mock object to be created
public void interaction(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-block
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |