[TestBox 4.5.0] How Does WrapInTransaction() Get Treated as an AroundEach() Implicit Method?

When I took the Coldbox Zero to Hero course, we set up a BaseIntegrationSpec.cfc that I have used for my BDD tests on many different projects over the last few years. In the class, we added a method called wrapInTransaction() that looks like this:

/**
 * This function is tagged as an around each handler.  All the integration tests we build
 * will be automatically rolled backed. No database corruption
 * 
 * @aroundEach
 */
function wrapInTransaction( spec ) {
    transaction action="begin" {
        try {
            arguments.spec.body();
        } catch ( any e ){
            rethrow;
        } finally {
            transaction action="rollback";
        }
    }
}

One thing that has always baffled me is how TestBox knows to call this method around each it() spec. How does TestBox know to treat wrapInTransaction() as an aroundEach() implicit method?

Follow Up Question: Is there something equivalent to aroundEach() that wraps completely around either the run() or describe() methods? It might be handy to wrap an entire describe() in a transaction - especially for complex or time-consuming database seeding operations.

It’s the @aroundEach annotation that tells TestBox to run this around each spec.

As far as I know, there is no aroundAll like there is a beforeAll or afterAll.

1 Like

Thank you for the insight @elpete! I have not used annotations in that way before.