extension

infix fun <T : Path> Expect<T>.extension(assertionCreator: Expect<String>.() -> Unit): Expect<T>(source)

Expects that the property Path.extension (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 extension = "txt"
val dir = tempDir.newDirectory("test.$extension")


expect(dir) extension { // subject inside this expectation-group is of type String (actually "txt")
    it notToBe empty
    it toEqual extension
    it notToEndWith "jpg"
} // subject here is back to type Path

fails {
    expect(dir) extension { // subject inside this expectation-group is of type String (actually "txt")
        it toEqual "txtt"     // fails because it doesn't equal to "txtt"
        it toEndWith "jpg"    // fails because it doesn't end with "jpg"
        //                       use `.extension` if you want fail fast behaviour
    } // subject here is back to type Path
}

Creates an Expect for the property Path.extension (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 extension = "txt"
val dir = tempDir.newFile("test_file.$extension")

expect(dir).extension notToBe empty toEqual extension notToEndWith ("jpg")
//          | subject is now of type String (actually "txt")

fails {
    expect(dir).extension toEqual "txtt" toEndWith "jpg"
    //          |           |              | not reported because toEqual already fails
    //          |           |              | use `extension { ... }` if you want that all expectations are evaluated
    //          |           | fails because it doesn't equal to "txtt"
    //          | subject is now of type String (actually "txt")
}