spock 在这个测试中是如何调用这个函数的?

How is spock calling this function in this test?

我正在看这个例子,但其中有一些东西让我很困惑:https://www.testcookbook.com/book/groovy/jenkins/intro-testing-job-dsl.html

在这个测试中,how/what正在执行getJobFiles()?我没有看到它在任何地方被调用。 jobFiles 有什么魔力吗?指定 jobFiles 是否以某种方式调用 getJobFiles?

import javaposse.jobdsl.dsl.DslScriptLoader
import javaposse.jobdsl.plugin.JenkinsJobManagement
import org.junit.ClassRule
import org.jvnet.hudson.test.JenkinsRule
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

class JobScriptsSpec extends Specification {
    @Shared
    @ClassRule
    JenkinsRule jenkinsRule = new JenkinsRule()

    @Unroll
    def 'test script #file.name'(File file) {
        given:
        def jobManagement = new JenkinsJobManagement(System.out, [:], new File('.'))

        when:
        new DslScriptLoader(jobManagement).runScript(file.text)

        then:
        noExceptionThrown()

        where:
        file << jobFiles
    }

    static List<File> getJobFiles() {
        List<File> files = []
        new File('jobs').eachFileRecurse {
            if (it.name.endsWith('.groovy')) {
                files << it
            }
        }
        files
    }
}

编辑

似乎 jobFiles 确实调用了 getJobFiles(),但我不明白如何调用。这是 groovy 还是 spock 功能?我一直在尝试对此进行研究,但可以找到任何详细解释的内容。

编辑

当Groovy 确定jobFiles 不引用任何现有变量时,它将名称视为Groovy property,然后允许它利用访问属性的快捷符号。

这是标准的 Groovy 功能。您可以缩写任何 getter 调用,如

def file = new File("sarek-test-parent/sarek-test-common/src/main/java")
println file.name          // getName()
println file.parent        // getParent()
println file.absolutePath  // getAbsolutePath()
println file.directory     // isDirectory()
java
sarek-test-parent\sarek-test-common\src\main
C:\Users\alexa\Documents\java-src\Sarek\sarek-test-parent\sarek-test-common\src\main\java
true

二传手同样适用:

new Person().name = "John"      // setName("John")
new Person().zipCode = "12345"  // setZipCode("12345")

实际上 jaco0646 提供的第二个 link 解释了它,只是他将这个简单的事实与数据提供者混淆了解释。