fileName

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.

Return

an Expect for the subject of this expectation.

Since

0.12.0

Samples

val dir = tempDir.newDirectory("test_dir")

expect(dir) fileName { // subject inside this expectation-group 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 expectation-group 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
}

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.

Return

The newly created Expect for the extracted feature.

Since

0.12.0

Samples

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")
}