Open jdsee opened 6 months ago
Yes, the predicate matcher already exists. My request is to accept an optional description to improve the currently hardcoded error message.
Or am I still missing something? 😃
Ah gotcha, I'm a little hesitant to add assertion-specific message overriding. There is some limited ability to override the message, for example you could set the name so that:
assertThat(12, name = "divisible by 5").matchesPredicate { it % 5 }
would give you
org.opentest4j.AssertionFailedError: divisible by 5
expected 12 to satisfy the predicate
otherwise, I would really recommend using a custom assertion, where you can set the message exactly how you want
fun Assert<X>.isSpecial() = given { actual ->
if (!it.isSpecial()) expected("${actual} to satisfy some very special requirements")
}
assertThat(x).isSpecial()
I'm migrating my project to assertk and I have the same feature request. How do I replace my Truth.assertWithMessage()
calls? I was using them as a way to describe my assertions. Here's an example:
Using custom assertions to include messages feels a bit odd.
Perhaps I can use Assert.all(message)
as a stop-gap?
yeah if something is going to be added it would be more general like assertWithMessage()
, there's been a bit of discussion on adding to/customizing the error message but nothing's been settled on. (see https://github.com/willowtreeapps/assertk/discussions/352)
Subscribed to #352!
Hi 👋
It would be great if the
matchesPredicate
assertion would allow a description parameter to be displayed on an assertion error instead of satisfy the predicate.It could look something like this:
which would then result in the error message:
I'm happy to submit a PR for this as soon as I find time for it.