Fields

实例化一个类

def obj = new ClassUnderSpecification()
def coll = new Collaborator()

Feature Methods

Feature Methods 指具体的测试用例方法

def "pushing an element on the stack"() {
// blocks go here
}

Fixture Methods

def setup() {} // run before every feature method
def cleanup() {} // run after every feature method
def setupSpec() {} // run before the first feature method
def cleanupSpec() {} // run after the last feature method

关于 Fixture Methods 的作用，我引用一下官方文档的一段话

Fixture methods are responsible for setting up and cleaning up the environment in
which feature methods are run. Usually it’s a good idea to use a fresh fixture for
every feature method, which is what the setup() and cleanup() methods are for.
All fixture methods are optional.

Blocks

关于 Blocks 的用法， 这里引用官网的一段话

Spock has built-in support for implementing each of the conceptual phases of a
feature method. To this end, feature methods are structured into so-called blocks.
Blocks start with a label, and extend to the beginning of the next block, or the
end of the method. There are six kinds of blocks: setup, when, then, expect,
cleanup, and where blocks