Why does shouldHaveSingleElement and other Collection "shoulds" have predicate instead of block for assertions?
See original GitHub issueWhat I do not really get is: when does your library want predicates (T)->Boolean and when does it require a function block that itself can do multiple assertions using matchers and should constructs?
I.e.:
list.shouldHaveSingleElement {
it.name == "Bob"
}
vs. (not the case)
list.shouldHaveSingleElement {
it.name shouldBe "Bob"
}
I’ve stumbled across both ways, but the simple predicate one is used for collections - and I do not like it at all, because the error messages don’t reveal any reason for failing the match whereas the latter one could state that something was expected to be “Bob” but is “Alice” for example.
Is there a reason behind this that I cannot see?
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Core Matchers | Kotest
shouldBe(other), General purpose assertion that the given obj and other are both equal. expr.shouldBeTrue(), Convenience assertion that the expression is ...
Read more >Use io.kotest.matchers.collections.nulls.Collection ... - LambdaTest
Learn how to use Collection.shouldContainNoNulls method in io.kotest.matchers.collections.nulls for your next Kotest project with LambdaTest Automation ...
Read more >Unit 2 Lab 3: Making Decisions by Using Predicates, Page 1
Predicates are reporter blocks (functions) that always report a Boolean value (they report only the values true or false ). In Snap!, they...
Read more >Advanced googletest Topics
Even though googletest has a rich set of assertions, they can never be ... you can instead use the following predicate-formatter assertions to...
Read more >https kotest io docs assertions inspectors html Inspectors | Kotest ...
Inspectors have sort of eluded me.. My typical use-pattern when writing tests is to write my test and go x should... and look...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The std lib has the method .single() to extract only a single element from a list, and throw if the list does not have size 1.
I think the difference here, is that they are single predicates. So each predicate is executed in turn on the next element of the list.
With inspectors, everything in the block is executed every each element, and the counts then compared to the requirements.