doc / ch.tutteli.atrium.api.fluent.en_GB / fileName

fileName

val <T : Path> Expect<T>.fileName: Expect<String> (source)

Creates an Expect for the property Path.fileNameAsString (provided via niok) of the subject of this expectation, so that further fluent calls are assertions about it.

val dir = tempDir.newDirectory("test_dir")

expect(dir).fileName // subject is now of type String (actually "test_dir")
    .toEndWith("dir")
    .toStartWith("test")
    .notToBeBlank()

fails {
    expect(dir).fileName        // subject is now of type String (actually "test_dir")
        .toEndWith("foo")       // fails because it does not end with "foo"
        .toStartWith("invalid") // not evaluated/reported because toEndWith already fails
    //                             use `fileName {...}` 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>.fileName(assertionCreator: Expect<String>.() -> Unit): Expect<T> (source)

Expects that the property Path.fileNameAsString (provided via niok) 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.

val dir = tempDir.newDirectory("test_dir")

expect(dir).fileName { // subject inside this block is of type String (actually "test_dir")
    toEndWith("dir")
    toStartWith("test")
    notToBeBlank()
} // subject here is back to type Path

fails {
    expect(dir).fileName {      // subject inside this block is of type String (actually "test_dir")
        toEndWith("foo")        // fails because it does not end with "foo"
        toStartWith("invalid")  // still evaluated even though toEndWith already fails
        //                         use `.fileName.` if you want fail fast behaviour
    }  // subject here is back to type Path
}

Return
an Expect for the subject of this expectation.

Since
0.9.0