File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
spock-core/src/main/java/org/spockframework/runtime/extension/builtin
spock-specs/src/test/groovy/org/spockframework/smoke/extension Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ include::include.adoc[]
99
1010* Fix ExtensionException in OSGi environment for global extension spockIssue:2076[]
1111** This issue was introduced with spockPull:1995[]
12+ * Fix `@RestoreSystemProperties` not restoring state between iterations of a data-driven feature spockIssue:2104[]
1213
1314== 2.4-M5 (2025-01-07)
1415
Original file line number Diff line number Diff line change @@ -30,13 +30,13 @@ public class RestoreSystemPropertiesExtension implements IStatelessAnnotationDri
3030 public void visitSpecAnnotation (RestoreSystemProperties annotation , SpecInfo spec ) {
3131 spec .addExclusiveResource (EXCLUSIVE_RESOURCE );
3232 for (FeatureInfo feature : spec .getFeatures ()) {
33- feature .addInterceptor (RestoreSystemPropertiesInterceptor .INSTANCE );
33+ feature .addIterationInterceptor (RestoreSystemPropertiesInterceptor .INSTANCE );
3434 }
3535 }
3636
3737 @ Override
3838 public void visitFeatureAnnotation (RestoreSystemProperties annotation , FeatureInfo feature ) {
39- feature .addInterceptor (RestoreSystemPropertiesInterceptor .INSTANCE );
39+ feature .addIterationInterceptor (RestoreSystemPropertiesInterceptor .INSTANCE );
4040 feature .addExclusiveResource (EXCLUSIVE_RESOURCE );
4141 }
4242}
Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ class RestoreSystemPropertiesExtension extends Specification {
3636 System . setProperty(" RestoreSystemPropertiesExtension.prop2" , " new value" )
3737 }
3838
39+ @Issue (" https://github.com/spockframework/spock/issues/2104" )
40+ @RestoreSystemProperties
41+ def " restores properties for each iteration of a data-driven feature method" () {
42+ expect :
43+ System . getProperty(" RestoreSystemPropertiesExtension.iteration" ) == null
44+
45+ when :
46+ System . setProperty(" RestoreSystemPropertiesExtension.iteration" , " $i " )
47+
48+ then :
49+ System . getProperty(" RestoreSystemPropertiesExtension.iteration" ) == " $i "
50+
51+ where :
52+ i << (1 .. 3 )
53+ }
54+
3955 def cleanupSpec () {
4056 assert System . getProperty(" RestoreSystemPropertiesExtension.prop1" ) == " original value"
4157 assert System . getProperty(" RestoreSystemPropertiesExtension.prop2" ) == " new value"
You can’t perform that action at this time.
0 commit comments