Spock Extensions allow to integrate Spock Specifications with other thid-party libraries, like Spring, Guice, Grails or Tapestry. They allow to control tests execution, their order and modify test results according to your custom criteria.
This presentation provides all the details required for implementing your very own Spock extensions. Global extensions, annotation-driven extensions, Spock interceptors and listeners are covered.
22. SpecInfo
Read
fields,
feature
and
fixture
methods
Add
interceptors
Add
listeners
Re-‐order,
filter,
sort,
skip,
exclude
features
22
23. SpecInfo
r
e methods
lxture
n
Read
fields,
feature
ai fi
o sio f nd
P r
Add
interceptors
n
eskip,
exclude
features
Add
listeners
x t
E
Re-‐order,
filter,
sort,
23
29. Listeners
Added
to
spec
Before
and
after
spec,
feature,
iteration
On
error
Skipped
spec
or
feature
Listen
passively,
do
not
throw
exceptions
Get
passed
official
test
results
29
30. Interceptors
Added
to
spec,
feature
or
fixture
methods
Intercept
method
invocation
invocation.proceed()
Can
change
test
outcome
and
behavior
Can
throw
exceptions
But
..
following
interceptors
can
do
the
same
30
31. Interceptors
e
Added
to
spec,
feature
or
fixture
methods
m
i
Intercept
method
invocation
T
@
invocation.proceed()
Can
change
test
outcome
and
behavior
Can
throw
exceptions
But
..
following
interceptors
can
do
the
same
31
32. Gotchas
Use
the
right
tool
for
the
job
Attach
interceptors
only
where
they
belong
Do
not
throw
exceptions
from
listeners
Reuse
listeners
or
interceptors
with
caution
Mark
feature
methods
as
skipped
if
needed
Skipped
(skip
a
few)
vs.
excluded
(run
a
few)
32