saurg saurg - 4 months ago 30
Ruby Question

File names in Chef Inspec

In ruby, * is used to represent the name of a file.

For example,

/home/user/*.rb
will return all files ending with
.rb
. I want to do something similar in
chef inspec
.

For example

describe file ('home/user/*') do
it {should_not exist }
end


It should give me all the file inside
/home/user
directory and check that no file exists inside this directory.In other words, I want to check if this directory is empty or not in chef.

How can I do that?

Answer

* for globs is mostly a shell feature, and as you might expect the file resource doesn't support them. Use a command resource instead:

describe command('ls /home/user') do
  its(:stdout) { is_expected.to eq "\n" }
end