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

asPath

fun <T : File> Expect<T>.asPath(): Expect<Path> (source)

Turns Expect<File> into Expect<Path>.

The transformation as such is not reflected in reporting. Use feature(File::toPath) if you want to show the transformation in reporting.

val file = tempDir.newFile("target").toFile()

expect(file)
  .asPath() // subject is now of type Path
  .toBeARegularFile()

fails {
    expect(file)
      .asPath()
      .toBeADirectory()  //fails
}

Return
The newly created Expect for the transformed subject.

Since
0.9.0

fun <T : File> Expect<T>.asPath(assertionCreator: Expect<Path>.() -> Unit): Expect<T> (source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject as Path.

The transformation as such is not reflected in reporting. Use feature(File::toPath, assertionCreator) if you want to show the transformation in reporting.

val file = tempDir.newFile("target").toFile()

expect(file).asPath { // subject within this block is of type Path
    toBeARegularFile()
    toStartWith(tempDir)
} // subject here is back to type File

fails {
    // all assertions are evaluated inside an assertion group block; for more details:
    // https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups

    expect(file).asPath {
        toBeADirectory()        // fails
        notToStartWith(tempDir) // still evaluated, use `.asPath().` if you want a fail fast behaviour
    }
}

Return
an Expect for the subject of this expectation.

Since
0.9.0