【发布时间】:2015-09-14 16:27:44
【问题描述】:
我想检查现有目录是否为空(不包含任何文件或子目录)。
我尝试了以下方法:
describe file('/path/to/file') do
it { should be_empty }
end
但这不起作用。 (当然,因为文档中没有提到。)
重要提示:我不想测试,如果目录存在 - 它确实存在并且我无法更改。
我的解决方案现在如下所示:
describe command('ls /data/nginx/cache/services | grep -q .') do
its(:exit_status) { should eq 1 }
end
但这不是使用 Serverspec 资源类型“文件”。有没有更好的方法来测试文件夹是否为空?
【问题讨论】:
-
你不能做类似 Dir["/path/to/file/*"].empty 的事情吗?
-
只是猜测,但可能是这样的:
decribe file('/path/to/dir/*') do it{ should_not exist } end
标签: ruby chef-infra test-kitchen serverspec