diff --git a/README.md b/README.md index f1c5645..3690600 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ To enable this Spock extension, you only need to declare a dependency to it (if Spock-reports is available on Maven Central and on JCenter. -> Since version 1.3.2, Spock version 1.1+ is required. -> From version 1.7.0, Spock 1.2-groovy-2.5 or newer should be used. -> If you use Java 9+, use the latest versions of both Spock and spock-reports. +> The versions below work with the new Spock 2 / Groovy 3 versions. +> If you want to stay with Spock 1 and Groovy 2.5.x, use spock-reports version 1.7.1. +> Spock-reports should work fine with Java 9+ since version 1.7.1. If you want to add information to your Spock-reports programmatically, since version 1.4.0, you can use the following `Specification` class' extension methods which are added by Spock Reports: @@ -60,10 +60,6 @@ def "My feature"() { ### If you are using Maven -> NOTE about Spock/Groovy versions: -> The versions below work with the new Spock 2 / Groovy 3 versions. -> If you want to stay with Spock 1 and Groovy 2.5.x, use spock-reports version 1.7.1. - Add ``spock-reports`` to your ````: ```xml diff --git a/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy b/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy index 0f72750..7e36bdd 100644 --- a/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy +++ b/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy @@ -11,8 +11,12 @@ import com.athaydes.spockframework.report.internal.SpecProblem import com.athaydes.spockframework.report.internal.SpockReportsConfiguration import com.athaydes.spockframework.report.util.Utils import groovy.util.logging.Slf4j +import org.junit.AssumptionViolatedException +import org.opentest4j.IncompleteExecutionException import org.spockframework.runtime.IRunListener import org.spockframework.runtime.extension.IGlobalExtension +import org.spockframework.runtime.extension.IMethodInterceptor +import org.spockframework.runtime.extension.IMethodInvocation import org.spockframework.runtime.model.ErrorInfo import org.spockframework.runtime.model.FeatureInfo import org.spockframework.runtime.model.IterationInfo @@ -75,7 +79,11 @@ class SpockReportExtension implements IGlobalExtension { @Override void visitSpec( SpecInfo specInfo ) { if ( reportCreator != null ) { - specInfo.addListener createListener() + def listener = createListener() + def abortionInterceptor = new AbortionInterceptor(listener) + specInfo.addListener listener + specInfo.allFeatures*.getFeatureMethod().each { it.addInterceptor(abortionInterceptor) } + specInfo.allFixtureMethods.each { it.addInterceptor(abortionInterceptor) } } else { log.warn "Not creating report for ${ specInfo.name } as reportCreator is null" } @@ -107,6 +115,24 @@ class SpockReportExtension implements IGlobalExtension { } +class AbortionInterceptor implements IMethodInterceptor { + SpecInfoListener listener + + AbortionInterceptor(SpecInfoListener listener) { + this.listener = listener + } + + @Override + void intercept(IMethodInvocation invocation) throws Throwable { + try { + invocation.proceed() + } catch( AssumptionViolatedException | IncompleteExecutionException t ) { + listener.executionAborted new ErrorInfo( invocation.method, t ) + throw t + } + } +} + @Slf4j class SpecInfoListener implements IRunListener { @@ -248,6 +274,13 @@ class SpecInfoListener implements IRunListener { // feature already knows if it's skipped } + void executionAborted( ErrorInfo error ) { + //properly handle aborted iteration or spec depending on ${error.method.kind} + //MethodKind.FEATURE for aborted features/iterations + //MethodKind.SETUP_SPEC for aborted setupSpec + //${error.error} holds the reason of abortion + } + private FeatureRun currentRun() { if ( specData.featureRuns.empty ) { specData.featureRuns.add new FeatureRun( feature: specData.info.features?.first() ?: dummyFeature() ) @@ -271,5 +304,4 @@ class SpecInfoListener implements IRunListener { private static FeatureInfo dummyFeature() { new FeatureInfo( name: '' ) } - }