Low commit activity in last 3 years
A long-lived project that still receives updates
chefspec matchers for simple_approvals patterned after the ApprovalTests pattern
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

simple_approvals/chefspec

a simple chefspec-based implementation of the ApprovalTests pattern

Usage

  1. Update your Gemfile to include:

    gem 'simple_approvals-chefspec'
  2. Update spec_helper.rb to include:

    require 'simple_approvals/chefspec'
  3. 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
  4. 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

  1. this library includes a transient dependency on the json gem; since version 2.2.0 this gem requires build_essentials to build native extensions so make sure that is installed somewhere in your environment.

Development

  1. make changes
  2. bump VERSION
  3. gem build simple_approvals-chefspec.gemspec
  4. gem push simple_approvals-chefspec-1.0.0.gem