Module: ChefSpec::API::ChocolateyPackageMatchers

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

Overview

Since:

  • 4.6.0

Instance Method Summary collapse

Instance Method Details

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

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

chocolatey_package '7zip' do
  action :install
end

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

)

Examples:

Assert that a chocolatey_package was installed

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

Assert that a chocolatey_package was installed with attributes

expect(chef_run).to install_chocolatey_package('git').with(
  version: %w(2.7.1),
  options: '--params /GitAndUnixToolsOnPath'

Assert that a chocolatey_package was not installed

expect(chef_run).to_not install_chocolatey_package('flashplayeractivex')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 4.6.0



34
35
36
# File 'lib/chefspec/api/chocolatey_package.rb', line 34

def install_chocolatey_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :install, resource_name)
end

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

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

chocolatey_package '7zip' do
  action :remove
end

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

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

Examples:

Assert that a chocolatey_package was removed

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

Assert that a specific chocolatey_package version was removed

expect(chef_run).to remove_chocolatey_package('7zip').with(
  version: %w(15.14)
)

Assert that a chocolatey_package was not removed

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

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 4.6.0



70
71
72
# File 'lib/chefspec/api/chocolatey_package.rb', line 70

def remove_chocolatey_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :remove, resource_name)
end

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

Assert that a chocolatey_package resource exists in the Chef run with the action :upgrade. Given a Chef Recipe that upgrades “7zip” as a chocolatey_package:

chocolatey_package '7zip' do
  action :upgrade
end

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

)

Examples:

Assert that a chocolatey_package was upgraded

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

Assert that a chocolatey_package was upgraded with attributes

expect(chef_run).to upgrade_chocolatey_package('git').with(
  version: %w(2.7.1),
  options: '-params "/GitAndUnixToolsOnPath"'

Assert that a chocolatey_package was not upgraded

expect(chef_run).to_not upgrade_chocolatey_package('flashplayeractivex')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 4.6.0



103
104
105
# File 'lib/chefspec/api/chocolatey_package.rb', line 103

def upgrade_chocolatey_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :upgrade, resource_name)
end