spockframework/spock

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

Open

#591 geöffnet am 31. Mai 2016

Auf GitHub ansehen
 (4 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Java (466 Forks)batch import
component:docshelp wanted

Repository-Metriken

Stars
 (3.457 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 8h) (11 gemergte PRs in 30 T)

Beschreibung

    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?

Contributor Guide