I want to check, if an existing directory is empty (does not contain any files or sub-directories).
I tried the following:
describe file('/path/to/file') do
it { should be_empty }
end
But this doesn't work. (Of course, as it is not mentioned in the docs.)
Important: I do not want to test, if the directory exists - it does exist and I can't change that.
My solution now looks as follows:
describe command('ls /data/nginx/cache/services | grep -q .') do
its(:exit_status) { should eq 1 }
end
But thats not using the Serverspec resource type 'file'. Is there a better way to test for a folder to be empty?