From 657dfce5eeb88325205e5d143c9ea4b77cde24e2 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Tue, 18 Apr 2023 08:12:10 +0200 Subject: [PATCH] OrderExtensionSpec: condense redundant code in embedded spec by extracting logging code into base spec. --- .../smoke/extension/OrderExtensionSpec.groovy | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy index 4e1be80761..d42454581c 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy @@ -44,38 +44,32 @@ class OrderExtensionSpec extends EmbeddedSpecification { compiler.addClassMemberImport(OrderExtensionSpec) compiler.addClassImport(Order) specs = compiler.compileWithImports(""" -class FirstSpec extends Specification { +abstract class BaseSpec extends Specification { @Shared execution = new SpecExecution(spec: this.class.simpleName) def setup() { execution.features << specificationContext.currentFeature.name } def cleanupSpec() { executionsTL.get() << execution } +} + +class FirstSpec extends BaseSpec { def one() { expect: true } def two() { expect: true } def three() { expect: true } } @Order(-1) -class SecondSpec extends Specification { - @Shared execution = new SpecExecution(spec: this.class.simpleName) - def setup() { execution.features << specificationContext.currentFeature.name } - def cleanupSpec() { executionsTL.get() << execution } +class SecondSpec extends BaseSpec { def foo() { expect: true } @Order(99) def bar() { expect: true } @Order(-5) def zot() { expect: true } } -class ThirdSpec extends Specification { - @Shared execution = new SpecExecution(spec: this.class.simpleName) - def setup() { execution.features << specificationContext.currentFeature.name } - def cleanupSpec() { executionsTL.get() << execution } +class ThirdSpec extends BaseSpec { def "some feature"() { expect: true } @Order(1) def "another feature"() { expect: true } def "one more feature"() { expect: true } } -class FourthSpec extends Specification { - @Shared execution = new SpecExecution(spec: this.class.simpleName) - def setup() { execution.features << specificationContext.currentFeature.name } - def cleanupSpec() { executionsTL.get() << execution } +class FourthSpec extends BaseSpec { def 'feature X'() { expect: true } def 'feature M'() { expect: true } @Order(-1) def 'feature D'() { expect: true }