Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ will now require that the spec is annotated with <<parallel_execution.adoc#isola
* OSGi: Pin the `Require-Capability:osgi.ee=JavaSE` to Java `8` spockPull:2233[]
* Fix: Prevent NPE in SpecRunHistory.sortFeatures when duration is missing spockIssue:2234[]
* `Retry` extension does not mesh with `TestAbortedException` and `PendingFeature` spockIssue:1863[]
* Fix display of caught exceptions within `verifyEach` blocks spockPull:2163[]

Thanks to all the contributors to this release: Andreas Turban, Björn Kautler, Christoph Loy, Leonard Brünings, Thanos Tsiamis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static <T> void verifyEach(
}

private static <T> SpockAssertionError getAssertionFailedError(Function<? super T, ?> namer, InternalItemFailure<T> failure) {
SpockAssertionError error = new SpockAssertionError(String.format("Assertions failed for item[%d] %s:\n%s", failure.index, namer.apply(failure.item), failure.throwable.getMessage()));
SpockAssertionError error = new SpockAssertionError(String.format("Assertions failed for item[%d] %s:\n%s", failure.index, namer.apply(failure.item), failure.throwable.toString()));
error.setStackTrace(failure.throwable.getStackTrace());
return error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,44 @@ class VerifyEachBlocks extends EmbeddedSpecification {
snap.assertThat(e.message).matchesSnapshot()
}

def "verifyEach fails handles exception"(@Snapshot Snapshotter snap) {
given:
def range = (1..10)

when:
verifyEach(range) {
if (it == 5) {
throw new RuntimeException("x == $it").tap {
// remove stack trace to make snapshot stable
it.stackTrace = []
}
}
}

then:
SpockAssertionError e = thrown()
snap.assertThat(e.message).matchesSnapshot()
}

def "verifyEach fails handles exceptions"(@Snapshot Snapshotter snap) {
given:
def range = (1..10)

when:
verifyEach(range) {
if (it in (5..6)) {
throw new RuntimeException("x == $it").tap {
// remove stack trace to make snapshot stable
it.stackTrace = []
}
}
}

then:
MultipleFailuresError e = thrown()
snap.assertThat(e.message).matchesSnapshot()
}

def "verifyEach fails handles nested exceptions"(@Snapshot Snapshotter snap) {
given:
def range = (1..10)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Assertions failed for item[4] 5:
java.lang.RuntimeException: x == 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Multiple Failures (2 failures)
org.spockframework.runtime.SpockAssertionError: Assertions failed for item[4] 5:
java.lang.RuntimeException: x == 5
org.spockframework.runtime.SpockAssertionError: Assertions failed for item[5] 6:
java.lang.RuntimeException: x == 6