robfletcher
11/26/2018, 5:06 PMdave08
11/26/2018, 5:15 PMisOneOf("this", "that")
on String
validation...dave08
11/26/2018, 5:16 PMrobfletcher
11/26/2018, 5:17 PMdave08
11/26/2018, 5:19 PMfun <T : Any> Assertion.Builder<T>.isOneOf(vararg expected: T): Assertion.Builder<T> =
assert("is one of %s", expected) {
when {
expected.contains(it) -> pass()
else -> fail()
}
}
robfletcher
11/26/2018, 5:19 PMdave08
11/26/2018, 5:21 PMall { isOneOf("this", "that") }
, but I think there could still be some short cut containsOneOf
and the console printout is too verbose using this workaround...robfletcher
11/26/2018, 5:39 PMdave08
11/27/2018, 4:32 PMfun <T : Iterable<E>, E> Assertion.Builder<T>.only(expected: Int, predicate: Assertion.Builder<E>.() -> Unit): Assertion.Builder<T> =
compose("only $expected elements match:") { subject ->
subject.forEach { element ->
get("%s") { element }.apply(predicate)
}
} then {
// I need the amount of assertions that passed here... anyPassed doesn't help here...
if (anyPassed) pass() else fail()
}
@robfletcherrobfletcher
11/27/2018, 5:01 PMdave08
11/27/2018, 5:02 PMfailedCount
and successfulCount
on CompoundAssertion
would help too 🙂robfletcher
11/27/2018, 5:03 PMexpectThat(list)
.get { it.filter(predicate) }
.size
.isGreaterThan(2)
robfletcher
11/27/2018, 5:03 PMrobfletcher
11/27/2018, 5:04 PMfilter
to Strikt’s API for Assertion.Builder<Collection<T>>
mkobit
11/27/2018, 5:05 PMatLeast
and other quantitative assertions for collectionsrobfletcher
11/27/2018, 5:06 PMdave08
11/27/2018, 5:07 PMonly
meaning isEqualTo
not isGreaterThan
. Filter would certainly be great! But what do you think about failedCount
and successfulCount
on CompoundAssertion
?robfletcher
11/27/2018, 5:08 PMrobfletcher
11/27/2018, 5:09 PMdave08
11/27/2018, 5:10 PMfilterIsInstance
before my matching pretty often (I have a list of objects with a common base class, in the same list and making assertions on it).dave08
11/27/2018, 5:18 PMget
after isA
failed in an expectThat() { }
block the tests crash with ClassCastException
instead of reporting the errors. Is this by design @robfletcher?robfletcher
11/27/2018, 5:18 PMchristophsturm
11/27/2018, 5:19 PMdave08
11/27/2018, 5:22 PMdata class Test(val a: String)
data class Test2(val b: String)
val i = Test("this")
expectThat(i) {
isA<Test2>().get { b }.isEqualTo("that")
}
christophsturm
11/27/2018, 5:24 PMdave08
11/27/2018, 5:25 PMrobfletcher
11/27/2018, 5:25 PMdave08
11/27/2018, 5:27 PMat strikt.internal.AssertionBuilder.get(AssertionBuilder.kt:64)
at strikt.api.Assertion$Builder$DefaultImpls.get(Assertion.kt:233)
at strikt.api.DescribeableBuilder$DefaultImpls.get(DescribeableBuilder.kt)
at strikt.internal.AssertionBuilder.get(AssertionBuilder.kt:10)
dave08
11/28/2018, 12:20 PMdave08
11/28/2018, 12:21 PM