spockframework/spock

Mocking: Variables of Closure type aren't evaluated as code args

Open

#591 aperta il 31 mag 2016

Vedi su GitHub
 (4 commenti) (1 reazione) (0 assegnatari)Java (466 fork)batch import
component:docshelp wanted

Metriche repository

Star
 (3457 star)
Metriche merge PR
 (Merge medio 2g 8h) (11 PR mergiate in 30 g)

Descrizione

    def beatIt = {
      def result = (it >= now)
      Thread.sleep(1)
      now = System.currentTimeMillis()
      return result
    }

    when:
    task.execute(context)

    then:
    1 * loggingService.startJob(job, _, beatIt) >> jobExec    // doesn't work
    1 * loggingService.startJob(job, _, { beatIt(it) }) >> jobExec // works

Example is from one of my tests, where I discovered it.

From what I can tell, it is related to how you decide what is a code argument in the InteractionRewriter.addArg method. Maybe try also inspecting any VariableExpressions for closure type?

Guida contributor