如何使用 serverspec 测试文件缺失?

con*_*sch 6 linux automated-testing testing configuration-management

关于资源类型serverspec 指南没有解释如何测试文件的缺失,而不是它的存在。这是我能想到的最好的:

describe command('/bin/bash -c "[[ ! -e /var/foo ]]"') do
  its(:exit_status) { should eq 0 }
end
Run Code Online (Sandbox Code Playgroud)

这看起来非常笨拙,但比利用内置函数要好:

describe file('/var/foo') do
  it { should_not be_file }
  it { should_not be_directory }
  it { should_not be_socket }
  it { should_not be_symlink }
end
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

con*_*sch 6

serverspecFile对象现在响应.exists?,所以这有效:

describe file('/var/foo') do
  it { should_not exist }
end
Run Code Online (Sandbox Code Playgroud)

该功能在 serverspec v2.17.0中添加的