Reputation: 45
I need help with a Spock test.
I am trying to stub a Domain Object's dynamic finder (findById
).
I can't use code like:
ObjectDomain.metaClass.static.findById = { -> new ObjectDomain()}
because I use the findsById
method in other part of the test and if I use that I get false positives.
anybody knows the best way to stub dynamic finders using Spock?
Thanks in advance.
Upvotes: 4
Views: 566
Reputation: 75671
The argument number and types have to match between your metaclass method and the real method. You added a no-arg findById()
method but you're calling an overloaded method with an id and a Map. So you'd need to change the closure args to match:
ObjectDomain.metaClass.static.findById = { id, Map args -> new ObjectDomain()}
Upvotes: 7