withFailureDescription

fun <T> withFailureDescription(failureDescription: String, assertionCreator: Expect<T>.(T) -> Unit): FailureDescriptionWithCreator<T>(source)

Helper function to create a FailureDescriptionWithCreator based on the given failureDescription and assertionCreator -- allows expressing KClass<*>, vararg KClass<*>.

Since

1.2.0

Samples

// imagine the data generator should not return an empty list
val persons = dataGenerator.getRandomPersonsHasABugReturnsEmptyList()
fails { // because persons is empty
    expect(persons) toHaveElementsAndAll { // fails
        // hence the sub-expectations within extractSubject cannot be evaluated
        // and instead we show the custom failure description
        withFailureDescription<Person2>("no person defined, cannot extract subject") {
            extractSubject { person ->
                feature { f(it::children) } notToHaveElementsOrAll {
                    because("person should at least be 16 years older than its children") {
                        feature { f(it::age) } toBeLessThan person.age - 16
                    }
                }
            }
        }
    }
}