1
1
package com.anotherchrisberry.spock.extensions.retry
2
2
3
+ import org.spockframework.compiler.model.FeatureMethod
3
4
import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension
4
5
import org.spockframework.runtime.model.FeatureInfo
6
+ import org.spockframework.runtime.model.MethodInfo
5
7
import org.spockframework.runtime.model.SpecInfo
6
8
7
9
class RetrySpecExtension extends AbstractAnnotationDrivenExtension<RetryOnFailure > {
@@ -31,7 +33,7 @@ class RetrySpecExtension extends AbstractAnnotationDrivenExtension<RetryOnFailur
31
33
List<FeatureInfo > featuresToRetry = [selfAndSubSpecs. features]. flatten(). unique()
32
34
for (FeatureInfo feature : featuresToRetry) {
33
35
clearInterceptors(feature)
34
- feature . getFeatureMethod() . addInterceptor( new RetryInterceptor (getNumberOfRetries( retries)) )
36
+ addInterceptors(feature, retries)
35
37
}
36
38
}
37
39
}
@@ -41,7 +43,25 @@ class RetrySpecExtension extends AbstractAnnotationDrivenExtension<RetryOnFailur
41
43
return Integer . parseInt(System . getProperty(" spock-retry.times" , defaultRetries))
42
44
}
43
45
46
+ private List<MethodInfo > getInterceptableMethods (FeatureInfo feature ) {
47
+ SpecInfo spec = feature. getSpec()
48
+ [ spec. setupMethods,
49
+ spec. setupSpecMethods,
50
+ spec. cleanupMethods,
51
+ spec. cleanupSpecMethods,
52
+ feature. featureMethod
53
+ ]. flatten(). unique() as List<MethodInfo >
54
+ }
55
+
44
56
private void clearInterceptors (FeatureInfo featureInfo ) {
45
- featureInfo. featureMethod. interceptors. removeAll { it. class == RetryInterceptor }
57
+ List<MethodInfo > interceptableMethods = getInterceptableMethods(featureInfo)
58
+ interceptableMethods. each { it. interceptors. removeAll { it. class == RetryInterceptor } }
59
+ }
60
+
61
+ private void addInterceptors (FeatureInfo featureInfo , RetryOnFailure retries ) {
62
+ def interceptor = new RetryInterceptor (getNumberOfRetries(retries))
63
+ getInterceptableMethods(featureInfo). each {
64
+ it. addInterceptor(interceptor)
65
+ }
46
66
}
47
67
}
0 commit comments