I am using a Dir.foreach 'loop' to run a control on every file in a given directory. When I use the Dir.foreach, the tests fail. If I use a describe block for an individual file however, the tests pass. With this code the controls fail:
Dir.foreach("/var/log") do | x |
describe file(x) do
its("owner") { should cmp "root" }
end
end
However, with this code, with the file /var/log/yum.log for example, the tests pass:
describe file("/var/log/yum.log") do
its("owner") { should cmp "root" }
end
Does anyone have an idea what the problem might be? I tried printing the value of 'x' on each line, and one thing I found was that yum.log (for example) is instead yum.log-20190101 Would this have anything to do with it?
For those reading this in the future, I have now fixed this issue. The loop is working fine but it was describing files in the '/' directory, rather than the '/var/log' directory. My code now looks like this and it works fine:
Dir.foreach("/var/log") do |x|
describe file("/var/log/" + x) do
its("owner") { should cmp "root" }
end
end