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?

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.