toHave

infix fun <E, T : Iterable<E>> Expect<T>.toHave(elements: elements): Expect<T>(source)

Expects that the subject of this expectation (an Iterable) has at least one element.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

expect(listOf("A", 1, 3f)) toHave elements

fails {
    expect(emptyList<Int>()) toHave elements
}

infix fun <T : Iterator<*>> Expect<T>.toHave(next: next): Expect<T>(source)

Expects that the subject of this expectation (an Iterator) has a next element.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

val list = listOf(1)
val iterator = list.iterator()
expect(iterator) toHave next      // holds as iterator has a next element

fails {
    iterator.next()               // returns the next element in iteration
    expect(iterator) toHave next  // fails as list has only 1 element, i.e. no next any more.
}
infix fun <T : Path> Expect<T>.toHave(directoryEntries: DirectoryEntries): Expect<T>(source)

Expects that the subject of this expectation (a Path) is a directory having the provided entries. That means that there is a file system entry at the location the Path points to and that it is a directory. Furthermore, every argument string resolved against the subject yields an existing file system entry.

This assertion resolves symbolic links for the subject, but not for the entries. Therefore, if a symbolic link exists at the location the subject points to, the search will continue at the location the link points at. If a symbolic link exists at one of the entries, this will fulfill the respective assertion and the entry’s symbolic link will not be followed.

This assertion is not atomic with respect to concurrent file system operations on the paths the assertions work on. The result, in particular its extended explanations, may be wrong if such concurrent file system operations take place.

Return

an Expect for the subject of this expectation.

Since

0.17.0

See also

Samples

val dir = tempDir.newDirectory("test_dir")

val file1 = dir.newFile("test_file1")
val file2 = dir.newFile("test_file2")

expect(dir) toHave directoryEntries("test_file1", "test_file2")

file1.delete()
file2.delete()

fails {
    expect(dir) toHave directoryEntries("test_file1", "test_file2")
}