A dynamic seeker using a Spock

I need help with the Spock test . I'm trying to stub a dynamic domain crawler ( findById

). I cannot use code like:

ObjectDomain.metaClass.static.findById = { -> new ObjectDomain()}

      

because I am using the method findsById

in another part of the test and if I use that I get false positives.

Does anyone know a better way to mute dynamic searchers using Spock?

Thanks in advance.

+3


source to share


1 answer


The argument and argument types must match between your metaclass method and the real method. You added a no-arg method findById()

, but you are calling an overloaded method with an ID and a map. Therefore, you will need to change the closure arguments to match:



ObjectDomain.metaClass.static.findById = { id, Map args -> new ObjectDomain()}

      

+6


source







All Articles