Make it possible to pass map constructor args to Spy #662

snimavat opened this Issue Oct 12, 2016 · 2 comments


None yet

2 participants


When using grails, some time we want to mock some specific methods on a service. We can use the spock Spy for that. However the service has dependency on other services. The service created using the Spy will have those member fields null, resulting in NPE. Spy allows list of constructor args. however that forces us to write a constructor. Groovy objects comes up with a map constructor. Why cant Spy allow a map constructor --

some thing like -- XService service = Spy(Service, constructorArgs:[YService: yservice, xx:xx])

szpak commented Oct 12, 2016

I didn't tested it, but have you tried to pass a map as the first list element?

= Spy(Service, constructorArgs: [[yService: yServiceRef, zService, zServiceRef]])

Seems to work, but it would be great if i can accept the map directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment