Search code examples
testinggroovyspock

What _ (underscore) means in Spock tests?


In one of the Spock tests I see a strange condition in then block:

0 * someInstance._

What does it mean?


Solution

  • _ is a wildcard, any object. See here to find how its exactly implemented and here for the docs. _ it's used for instance to check invocation of a method which argument does not matter, then it looks like:

    1 * obj.method(1, _)
    

    In this particular case it's checked if method method on instance obj was invoked exactly once with 1 as a first argument and anything as a second.