val <T : Collection<*>> Expect<T>.size: Expect<Int>
(source)
Creates an Expect for the property Collection.size of the subject of this
expectation,
so that further fluent calls are assertions about it.
expect(listOf(1, 2, 3))
.size isGreaterThan 1 isLessThan 4
//| | | subject is still of type Int (still 3)
//| | subject is still of type Int (still 3)
//| subject is now of type Int (actually 3)
fails {
expect(listOf(1, 2, 3))
.size isLessThan 1 isGreaterThan 4
//| | | not reported because `isLessThan 1` already fails
//| | fails
//| subject is now of type Int (actually 3)
} message {
contains("${isLessThanDescr}: 1")
containsNot("${isGreaterThanDescr}: 4")
}
Return
The newly created Expect for the extracted feature.
infix fun <E, T : Collection<E>> Expect<T>.size(assertionCreator: Expect<Int>.() -> Unit): Expect<T>
(source)
Expects that the property Collection.size of the subject of this
expectation
holds all assertions the given assertionCreator creates for it and
returns an Expect for the current subject of this
expectation.
expect(listOf(1, 2, 3)) size { // subject inside this block is of type Int (actually 3)
it isGreaterThan 1
} size { // subject inside this block is of type Int (actually 3)
it isLessThan 4
}
fails {
// all assertions are evaluated inside an assertion group block; for more details:
// https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
expect(listOf(1, 2, 3)) size { // subject inside this block is of type Int (actually 3)
it isLessThan 1 // fails
it isGreaterThan 4 // isLessThan 1 fails, but isGreaterThan 4 still evaluated
// use `.size.` if you want a fail fast behaviour
}
} messageContains values(
"${isLessThanDescr}: 1",
"${isGreaterThanDescr}: 4"
)
Return
an Expect for the subject of this
expectation.