Any opinions about making `.shouldBeSingleton()` a...
# kotest
s
Any opinions about making
.shouldBeSingleton()
actually return the singleton instead of the original (single-valued) collection? That would allow for nicer chaining of assertions, like
.shouldBeSingleton().shouldBeSuccess()
.
s
I think that makes sense
👍🏻 1
s
It's a breaking change, though, I guess...
s
it is ... which is why I made the ticket instead of just doing it, because we need to think about it
you're right, its better tho
s
👍🏻
c
The stdlib has
List<T>.single(): T
for that, so maybe
shouldBeSingle()
can be added without breaking the existing method?
💯 1
s
Sounds good to me! I always found "singleton" a bit misleading here, as it has nothing to do with the "singleton design pattern" (for classes).
s
agreed. So deprecate original, add
shouldBeSingle
s
Or maybe not even deprecate. It's just two different functions then.
➕ 1
s
true
I've set claude on it
😄 1
we're releasing 6.2 this week I think, so it'll go into that
🎉 1
k
I agree that we should keep the original method and just add
shouldBeSingle
. The original method could still be used like this:
Copy code
actualCollection.shouldBeSingleton().shouldBeTypeInstanceOf<Set<X>>() shouldBe expectedCollection
Also, note that the original post could be written like this, using only existing methods:
Copy code
actualCollection.shouldBeSingleton { it.shouldBeSuccess() }
💯 1
o
Just my five cents: I always struggled with this as well. It is counterintuitive that shouldBeSingleton() returns the collection and not the single element....