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])
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.