mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
Merge pull request #951 from robstoll/fix-feature-extraction-empty-feature
show representation for failure in feature extraction if subject 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)
|
||||
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>)
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -69,14 +69,25 @@ class DefaultFeatureExtractor : FeatureExtractor {
|
||||
)
|
||||
})
|
||||
}
|
||||
container.addAssertion(
|
||||
assertionBuilder.fixedClaimGroup
|
||||
.withFeatureType
|
||||
.failing
|
||||
.withDescriptionAndRepresentation(description, repForFailure)
|
||||
.withAssertions(failureHintAssertions + subAssertions)
|
||||
.build()
|
||||
)
|
||||
val featureAssertions = failureHintAssertions + subAssertions
|
||||
val fixedClaimGroup = assertionBuilder.fixedClaimGroup
|
||||
.withFeatureType
|
||||
.failing
|
||||
.withDescriptionAndRepresentation(description, repForFailure)
|
||||
.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 ->
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user