How to remove constraints on the number of arguments when mocking with Spock?
Asked Answered
A

1

6

Is there a way to accept any number of arguments when mocking a method?

For instance if I want to mock those 2 methods:

foo(String s);
foo(String s, int i);

For now, in my test I do:

myMockedClass.foo(_) >> x
myMockedClass.foo(_, _) >> x

Is there a way to mock both at once? Something like:

myMockedClass.foo(*) >> x

(this doesn't work)

Anastatius answered 12/1, 2012 at 3:28 Comment(0)
H
5

This feature is planned, but doesn't exist yet. The proposed syntax is foo.bar(*_).

Halle answered 12/1, 2012 at 14:1 Comment(1)
Already implemented in the latest snapshot. *_ stands for "any number (including zero) of additional arguments". It must come at the end (but not necessarily at the start) of the argument list.Halle

© 2022 - 2024 — McMap. All rights reserved.