Search code examples
rubyrspecchef-infrainspec

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/}
end

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


Solution

  • Rspec (and thus InSpec) has its 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.