What does _ (underscore) mean in Spock tests?

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

0 * someInstance._ 

What does it mean?

+6
source share
2 answers

_ is a wildcard for any object. See here for how it is precisely implemented and here for documents. _ he used, for example, to test the invocation of a method whose argument does not matter, then it looks like this:

1 * obj.method(1, _)

In this particular case, he checked if the method method in the obj instance was exactly once with 1 as the first argument and something like a second.

+9
source

EDIT . My answer does not address the problem of operators and relates to an unrelated problem. The correct answer can be seen above.


_ often used to refer to personal content / variables in languages ​​like Groovy/Javascript , which now follow or provide visibility directives.

While you can access them from outside the class or instance, the developer is trying to tell you that this variable is for internal use only.

0
source

Source: https://habr.com/ru/post/979383/


All Articles