While upgrading one of my cookbooks to Chef 14.5.33 (ChefDK 3.3.23), I noticed some test failures around the title of exceptions raised by Chef's validation on required properties within custom resources.

describe'...'docontext'When site type is an empty string'do# ...it'throws an error'doexpect{chef_run.converge(described_recipe)}.to\raise_error(Chef::Exceptions::ValidationFailed,%r{site_type is required})endendend

This would unfortunately fail the ChefSpec run, with the following error:

This was odd, as running in Chef 13.6.4 (ChefDK 2.4.17) worked successfully.

As the error suggests, it's due to a change in the error's message, which is resolved with the very straightforward change:

describe 'cookbook-spectat::_caddy_resource' do
context 'When site type is an empty string' do
# ...
it 'throws an error' do
expect { chef_run.converge(described_recipe) }.to\
- raise_error(Chef::Exceptions::ValidationFailed, %r{site_type is required})
+ raise_error(Chef::Exceptions::ValidationFailed, %r{site_type is a required property})
end
end
end

Written by Jamie Tanna on 12 November 2018, and last updated on 30 December 2018.