resolve

fun <T : Path> Expect<T>.resolve(other: String): Expect<Path>(source)

Expects that other resolves against this Path and creates an Expect for the resolved Path so that further fluent calls are assertions about it.

Return

The newly created Expect for the extracted feature.

Since

0.10.0

Samples

val dir = tempDir.newDirectory("test_dir")
val fileInDir = dir.newFile("test_file.txt")

expect(dir).resolve("test_file.txt") // subject changes to `test_dir/test_file.txt`
    .toEqual(fileInDir)
    .toEndWith(Paths.get("test_file.txt"))

fails {
    expect(dir).resolve("test_file.ttt")
        .toEqual(fileInDir)          // fails because resolve returns *test_file.ttt and fileInDir equals *test_file.txt
        .toEndWith(Paths.get("ttt")) // not evaluated/reported toEqual already fails
    //                                  use `.resolve(other) { ... }` if you want that all expectations are evaluated
}

fun <T : Path> Expect<T>.resolve(other: String, assertionCreator: Expect<Path>.() -> Unit): Expect<T>(source)

Expects that other resolves against this Path, that the resolved Path 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.10.0

Samples

val dir = tempDir.newDirectory("test_dir")
val fileInDir = dir.newFile("test_file.txt")

expect(dir).resolve("test_file.txt") { // subject inside this expectation-group refers to `test_dir/test_file.txt`
    toEqual(fileInDir)
    toExist()
} // subject here is back to `test_dir`

fails {
    expect(dir).resolve("test_file.ttt") {
        toEqual(fileInDir) // fails
        toExist()          // still evaluated even though toEqual already fails
        //                    use `.resolve(other).` if you want a fail fast behaviour
    }
}