strikt icon indicating copy to clipboard operation
strikt copied to clipboard

Or conjunction

Open pmwmedia opened this issue 5 years ago • 5 comments

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")
}

pmwmedia avatar Dec 19 '19 23:12 pmwmedia

It should be possible, I think. It's fundamentally similar to the any conjunction that already exists for Assertion.Builder<Iterable<*>>.

robfletcher avatar Dec 21 '19 05:12 robfletcher

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")
}

cjbrooks12 avatar Dec 21 '19 21:12 cjbrooks12

I like your oneOf suggestion :)

pmwmedia avatar Dec 21 '19 22:12 pmwmedia

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 avatar Jan 13 '20 11:01 MartinHaeusler

@MartinHaeusler easiest way is to sort list first and then do you assertions in expected order

qoomon avatar May 30 '20 08:05 qoomon