Module: ChefSpec::API::WindowsPackageMatchers

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

Overview

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

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

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

windows_package '7zip' do
  action :install
end

To test the content rendered by a windows_package, see RenderFileMatchers.

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

Examples:

Assert that a windows_package was installed

expect(chef_run).to install_windows_package('7zip')

Assert that a windows_package was installed with predicate matchers

expect(chef_run).to install_windows_package('7zip').with_pattern('BI*')

Assert that a windows_package was installed with attributes

expect(chef_run).to install_windows_package('7zip').with(pattern: 'BI*')

Assert that a windows_package was installed using a regex

expect(chef_run).to install_windows_package('7zip').with(pattern: /(.+)/)

Assert that a windows_package was not installed

expect(chef_run).to_not install_windows_package('7zip')

Parameters:

  • the name of the resource to match

Returns:

Since:

  • 0.5.0



42
43
44
# File 'lib/chefspec/api/windows_package.rb', line 42

def install_windows_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:windows_package, :install, resource_name)
end

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

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

windows_package '7zip' do
  action :remove
end

To test the content rendered by a windows_package, see RenderFileMatchers.

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

Examples:

Assert that a windows_package was removeped

expect(chef_run).to remove_windows_package('7zip')

Assert that a windows_package was removeped with predicate matchers

expect(chef_run).to remove_windows_package('7zip').with_pattern('BI*')

Assert that a windows_package was removeped with attributes

expect(chef_run).to remove_windows_package('7zip').with(pattern: 'BI*')

Assert that a windows_package was removeped using a regex

expect(chef_run).to remove_windows_package('7zip').with(pattern: /(.+)/)

Assert that a windows_package was not removeped

expect(chef_run).to_not remove_windows_package('7zip')

Parameters:

  • the name of the resource to match

Returns:

Since:

  • 0.5.0



82
83
84
# File 'lib/chefspec/api/windows_package.rb', line 82

def remove_windows_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:windows_package, :remove, resource_name)
end