14 July 2015

In a previous post I described how to use Spock-Reports with Grails 3.0.

That was easy since Grails 3.0 is Gradle based.

Now I will try to figure out how to use Spock-Reports with Grails 2.2.4 .

Again, the configuration of the dependencies is easy: just open your grails-app/conf/BuildConfig.groovy file and add

repositories {
  //for spock-reports
  mavenRepo "http://jcenter.bintray.com"

to the repositories section and

dependencies {
  //for spock-reports
  test 'com.athaydes:spock-reports:1.2.5'  

to the dependencies section. But since Grails 2.2.4 does not include Spock be default, we also have to follow the
documentation for the Grails-Spock-Plugin and add in addition

plugins {
	test(":spock:0.7") {
	    //since we use groovy 2.x with grails 2.2.4
      	    exclude "spock-grails-support"

to the plugins section and

dependencies {
  test 'org.spockframework:spock-grails-support:0.7-groovy-2.0'

to the dependencies section. Now, that should do the trick. The standard reports are now generated and stored in build/spock-reports/..

Customizing your Reports

In order to store the generated reports in target/test-reports/spock/. you have to customize your reports as described in the documentation, you have to create a file called META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties.
That sounds easier than it is, because it has to be in the classpath and for some Grails projects, it's not easy to find the right folder to put it.

For Grails 2.2.4, you will succeed by putting it in grails-app/conf/META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties.

Here is a sample file which uses the template based reports:

# Name of the implementation class of the report creator
# Currently supported classes are:
#   1. com.athaydes.spockframework.report.internal.HtmlReportCreator
#   2. com.athaydes.spockframework.report.template.TemplateReportCreator

# Output directory (where the spock reports will be created) - relative to working directory

# If set to true, hides blocks which do not have any description

# Set properties of the report creator

this file specifies that the templates are located in grails-app/conf/spockreporttemplates and the output
will be written to target/test-reports/spock. A good idea is to start with the default templates spec-template.md and summary-template.md

You might want to use this https://github.com/rdmueller/Grails2.2-Spock-Reports-Sample as a starting point...