title: Spock framework: matching wildcard arguments
body: <p>I am trying to write a Spock specification, where I want to verify a method that is being called with three arguments. I don't care about the first two at all, any instance of the argument types would do.
  I'm trying to use Spock wildcard argument matching but keep running into issues. My verification looks like this:</p>
  
  <pre><code>    when:
      packageUploadController.handleUpload(httpRequest)
  
      then: "the value of the 'dest' parameter is passed on to saveservice"
      saveService.saveImportPackage(_ as UploadedPackage, _ as PackageImportResponse.Builder)
  </code></pre>
  
  <p>Here <code>saveService</code> is a mock and UploadedPackage and PackageImportResponse.Builder are the expected arguments; I'm trying to get to a working test first before changing the code that calls saveService.</p>
  
  <p>As far as I can see I'm doing this as documented, however the test fails with the following message: </p>
  
  <pre><code>org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
  Cannot cast object '_' with class 'org.spockframework.lang.Wildcard' to 
  class 'UploadedPackage' due to:
  groovy.lang.GroovyRuntimeException: Could not find matching constructor for: 
  UploadedPackage(org.spockframework.lang.SpreadWildcard)
  </code></pre>
  
  <p>I don't understand this message as it seems to indicate that my production code needs to provide a constructor taking a <code>SpreadWildCard</code> as an argument. What am I doing wrong here?</p>
  
  <p>I also tried leaving the types out and just match on <code>(_, _)</code>, however this also fails:</p>
  
  <pre><code>org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: 
  SaveService$$EnhancerByCGLIB$$67b7324.saveImportPackage() is applicable for argument types: (org.spockframework.lang.Wildcard, org.spockframework.lang.Wildcard) values: [[*_], [*_]]
  </code></pre>
  
  <p>Here also I think I'm doing it as per the documentation, and don't understand why this fails (I added the types later to try and get rid of this error).</p>