As far as I can tell, the expression given:
(starting the "given" block) does nothing at all in Spock tests and they function exactly the same if you just omit it.
Does anyone know different?
From the Spock documentation,
The
given
block is where you do any setup work for the feature that you are describing. It may not be preceded by other blocks, and may not be repeated. Agiven
block doesn’t have any special semantics. Thegiven:
label is optional and may be omitted, resulting in an implicitgiven
block. Originally, the aliassetup:
was the preferred block name, but usinggiven:
often leads to a more readable feature method description (see Specifications as Documentation).
So, ultimately yes, it functions just the same if you omit it, because Spock implicitly puts the label there anyway; but making the given
label explicit can help to document your tests.