groovy - spock 在这个测试中是如何调用这个函数的?
问题描述
我正在浏览这个示例,但它的某些内容让我非常困惑:https ://www.testcookbook.com/book/groovy/jenkins/intro-testing-job-dsl.html
在这个测试中,如何/执行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属性,然后允许它利用快捷表示法来访问属性。
推荐阅读
- mysql - 如何仅对 MySQL 中的数据子集强制执行区分大小写的唯一索引?
- reactjs - 从窗口获取路径名并将其存储在状态中以在 fetch 函数中使用
- ruby-on-rails - 如何从 Rails 中的 f.select 中删除 Null 值?
- opencv - “'cv2.face'没有属性'LBPHFaceRecognizer_create'”但是如果从pip安装,gui会给出qt线程错误
- cloud-foundry - 无法使用 Steeltoe 中的配置服务器服务从 GIT 存储库中读取属性键值
- c - C程序,将参数传递给信号处理函数?
- android - Android Studio Layout Preview 卡住加载
- sql-server - 将 Excel 数据从 Azure Data Lake 加载到 Azure SQL 的理想方式
- c# - 直接访问 UserControl 的 DataContext,无需中介 DepProps:可能吗?
- c# - 将 C# 数组作为函数参数传递以分配其内存不起作用