## Solved ##
Thanks to dmahapatro (and erdi). I specifically glossed over setupSpec() and cleanup() as they are private in GebReportingSpec.
Just for completion sake I am going to post a simplified version of my final solution using the grails remote control plugin just in-case it helps anyone else. The only thing to note is that the setup/teardown appears to be called once per Spec, not before each test. Which for me is actually preferably as my test data is quite complex and takes time to be created. So you have a set of test data from the Spec which is modified through the tests in the Spec and then finally cleared down before your next Spec is executed.
@Stepwise
class TestDataBaseSpec extends GebReportingSpec {
protected void createTestUsers() {
def remote = new RemoteControl()
def created = remote {
def createUser = { name, roles, pwHash ->
def user = new ShiroUser(username: name, passwordHash: pwHash, passwordSetDate: new Date())
roles.each { user.addToRoles(it) }
user.save(failOnError: true)
return user
}
createUser("root", [ShiroRole.findByName("base_user")], pwHash)
// .. repeat for more
}
}
protected void deleteTestUsers() {
def remote = new RemoteControl()
def created = remote {
ShiroUser.findAll().each {
it.delete(flush: true)
}
return true
}
}
}
@Stepwise
class ExampleSpec extends TestDataBaseSpec {
def setupSpec() {
super.createTestUsers()
}
def cleanupSpec() {
super.deleteTestUsers()
}
def "valid root user logs in"() {
given: "I am at the login page"
to LoginPage
when: "I enter root's credentials"
username = "root"
password = "password"
and: "I click the login button"
loginButton.click()
then: "I am logged in and directed to the welcome page"
at WelcomePage
}
}