show representation for failure in feature extraction if subject defined

or in case failure hints or sub-assertions are defined.
This commit is contained in:
Robert Stoll
2021-07-06 22:32:20 +02:00
parent 1a8e024a7b
commit 1f1f0a50ca
5 changed files with 25 additions and 16 deletions

View File

@@ -2192,8 +2192,8 @@ fun Expect<Person>.toHaveAdultChildren(): Expect<Person> =
We once again use `feature` with an [assertion group block](#define-single-assertions-or-assertion-groups)
for the same reason as above.
We might be tempted to add a size check -- because a Person with 0 children does not have adult children --
but we do not have to, as `all` already checks that there is at least one element.
Note how `toHaveElementsAndAll` already checks that there is at least one element.
I.e. it fails for a `Person` with 0 children, because such a person does not have adult children.
<ex-own-compose-4>
@@ -2208,7 +2208,6 @@ expected that subject: Person(firstName=Susanne, lastName=Whitley, age=43, child
children: [] (kotlin.collections.EmptyList <1234789>)
has: a next element
» all entries:
» ▶age:
» ▶age:
is greater than or equal to: 18 (kotlin.Int <1234789>)
```

View File

@@ -1,7 +1,6 @@
package ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3
import ch.tutteli.atrium.api.infix.en_GB.aSuccess
import ch.tutteli.atrium.api.infix.en_GB.success
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.specs.integration.ResultExpectationsSpec
import ch.tutteli.atrium.specs.notImplemented

View File

@@ -5,7 +5,7 @@
package custom
import ch.tutteli.atrium.api.fluent.en_GB.kotlin_1_3.isSuccess
import ch.tutteli.atrium.api.fluent.en_GB.kotlin_1_3.toBeASuccess
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import ch.tutteli.atrium.assertions.Assertion
@@ -25,7 +25,7 @@ object SmokeSpec : Spek({
}
test("see if `Result.isSuccess` can be used") {
expect(Result.success(1)).isSuccess { toEqual(1) }
expect(Result.success(1)).toBeASuccess { toEqual(1) }
}
test("see if own assertion function without i18n can be used") {

View File

@@ -69,14 +69,25 @@ class DefaultFeatureExtractor : FeatureExtractor {
)
})
}
container.addAssertion(
assertionBuilder.fixedClaimGroup
val featureAssertions = failureHintAssertions + subAssertions
val fixedClaimGroup = assertionBuilder.fixedClaimGroup
.withFeatureType
.failing
.withDescriptionAndRepresentation(description, repForFailure)
.withAssertions(failureHintAssertions + subAssertions)
.withAssertions(featureAssertions)
.build()
)
container.maybeSubject.fold({
// If the feature extraction fails because the subject is already None, then we don't need/want to
// show the fixedClaimGroup in case it is empty because the feature as such will already be shown
// via explanatory assertion group
if (featureAssertions.isNotEmpty()) {
container.addAssertion(fixedClaimGroup)
}
}, {
// on the other hand, if the subject is defined, then we need the fixedClaimGroup which inter alia
// shows why the extraction went wrong (e.g. index out of bound)
container.addAssertion(fixedClaimGroup)
})
createFeatureExpect(None, listOf())
},
{ subject ->

View File

@@ -91,8 +91,8 @@ class DefaultIterableLikeAssertions : IterableLikeAssertions {
val listAssertionContainer = turnSubjectToList(container, converter)
val list = listAssertionContainer.maybeSubject.getOrElse { emptyList() }
val explanatoryGroup = createExplanatoryAssertionGroup(container, assertionCreatorOrNull)
val assertions = mutableListOf<Assertion>(explanatoryGroup)
val assertions = ArrayList<Assertion>(2)
assertions.add(createExplanatoryAssertionGroup(container, assertionCreatorOrNull))
val mismatches = createIndexAssertions(list) { (_, element) ->
!allCreatedAssertionsHold(container, element, assertionCreatorOrNull)
}