spockframework/spock

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

Open

#591 创建于 2016年5月31日

在 GitHub 查看
 (4 评论) (1 反应) (0 负责人)Java (466 fork)batch import
component:docshelp wanted

仓库指标

Star
 (3,457 star)
PR 合并指标
 (平均合并 2天 8小时) (30 天内合并 11 个 PR)

描述

    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?

贡献者指南