You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to define custom assertions on a complexe object (I used here Pair just for demonstration), while combining this custom assertion with and the test pass although not all assertions are corrects:
here is an example to reproduce the issue:
@Test
fun testCustomAssertions(){
val result = 1 to "test"
expectThat(result).and {
isEqualTo(3 to "test")
hasLength(4)
}
}
fun Assertion.Builder<Pair<Int, String>>.hasLength(expected: Int): Assertion.Builder<Pair<Int, String>> =
assert("Has length equal to %s", expected) {
expect {
that(it).get { second }
.isNotBlank()
.and {
get { length }.isEqualTo(expected)
}
}
}
The text was updated successfully, but these errors were encountered:
I think the issue here is that you should not use expect / that in that way inside a custom assertion. You're basically creating an entirely new assertion at that point.
This is pretty confusing. Strikt should prevent this, ideally at compile time (although I'm not sure how that would be feasible) but certainly at least at runtime.
If I rewrite your custom assertion like this it works as expected:
fun Assertion.Builder<Pair<Int, String>>.hasLength(expected:Int): Assertion.Builder<Pair<Int, String>> =
compose("Has length equal to %s", expected) {
get { second }
.isNotBlank()
.and {
get { length }.isEqualTo(expected)
}
} then {
if (allPassed) pass() else fail()
}
I need to define custom assertions on a complexe object (I used here Pair just for demonstration), while combining this custom assertion with and the test pass although not all assertions are corrects:
here is an example to reproduce the issue:
The text was updated successfully, but these errors were encountered: