Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show representation for failure in feature extraction if subject defined #951

Merged
merged 1 commit into from
Jul 7, 2021
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>)
```
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down