message
fun <T : Throwable> Expect<T>.message(assertionCreator: Expect<String>.() -> Unit): Expect<T>(source)
Expects that the property Throwable.message of the subject of this
expectation is not null and holds all assertions the given assertionCreator creates for it and returns an Expect for the current subject of this
expectation.
Return
an Expect for the subject of this
expectation.
Samples
expect(RuntimeException("abc"))
.message // subject is now of type String
.toContain("a")
fails {
expect(RuntimeException("abc"))
.message
.toContain("d") // fails
.toStartWith("z") // not evaluated/reported because `toContain` already fails
// use `.message { ... }` if you want that all assertions are evaluated
}
Expects that the property Throwable.message of the subject of this
expectation is not null, creates an Expect for it and returns it.
Return
The newly created Expect for the property Throwable.message of the subject of this
expectation.
Samples
expect(RuntimeException("abc")).message { // subject inside this expectation-group is of type String (actually "abc")
toContain("a")
} // subject here is back to type RuntimeException
fails {
expect(RuntimeException("abc")).message { // subject inside this expectation-group is of type String (actually "abc")
toContain("d") // fails
toStartWith("z") // still evaluated even though `toContain` already fails
// use `.message.` if you want a fail fast behaviour
}
}