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

its

fun <T, R> Expect<T>.its(extractor: T.() -> R): FeatureExpect<T, R> (source)

Extracts a feature out of the current subject of this expectation with the help of the given extractor, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

val person = Person(name = "John Smith", age = 25)

expect(person)
    .its { age } // subject is now Int
    .toBeLessThan(30)
    .toBeGreaterThan(20)


fails {
    expect(person)
        .its { age }         // subject is now Int
        .toBeLessThan(20)    // fails
        .toBeGreaterThan(30) // not evaluated/reported because `toBeLessThan` already fails
    //                          use `.its { ... }` if you want that all assertions are evaluated
}

Return
The newly created Expect for the extracted feature.

Since
0.16.0

fun <T, R> Expect<T>.its(extractor: T.() -> R, assertionCreator: Expect<R>.() -> Unit): Expect<T> (source)

Extracts a feature out of the current subject of this expectation with the help of the given extractor, creates a new Expect for it, applies an assertion group based on the given assertionCreator for the feature and returns the initial Expect with the current subject.

val person = Person(name = "John Smith", age = 25)

expect(person)
    .its({ age }) { // subject within this block is of type Int
        toBeGreaterThan(18)
        toBeLessThan(35)
    } // subject here is back to type Person

fails {
    expect(person)
        .its({ age }) {
            // introduces an expectation group block
            // all expectations are evaluated inside an expectation group block; for more details:
            // https://github.com/robstoll/atrium#define-single-expectations-or-expectation-groups

            toBeGreaterThan(40) // fails
            toBeLessThan(50)    // still evaluated, use `.its.` if you want fail fast behaviour
        }
}

Return
an Expect for the subject of this expectation.

Since
0.16.0