Hey, I've added a very small but convenient extens...
# kotest
c
Hey, I've added a very small but convenient extension to provide scope in an assertSoftly block
Copy code
inline fun <T, R> T.assertSoftly(assertions: T.() -> R): R {
   return io.kotest.assertions.assertSoftly { this.assertions() }
}
Are there any thoughts or objections about adding this to kotest, along with other similar scoping functions? An example of its use:
Copy code
val user = buildUser()
user.assertSoftly {
    name shouldBe "Bob"
    role shouldBe Role.ADMIN
}
s
I thought we had that already tbh
but if not, seems worthwhile to add.
l
No no no
We had a big issue because of that
Let me find the reason why
c
Thanks for the quick reply! I'm curious what problems that code could cause
l
I think it messed up with other kind of tests, kind of overriding the context
It was added in this commit, I'm still to find the reversal
Copy code
inline fun <S, T> S.assertSoftly(crossinline assertions: S.() -> T): T = assertSoftly( { assertions() } as () -> T )
It even has the same signature you proposed, @Chad Moller
This was one of the issues reporting the bugs we had with it
@Ashish Kumar Joy Do you remember this?
c
I'm going to play with this later! I'm curious!!
a
s
You have a good memory @LeoColman! What is the tl;dr on the issue ?
l
I think the gist of it is that having the second case would always pass
Spec
as
this
if you want to use the other case
Nice find @Ashish Kumar Joy! I searched in this channel but didn't think of #kotest-contributors
c
So if I read that correctly, it was an overloading issue. Thanks for the info! You probably saved me some future headaches here. Any thoughts on using a unique name for the receiver object version? assertSoftlyRun, or similar?
s
Apply is the kotlin stblib name for it
assertSoftlyApply ?
applyAssertSoftly
c
I only mentioned run because of the return value. Apply returns the context object itself which shouldn't really matter in this use case that I can think of
s
That's fair
c
And certainly apply makes more grammatical sense
l
applySoftly
sounds cute
assertedSoftly
?
as in
"foo".assertedSoftly { }
foo.assertingSoftly{}
c
"Apply softly" are instructions for lotion
I like all those options tho
s
what about the original name, and just
assertSoftly(object) { }
l
I mean, it's what we have today hahahah