simple_approvals/chefspec
a simple chefspec-based implementation of the ApprovalTests pattern
Usage
-
Update your
Gemfile
to include:gem 'simple_approvals-chefspec'
-
Update
spec_helper.rb
to include:require 'simple_approvals/chefspec'
-
Add a single template approval like this:
describe 'my-cookbook::my-recipe' do include ChefVault::TestFixtures.rspec_shared_context context 'When all attributes are default, on CentOS 7.4.1708' do let(:chef_run) do # for a complete list of available platforms and versions see: # https://github.com/customink/fauxhai/blob/master/PLATFORMS.md runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '7.4.1708') do |node, server| node.override['my-cookbook']['attribute1'] = true end runner.converge(described_recipe) end it 'converges successfully' do expect { chef_run }.to_not raise_error end verify_chef_template( expected_path: '/path/to/rendered/template', approved_path: 'local/path/to/approved/template/output' # e.g. test/fixtures/approvals/logfile.xml ) end end
-
Add multiple template approvals like this:
describe 'my-cookbook::my-recipe' do include ChefVault::TestFixtures.rspec_shared_context context 'When all attributes are default, on CentOS 7.4.1708' do let(:chef_run) do # for a complete list of available platforms and versions see: # https://github.com/customink/fauxhai/blob/master/PLATFORMS.md runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '7.4.1708') do |node, server| node.override['my-cookbook']['attribute1'] = true end runner.converge(described_recipe) end it 'converges successfully' do expect { chef_run }.to_not raise_error end verify_chef_templates( { expected_path: '/path/to/rendered/template1', approved_path: 'local/path/to/approved/template/output1' # e.g. test/fixtures/approvals/logfile1.xml }, { expected_path: '/path/to/rendered/template2', approved_path: 'local/path/to/approved/template/output2' # e.g. test/fixtures/approvals/logfile2.xml } ) end end
Known Issues
- this library includes a transient dependency on the
json
gem; since version2.2.0
this gem requires build_essentials to build native extensions so make sure that is installed somewhere in your environment.
Development
- make changes
- bump
VERSION
gem build simple_approvals-chefspec.gemspec
gem push simple_approvals-chefspec-1.0.0.gem