Skip to content

Commit cf60234

Browse files
committed
Prevent assertions in helper methods from being wrapped in ConditionFailedWithExceptionError
Signed-off-by: Pavlo Shevchenko <pavel.shevchenko.95@gmail.com>
1 parent 808616e commit cf60234

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

spock-core/src/main/java/org/spockframework/runtime/SpockRuntime.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public static void conditionFailedWithException(ErrorCollector errorCollector, @
7777
errorCollector.collectOrThrow(spockException); // this is our exception - it already has good message
7878
return;
7979
}
80+
if (throwable instanceof MultipleFailuresError) {
81+
final MultipleFailuresError multipleFailuresError = (MultipleFailuresError) throwable;
82+
errorCollector.collectOrThrow(multipleFailuresError); // this is our exception - it already has good message
83+
return;
84+
}
8085
final ConditionFailedWithExceptionError conditionNotSatisfiedError = new ConditionFailedWithExceptionError(
8186
new Condition(
8287
getValues(recorder),

spock-specs/src/test/groovy/org/spockframework/smoke/VerifyAllMethodsSpecification.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.spockframework.smoke
1717
import org.opentest4j.MultipleFailuresError
1818
import org.spockframework.EmbeddedSpecification
1919
import org.spockframework.runtime.ConditionNotSatisfiedError
20+
import org.spockframework.runtime.SpockComparisonFailure
2021

2122
class VerifyAllMethodsSpecification extends EmbeddedSpecification {
2223

@@ -59,13 +60,14 @@ def "feature"() {
5960

6061
then:
6162
result.failures.size() == 1
62-
with(result.failures[0].exception.cause, MultipleFailuresError) {
63+
with(result.failures[0].exception, MultipleFailuresError) {
6364
failures.size() == 2
6465
with(failures[0], ConditionNotSatisfiedError) {
6566
condition.text == 'x > 0'
6667
}
67-
with(failures[1], ConditionNotSatisfiedError) {
68-
condition.text == 'x % 2 == 0'
68+
with(failures[1], SpockComparisonFailure) {
69+
expected.stringRepresentation.trim() == "0"
70+
actual.stringRepresentation.trim() == "-1"
6971
}
7072
}
7173
}
@@ -91,13 +93,14 @@ class SpecWithHelpers extends Specification {
9193

9294
then:
9395
result.failures.size() == 1
94-
with(result.failures[0].exception.cause, MultipleFailuresError) {
96+
with(result.failures[0].exception, MultipleFailuresError) {
9597
failures.size() == 2
9698
with(failures[0], ConditionNotSatisfiedError) {
9799
condition.text == 'x > 0'
98100
}
99-
with(failures[1], ConditionNotSatisfiedError) {
100-
condition.text == 'x % 2 == 0'
101+
with(failures[1], SpockComparisonFailure) {
102+
expected.stringRepresentation.trim() == "0"
103+
actual.stringRepresentation.trim() == "-1"
101104
}
102105
}
103106
}

0 commit comments

Comments
 (0)