Is there a way to group assertSoftly into one matc...
# kotest
l
Is there a way to group assertSoftly into one matcher that can be reused ?
Copy code
assertSoftly(foo) {
    shouldNotEndWith("b")
    length shouldBe 3
}
->
foo shouldBe customAssert
s
You could write a custom matcher that calls assert softly
l
I have seen in the doc how to build a custom matcher but it requires a boolean I don't how to link it to assertSoftly Do you have an example ?
Copy code
fun containFoo() = object : Matcher<String> {
  override fun test(value: String) = MatcherResult(value.contains("foo"), "String $value should include foo", "String $value should not include foo")
}
s
The result would be whatever was in that function you wanted to create
I can make an example. Give me an hour or so
l
ok thanks a lot :)
s
Copy code
fun customAssert() = Matcher<String> { foo ->
   val error = try {
      assertSoftly(foo) {
         shouldNotEndWith("b")
         length shouldBe 3
      }
      null
   } catch (e: Throwable) {
      e
   }
   MatcherResult(error == null, "should not have failed", "should have failed")
}
❤️ 1