Skip to content

Commit 36a2430

Browse files
authored
Make @PendingFeature and @PendingFeatureIf play nicely together (#1120)
1 parent 500f65d commit 36a2430

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/PendingFeatureBaseInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ protected boolean isExpected(Throwable e) {
2424
}
2525
return false;
2626
}
27-
protected AssertionError featurePassedUnexpectedly(StackTraceElement[] stackTrace) {
28-
AssertionError assertionError = new AssertionError("Feature is marked with " + annotationUsed + " but passes unexpectedly");
27+
protected PendingFeatureSuccessfulError featurePassedUnexpectedly(StackTraceElement[] stackTrace) {
28+
PendingFeatureSuccessfulError assertionError = new PendingFeatureSuccessfulError("Feature is marked with " + annotationUsed + " but passes unexpectedly");
2929
if (stackTrace != null) {
3030
assertionError.setStackTrace(stackTrace);
3131
}

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/PendingFeatureInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public PendingFeatureInterceptor(Class<? extends Throwable>[] handledExceptions,
1616
public void intercept(IMethodInvocation invocation) throws Throwable {
1717
try {
1818
invocation.proceed();
19-
} catch (TestAbortedException e) {
19+
} catch (TestAbortedException | PendingFeatureSuccessfulError e) {
2020
throw e;
2121
} catch (AssertionError e) {
2222
throw testAborted(e.getStackTrace());

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/PendingFeatureIterationInterceptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public void intercept(IMethodInvocation invocation) throws Throwable {
6464
try {
6565
invocation.proceed();
6666
success.set(true);
67+
} catch (PendingFeatureSuccessfulError e) {
68+
throw e;
6769
} catch (TestAbortedException e) {
6870
// if no expected failure set a stack trace, set it from an abort
6971
// that is better than the stack trace in the base interceptor
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.spockframework.runtime.extension.builtin;
2+
3+
import org.spockframework.util.Beta;
4+
5+
/**
6+
* @since 2.0
7+
*/
8+
@Beta
9+
public class PendingFeatureSuccessfulError extends AssertionError {
10+
public PendingFeatureSuccessfulError(String detailMessage) {
11+
super(detailMessage);
12+
}
13+
}

spock-specs/src/test/groovy/org/spockframework/smoke/extension/PendingFeatureIfExtensionSpec.groovy

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,100 @@ def bar() {
3737
e.message == "Feature is marked with @PendingFeatureIf but passes unexpectedly"
3838
}
3939

40+
def "@PendingFeatureIf marks passing feature as failed if the conditional expression returns true even if @PendingFeature is applied first"() {
41+
when:
42+
runner.runSpecBody """
43+
@PendingFeature
44+
@PendingFeatureIf({true})
45+
def bar() {
46+
expect: true
47+
}
48+
"""
49+
50+
then:
51+
AssertionError e = thrown()
52+
e.message == "Feature is marked with @PendingFeatureIf but passes unexpectedly"
53+
}
54+
55+
def "@PendingFeatureIf marks passing parameterized feature as failed if the conditional expression returns true even if @PendingFeature is applied first"() {
56+
when:
57+
runner.runSpecBody """
58+
@PendingFeature
59+
@PendingFeatureIf({true})
60+
def bar() {
61+
expect: true
62+
where: a = 1
63+
}
64+
"""
65+
66+
then:
67+
AssertionError e = thrown()
68+
e.message == "Feature is marked with @PendingFeatureIf but passes unexpectedly"
69+
}
70+
71+
def "@PendingFeatureIf marks passing feature as failed if the data variable accessing conditional expression returns true even if @PendingFeature is applied first"() {
72+
when:
73+
runner.runSpecBody """
74+
@PendingFeature
75+
@PendingFeatureIf({a == 1})
76+
def bar() {
77+
expect: true
78+
where: a = 1
79+
}
80+
"""
81+
82+
then:
83+
AssertionError e = thrown()
84+
e.message == "Feature is marked with @PendingFeatureIf but passes unexpectedly"
85+
}
86+
87+
def "@PendingFeatureIf marks passing feature as failed if the conditional expression returns true even if @PendingFeature is applied after it"() {
88+
when:
89+
runner.runSpecBody """
90+
@PendingFeatureIf({true})
91+
@PendingFeature
92+
def bar() {
93+
expect: true
94+
}
95+
"""
96+
97+
then:
98+
AssertionError e = thrown()
99+
e.message == "Feature is marked with @PendingFeature but passes unexpectedly"
100+
}
101+
102+
def "@PendingFeatureIf marks passing parameterized feature as failed if the conditional expression returns true even if @PendingFeature is applied after it"() {
103+
when:
104+
runner.runSpecBody """
105+
@PendingFeatureIf({true})
106+
@PendingFeature
107+
def bar() {
108+
expect: true
109+
where: a = 1
110+
}
111+
"""
112+
113+
then:
114+
AssertionError e = thrown()
115+
e.message == "Feature is marked with @PendingFeature but passes unexpectedly"
116+
}
117+
118+
def "@PendingFeatureIf marks passing feature as failed if the data variable accessing conditional expression returns true even if @PendingFeature is applied after it"() {
119+
when:
120+
runner.runSpecBody """
121+
@PendingFeatureIf({a == 1})
122+
@PendingFeature
123+
def bar() {
124+
expect: true
125+
where: a = 1
126+
}
127+
"""
128+
129+
then:
130+
AssertionError e = thrown()
131+
e.message == "Feature is marked with @PendingFeatureIf but passes unexpectedly"
132+
}
133+
40134
def "@PendingFeatureIf marks failing feature as failed if the conditional expression returns false"() {
41135
when:
42136
runner.runSpecBody """

0 commit comments

Comments
 (0)