0.01
The project is in a healthy, maintained state
A package that depends on all the gems Vox Pupuli modules need and methods to simplify spec helpers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.12

Runtime

 Project Readme

Voxpupuli Test Gem

License Test codecov Release RubyGem Version RubyGem Downloads

This is a helper Gem to test the various Vox Pupuli Puppet modules. This Gem provides common functionality for rspec-puppet based testing. The aim is to reduce the boiler plate and need for modulesync.

Usage

Add the voxpupuli-test Gem to your Gemfile:

gem 'voxpupuli-test'

Then, at the top of your Rakefile, add:

require 'voxpupuli/test/rake'

In your spec/spec_helper.rb

require 'voxpupuli/test/spec_helper'

In your .rubocop.yml (see Rubocop's documentation).

inherit_gem:
  voxpupuli-test: rubocop.yml

Fact handling

The recommended method is using rspec-puppet-facts and is set up by default. This means the tests are writting as follows:

require 'spec_helper'

describe 'myclass' do
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile.with_all_deps }
    end
  end
end

Now a common case is to override facts in tests. Let's take the example of SELinux with legacy facts.

require 'spec_helper'

describe 'mytool' do
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile.with_all_deps }

      describe 'with SELinux enabled' do
        let(:facts) { super().merge(selinux: true) }

        it { is_expected.to contain_package('mytool-selinux') }
      end

      describe 'with SELinux disabled' do
        let(:facts) { super().merge(selinux: false) }

        it { is_expected.not_to contain_package('mytool-selinux') }
      end
    end
  end
end

This is all fairly straight forward, but it gets more complex when using modern facts. Modern facts are nested which means you need to do deep merging. There is deep_merge but its results are not at all useful for spec testing. That's why voxpupuli-test has an override_facts helper.

require 'spec_helper'

describe 'mytool' do
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile.with_all_deps }

      describe 'with SELinux enabled' do
        let(:facts) { override_facts(super(), os: {selinux: {enabled: true}}) }

        it { is_expected.to contain_package('mytool-selinux') }
      end

      describe 'with SELinux disabled' do
        let(:facts) { override_facts(super(), os: {selinux: {enabled: false}}) }

        it { is_expected.not_to contain_package('mytool-selinux') }
      end
    end
  end
end

Note that this helper deals with symbols/strings for you as well.