How should I use the `infix fun <T> T.should...
# kotlintest
t
How should I use the
infix fun <T> T.should(matcher: (T) -> Unit)
? What's its purpose ? I use it like this :
Copy code
person.should {
    it.firstName shouldBe "John"
    it.lastName shouldBe "Doe"
}
But that
should
seems redondant to me.
w
shouldBe
checks for equality,
should
accepts a matcher. So you can write things like:
aNumber shouldBe lessThan 4
https://github.com/kotlintest/kotlintest/blob/master/doc/matchers.md here are the matchers. I believe most, if not all, of them can be separated, so if you see
str.shouldHaveLineCount(count)
then you can write
str should haveLineCount(count)
as well
l
That's correct.
We usually have extensions and infix functions for every matcher