val <T : Path> Expect<T>.parent: Expect<Path>
(source)
Expects that this Path has a parent and creates an Expect for it, so that further fluent calls are assertions about it.
val dir = tempDir.newDirectory("test_dir_1")
val dir2 = tempDir.newDirectory("test_dir_2")
expect(dir).parent.toEqual(dir2.parent).toExist()
fails {
val dir3 = dir2.newDirectory("test_dir")
expect(dir).parent
.toEqual(dir3) // fails because dir3 and dir do not have same parents
.notToExist() // not evaluated/reported because toEqual already fails
// use `.parent { ... }` if you want that all expectations are evaluated
}
Return
The newly created Expect for the extracted feature.
Since
0.9.0
fun <T : Path> Expect<T>.parent(assertionCreator: Expect<Path>.() -> Unit): Expect<T>
(source)
Expects that this Path has a parent, that the parent holds all assertions the
given assertionCreator creates for it and returns an Expect for the current subject of this
expectation.
val dir = tempDir.newDirectory("test_dir_1")
val dir2 = tempDir.newDirectory("test_dir_2")
expect(dir).parent { // subject inside this block refers to path corresponding to `test_dir_1/..`
toEqual(dir2.parent)
toExist()
} // subject here is back to `test_dir_1`
fails {
val dir3 = dir2.newDirectory("test_dir")
expect(dir).parent {
toEqual(dir3) // fails because dir3 and dir do not have same parents
notToExist() // still evaluated even though toEqual already fails
// use `.parent.` if you want a fail fast behaviour
}
}
Return
an Expect for the subject of this
expectation.
Since
0.9.0