Module: ChefSpec::API::MsuPackageMatchers

Defined in:
lib/chefspec/api/msu_package.rb

Overview

Since:

  • 6.0.0

Instance Method Summary collapse

Instance Method Details

#install_msu_package(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a msu_package resource exists in the Chef run with the action :install. Given a Chef Recipe that installs “KB2959977” as a msu_package:

msu_package 'KB2959977' do
  source 'C:\Windows8.1-KB2959977-x64.msu'
  action :install
end

The Examples section demonstrates the different ways to test a msu_package resource with ChefSpec.

Examples:

Assert that a msu_package was installed

expect(chef_run).to install_msu_package('KB2959977')

Assert that a msu_package was installed with predicate matchers

expect(chef_run).to install_msu_package('KB2959977').with_source('C:\Windows8.1-KB2959977-x64.msu')

Assert that a msu_package was installed with attributes

expect(chef_run).to install_msu_package('KB2959977').with(source: 'C:\Windows8.1-KB2959977-x64.msu')

Assert that a msu_package was installed using a regex

expect(chef_run).to install_msu_package('KB2959977').with(source: /.*KB2959977.*/)

Assert that a msu_package was not installed

expect(chef_run).to_not install_msu_package('KB2959977')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 6.0.0



40
41
42
# File 'lib/chefspec/api/msu_package.rb', line 40

def install_msu_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:msu_package, :install, resource_name)
end

#remove_msu_package(resource_name) ⇒ ChefSpec::Matchers::ResourceMatcher

Assert that a msu_package resource exists in the Chef run with the action :remove. Given a Chef Recipe that removes “KB2959977” as a msu_package:

msu_package 'KB2959977' do
  action :remove
end

The Examples section demonstrates the different ways to test a msu_package resource with ChefSpec.

Examples:

Assert that a msu_package was removed

expect(chef_run).to remove_msu_package('KB2959977')

Assert that a msu_package was removed with predicate matchers

expect(chef_run).to remove_msu_package('KB2959977').with_source('C:\Windows8.1-KB2959977-x64.msu')

Assert that a msu_package was removed with attributes

expect(chef_run).to remove_msu_package('KB2959977').with(source: 'C:\Windows8.1-KB2959977-x64.msu')

Assert that a msu_package was removed using a regex

expect(chef_run).to remove_msu_package('KB2959977').with(source: /.*KB2959977.*/)

Assert that a msu_package was not removed

expect(chef_run).to_not remove_msu_package('KB2959977')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 6.0.0



77
78
79
# File 'lib/chefspec/api/msu_package.rb', line 77

def remove_msu_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:msu_package, :remove, resource_name)
end