beforeEach()
and afterEach()
methods that each take in a closure as their argument that receive the name of the spec that's about to be executed or just executed. As their names indicate, they execute before a spec and after a spec in a related describe
block.aroundEach()
life-cycle method will completely wrap your spec in another closure. This is an elegant way for you to provide a complete around AOP advice to a specification. You can use it to surround the execution in transaction blocks, ORM rollbacks, logging, and so much more. This life-cycle method will decorate ALL specs within a single suite and any children suites. The method signature is below:beforeEach()
, afterEach()
, and aroundEach()
at the same time, there is a specific order they fire in. For a given describe block, they will fire in this order. Remember, aroundEach()
is split into two parts-- the half of the method before you call spec.body()
and the second half of the method.spec.body()
call)it()
blocks, the process repeats for each one. Steps 1, 2, 4, 5 will wrap every single it()
. beforeEach()
starts and we end on the outermost afterEach()
. it()
in the inner most describe. beforeEach()
callbeforeEach()
callaroundEach()
call (first half)aroundEach()
call (first half)it()
blockaroundEach()
calls (second half)aroundEach()
call (second half)afterEach()
callafterEach()
callit()
block. This is as opposed to the beforeAll()
and afterAll()
method which only run once for the entire CFC regardless of how many specs there are.