doc / ch.tutteli.atrium.api.infix.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 toEndWith "dir" toStartWith "test" notToBe blank
//          | subject is now of type String (actually "test_dir")

fails {
    expect(dir).fileName toEndWith "foo" toStartWith "invalid"
    //          |          |               | not reported
    //          |          |               | use `fileName {...}` if you want that all expectations are evaluated
    //          |          | fails because it does not end with "foo"
    //          | subject is now of type String (actually "test_dir")
}

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix 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")
    it toEndWith "dir"
    it toStartWith "test"
    it notToBe blank
} // subject here is back to type Path

fails {
    expect(dir) fileName {        // subject inside this block is of type String (actually "test_dir")
        it toEndWith "foo"        // fails because it does not end with "foo"
        it 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.12.0