second

fun <K, V, T : Pair<K, V>> Expect<T>.second(assertionCreator: Expect<V>.() -> Unit): Expect<T>(source)

Expects that the property Pair.second 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.

Samples

val pair = "one" to 1

expect(pair)
    .second { // subject inside this expectation-group is of type Int (actually 1)
        toBeLessThan(2)
    } // subject here is back to type Pair<Int, String>
    .second {
        toBeGreaterThan(0)
    }

fails {
    // all expectations inside an expectation-group are evaluated together; for more details see:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group

    expect(pair)
        .second {
            toBeGreaterThan(2) // fails
            toBeLessThan(0)    // still evaluated even though `toBeGreaterThan` already fails,
            //                    use `.second.` if you want a fail fast behaviour
        }
}

val <V, T : Pair<*, V>> Expect<T>.second: Expect<V>(source)

Creates an Expect for the property Pair.second of the subject of this expectation, so that further fluent calls are assertions about it.

Return

The newly created Expect for the extracted feature.

Samples

val pair = "one" to 1

expect(pair)
    .second             // subject now of type Int (actually 1)
    .toBeLessThan(2)    // subject is still of type Int (still 1)
    .toBeGreaterThan(0)

fails {
    expect(pair)
        .second
        .toBeGreaterThan(2) // fails
        .toBeLessThan(0)    // not evaluated/reported because `toBeGreaterThan` already fails
    //                         use `.second { ... }` if you want that all assertions are evaluated
}