mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
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:
@@ -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)
|
We once again use `feature` with an [assertion group block](#define-single-assertions-or-assertion-groups)
|
||||||
for the same reason as above.
|
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 --
|
Note how `toHaveElementsAndAll` already checks that there is at least one element.
|
||||||
but we do not have to, as `all` 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>
|
<ex-own-compose-4>
|
||||||
|
|
||||||
@@ -2208,7 +2208,6 @@ expected that subject: Person(firstName=Susanne, lastName=Whitley, age=43, child
|
|||||||
◆ ▶ children: [] (kotlin.collections.EmptyList <1234789>)
|
◆ ▶ children: [] (kotlin.collections.EmptyList <1234789>)
|
||||||
◾ has: a next element
|
◾ has: a next element
|
||||||
» all entries:
|
» all entries:
|
||||||
» ▶ age:
|
|
||||||
» ▶ age:
|
» ▶ age:
|
||||||
◾ is greater than or equal to: 18 (kotlin.Int <1234789>)
|
◾ is greater than or equal to: 18 (kotlin.Int <1234789>)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3
|
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.aSuccess
|
||||||
import ch.tutteli.atrium.api.infix.en_GB.success
|
|
||||||
import ch.tutteli.atrium.creating.Expect
|
import ch.tutteli.atrium.creating.Expect
|
||||||
import ch.tutteli.atrium.specs.integration.ResultExpectationsSpec
|
import ch.tutteli.atrium.specs.integration.ResultExpectationsSpec
|
||||||
import ch.tutteli.atrium.specs.notImplemented
|
import ch.tutteli.atrium.specs.notImplemented
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package custom
|
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.fluent.en_GB.toEqual
|
||||||
import ch.tutteli.atrium.api.verbs.expect
|
import ch.tutteli.atrium.api.verbs.expect
|
||||||
import ch.tutteli.atrium.assertions.Assertion
|
import ch.tutteli.atrium.assertions.Assertion
|
||||||
@@ -25,7 +25,7 @@ object SmokeSpec : Spek({
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("see if `Result.isSuccess` can be used") {
|
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") {
|
test("see if own assertion function without i18n can be used") {
|
||||||
|
|||||||
@@ -69,14 +69,25 @@ class DefaultFeatureExtractor : FeatureExtractor {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
container.addAssertion(
|
val featureAssertions = failureHintAssertions + subAssertions
|
||||||
assertionBuilder.fixedClaimGroup
|
val fixedClaimGroup = assertionBuilder.fixedClaimGroup
|
||||||
.withFeatureType
|
.withFeatureType
|
||||||
.failing
|
.failing
|
||||||
.withDescriptionAndRepresentation(description, repForFailure)
|
.withDescriptionAndRepresentation(description, repForFailure)
|
||||||
.withAssertions(failureHintAssertions + subAssertions)
|
.withAssertions(featureAssertions)
|
||||||
.build()
|
.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())
|
createFeatureExpect(None, listOf())
|
||||||
},
|
},
|
||||||
{ subject ->
|
{ subject ->
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ class DefaultIterableLikeAssertions : IterableLikeAssertions {
|
|||||||
val listAssertionContainer = turnSubjectToList(container, converter)
|
val listAssertionContainer = turnSubjectToList(container, converter)
|
||||||
val list = listAssertionContainer.maybeSubject.getOrElse { emptyList() }
|
val list = listAssertionContainer.maybeSubject.getOrElse { emptyList() }
|
||||||
|
|
||||||
val explanatoryGroup = createExplanatoryAssertionGroup(container, assertionCreatorOrNull)
|
val assertions = ArrayList<Assertion>(2)
|
||||||
val assertions = mutableListOf<Assertion>(explanatoryGroup)
|
assertions.add(createExplanatoryAssertionGroup(container, assertionCreatorOrNull))
|
||||||
val mismatches = createIndexAssertions(list) { (_, element) ->
|
val mismatches = createIndexAssertions(list) { (_, element) ->
|
||||||
!allCreatedAssertionsHold(container, element, assertionCreatorOrNull)
|
!allCreatedAssertionsHold(container, element, assertionCreatorOrNull)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user