saurg saurg - 1 year ago 104
Ruby Question

File names in Chef Inspec

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

For example,

will return all files ending with
. I want to do something similar in
chef inspec

For example

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

It should give me all the file inside
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 Source

* 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) { eq "\n" }