6

The serverspec guide on resource types doesn't explain how to test for the absence of a file, rather than its presence. This is the best I could come up with:

describe command('/bin/bash -c "[[ ! -e /var/foo ]]"') do
  its(:exit_status) { should eq 0 }
end

That seems terribly clunky, but better than leveraging the builtins:

describe file('/var/foo') do
  it { should_not be_file }
  it { should_not be_directory }
  it { should_not be_socket }
  it { should_not be_symlink }
end

Is there a better way to do this?

conorsch
  • 339
  • 3
  • 10

1 Answers1

6

The serverspec File object now responds .exists?, so this works:

describe file('/var/foo') do
  it { should_not exist }
end

The feature was added in serverspec v2.17.0.

conorsch
  • 339
  • 3
  • 10