strikt
strikt copied to clipboard
Or conjunction
Would it be possible to add an or conjunction for the case that there are multiple ways to pass a test?
Example:
val value: String = nextMagicValue()
expectThat(value).or {
isEqualTo("3.14")
isEqualTo("42")
}
It should be possible, I think. It's fundamentally similar to the any
conjunction that already exists for Assertion.Builder<Iterable<*>>
.
Personally, I think the proposed syntax is a bit odd. If it opens a lambda, maybe it should be anyOf
or oneOf
or something along those lines? Or maybe or
could be an infix operator?
val value: String = nextMagicValue()
expectThat(value).oneOf {
isEqualTo("3.14")
isEqualTo("42")
}
val value: String = nextMagicValue()
expectThat(value) {
isEqualTo("3.14") or isEqualTo("42")
}
I like your oneOf
suggestion :)
I would very much welcome a oneOf
method. My use case is that in the test I get a list of two (complex) objects. I know all assertions I need to perform on them, but I don't know which of the two object comes first in the list.
@MartinHaeusler easiest way is to sort list first and then do you assertions in expected order