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.
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()}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With