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
// you can use withFailureDescription if you want to specify a custom failure description instead of using
// the default one.
// 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
this extractSubject withFailureDescription("no person defined, cannot extract subject") { 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)
}
}
}
}
}