diff --git a/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt b/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt index 454d1897..0363daf5 100644 --- a/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt +++ b/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt @@ -684,10 +684,12 @@ fun , E> Builder.containsWithOrderingConstraints( val assertNoOtherElements = section.expectsNoOtherElements if (assertNoOtherElements) { assert("contains no other elements", expected = emptyList()) { - if (elementsConsumed == it.count()) { + val declaredElements = section.elementsWithConstraints.map { it.element } + val undeclaredElements = it - declaredElements + if (undeclaredElements.isEmpty()) { pass() } else { - fail(actual = it.drop(elementsConsumed)) + fail(actual = undeclaredElements) } } } else { @@ -704,6 +706,7 @@ fun , E> Builder.containsWithOrderingConstraints( } val assertNoFurtherElements = builder.expectsNoFurtherElements || + allSections.last().expectsNoOtherElements || // Check if the last section explicitly defines the end element allSections.last().endDefinedBy is SectionAssertionSpec.EndDefinition.DeclaredElement<*> if (assertNoFurtherElements) {