parent

infix 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.

Return

an Expect for the subject of this expectation.

Since

0.12.0

Samples

val dir = tempDir.newDirectory("test_dir_1")
val dir2 = tempDir.newDirectory("test_dir_2")

expect(dir) parent { // subject inside this expectation-group refers to path corresponding to `test_dir_1/..`
    it toEqual dir2.parent
    it toBe existing
} // subject here is back to `test_dir_1`

fails {
    val dir3 = dir2.newDirectory("test_dir")
    expect(dir) parent {
        it toEqual dir3     // fails because dir3 and dir do not have same parents
        it notToBe existing // still evaluated even though `toEqual(dir3)` already fails
        //                     use `.parent` if you want a fail fast behaviour
    }
}

Expects that this Path has a parent and creates an Expect for it, so that further fluent calls are assertions about it.

Return

The newly created Expect for the extracted feature.

Since

0.12.0

Samples

val dir = tempDir.newDirectory("test_dir_1")
val dir2 = tempDir.newDirectory("test_dir_2")

expect(dir).parent toEqual dir2.parent toBe existing

fails {
    val dir3 = dir2.newDirectory("test_dir")
    expect(dir).parent toEqual (dir3) notToBe existing
    //                   |              | not reported `toEqual(dir3)` already fails
    //                   |              | use `.parent { ... }` if you want that all expectations are evaluated
    //                   | fails because dir3 and dir do not have same parents
}