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

extension

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

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.

val extension = "txt"
val dir = tempDir.newFile("test_file.$extension")

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

fails {
    expect(dir).extension // subject is now of type String (actually "txt")
        .toEqual("txtt")  // fails because it doesn't equal to "txtt"
        .toEndWith("jpg") // not evaluated/reported because toEqual already fails
    //                       use `.extension { ... } ` 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>.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.

val extension = "txt"
val dir = tempDir.newDirectory("test.$extension")

expect(dir).extension { // subject inside this block is of type String (actually "txt")
    notToBeEmpty()
    toEqual(extension)
    notToEndWith("jpg")
} // subject here is back to type Path

fails {
    expect(dir).extension { // subject inside this block is of type String (actually "txt")
        toEqual("txtt")     // fails because it doesn't equal to "txtt"
        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
}

Return
an Expect for the subject of this expectation.

Since
0.9.0