0
votes

eg.

Creating Directories using directory resource in chef.

directory '/app/my_app/log' do
   owner 'myuser'
   group 'myuser'
   recursively true
end

Now writing spec for this resource.

it 'creates directory /app' do
        expect(chef_run).to create_directory('/app').with(
            user: 'myuser',
            group: 'myuser'
        )
    end
it 'creates directory /app/my_app' do
        expect(chef_run).to create_directory('/app/my_app').with(
            user: 'myuser',
            group: 'myuser'
        )
    end
it 'creates directory /app/my_app/log' do
        expect(chef_run).to create_directory('/app/my_app/log').with(
            user: 'myuser',
            group: 'myuser'
        )
    end

Is this how one should write spec ? I would like to know if I am doing it wrong, if so then how would you do it ?

Thanks!

1

1 Answers

1
votes

You just check for recursive: true like you have for user and group in the with() call. There is no directory resource created for the intervening directories, just the one.

it 'creates directory /app/my_app/log' do
    expect(chef_run).to create_directory('/app/my_app/log').with(
        user: 'myuser',
        group: 'myuser',
        recursive: true,
    )
end