saurg saurg - 1 year ago 65
Ruby Question

Using a Chef InSpec resource before deleting a file

I am running

chef InSpec command
resource which matches output of the command with some content from a file. Then I am deleting that file after using the following resource. But the following command returns
and test fails.

describe command("some command") do
its ('stdout') {should match /some_regex/}

But when I do not delete the file, above command returns expected output. Is there any issue with
resources and deleting the file?

Answer Source

Rspec (and thus InSpec) has it's own two-pass loading model similar (but unrelated and distinct) to Chef's. That means you are probably deleting it before the test gets run, even though it looks like it is after in the code. Try using an after(:all) block? That's the way to do it in normal RSpec, but InSpec deviates from Rspec in some places so I'm not 100% it will work.