Is there any way to do mock argument capturing in Spock

You can capture an argument as follows:

// must be declared before when-block (or inside Specification.interaction {})
def captured

when:
...

then:
1 * mock.doNetworkCall(...) >> { record, recordClass -> 
    // save the argument
    captured = record
    ...
}
// use the saved argument
captured == ...

That said, often there is a simpler solution such as checking the expected record right in the argument constraint (e.g. ...doNetworkCall( { it == ... } )).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)