Skip to content

Commit

Permalink
Prevent assertions in helper methods from being wrapped in `Condition…
Browse files Browse the repository at this point in the history
…FailedWithExceptionError`

Signed-off-by: Pavlo Shevchenko <[email protected]>
  • Loading branch information
pshevche committed Feb 24, 2025
1 parent 808616e commit cf60234
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public static void conditionFailedWithException(ErrorCollector errorCollector, @
errorCollector.collectOrThrow(spockException); // this is our exception - it already has good message
return;
}
if (throwable instanceof MultipleFailuresError) {
final MultipleFailuresError multipleFailuresError = (MultipleFailuresError) throwable;
errorCollector.collectOrThrow(multipleFailuresError); // this is our exception - it already has good message
return;
}
final ConditionFailedWithExceptionError conditionNotSatisfiedError = new ConditionFailedWithExceptionError(
new Condition(
getValues(recorder),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org.spockframework.smoke
import org.opentest4j.MultipleFailuresError
import org.spockframework.EmbeddedSpecification
import org.spockframework.runtime.ConditionNotSatisfiedError
import org.spockframework.runtime.SpockComparisonFailure

class VerifyAllMethodsSpecification extends EmbeddedSpecification {

Expand Down Expand Up @@ -59,13 +60,14 @@ def "feature"() {

then:
result.failures.size() == 1
with(result.failures[0].exception.cause, MultipleFailuresError) {
with(result.failures[0].exception, MultipleFailuresError) {
failures.size() == 2
with(failures[0], ConditionNotSatisfiedError) {
condition.text == 'x > 0'
}
with(failures[1], ConditionNotSatisfiedError) {
condition.text == 'x % 2 == 0'
with(failures[1], SpockComparisonFailure) {
expected.stringRepresentation.trim() == "0"
actual.stringRepresentation.trim() == "-1"
}
}
}
Expand All @@ -91,13 +93,14 @@ class SpecWithHelpers extends Specification {

then:
result.failures.size() == 1
with(result.failures[0].exception.cause, MultipleFailuresError) {
with(result.failures[0].exception, MultipleFailuresError) {
failures.size() == 2
with(failures[0], ConditionNotSatisfiedError) {
condition.text == 'x > 0'
}
with(failures[1], ConditionNotSatisfiedError) {
condition.text == 'x % 2 == 0'
with(failures[1], SpockComparisonFailure) {
expected.stringRepresentation.trim() == "0"
actual.stringRepresentation.trim() == "-1"
}
}
}
Expand Down

0 comments on commit cf60234

Please sign in to comment.