Module: ChefSpec::API::PackageMatchers

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

Overview

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

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

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

package 'apache2' do
  action :install
end

The Examples section demonstrates the different ways to test an package resource with ChefSpec.

Examples:

Assert that an package was installed

expect(chef_run).to install_package('apache2')

Assert that an package was installed with predicate matchers

expect(chef_run).to install_package('apache2').with_version('1.2.3')

Assert that an package was installed with attributes

expect(chef_run).to install_package('apache2').with(version: '1.2.3')

Assert that an package was installed using a regex

expect(chef_run).to install_package('apache2').with(version: /(\d+\.){2}\.\d+/)

Assert that an package was not installed

expect(chef_run).to_not install_package('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



39
40
41
# File 'lib/chefspec/api/package.rb', line 39

def install_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:package, :install, resource_name)
end

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

Assert that an package resource exists in the Chef run with the action :purge. Given a Chef Recipe that purges “apache2” as an package:

package 'apache2' do
  action :purge
end

The Examples section demonstrates the different ways to test an package resource with ChefSpec.

Examples:

Assert that an package was purged

expect(chef_run).to purge_package('apache2')

Assert that an package was purged with predicate matchers

expect(chef_run).to purge_package('apache2').with_version('1.2.3')

Assert that an package was purged with attributes

expect(chef_run).to purge_package('apache2').with(version: '1.2.3')

Assert that an package was purged using a regex

expect(chef_run).to purge_package('apache2').with(version: /(\d+\.){2}\.\d+/)

Assert that an package was not purged

expect(chef_run).to_not purge_package('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



76
77
78
# File 'lib/chefspec/api/package.rb', line 76

def purge_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:package, :purge, resource_name)
end

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

Assert that an package resource exists in the Chef run with the action :reconfig. Given a Chef Recipe that reconfigures “apache2” as an package:

package 'apache2' do
  action :reconfig
end

The Examples section demonstrates the different ways to test an package resource with ChefSpec.

Examples:

Assert that an package was reconfigured

expect(chef_run).to reconfig_package('apache2')

Assert that an package was reconfigured with predicate matchers

expect(chef_run).to reconfig_package('apache2').with_version('1.2.3')

Assert that an package was reconfigured with attributes

expect(chef_run).to reconfig_package('apache2').with(version: '1.2.3')

Assert that an package was reconfigured using a regex

expect(chef_run).to reconfig_package('apache2').with(version: /(\d+\.){2}\.\d+/)

Assert that an package was not reconfigured

expect(chef_run).to_not reconfig_package('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



113
114
115
# File 'lib/chefspec/api/package.rb', line 113

def reconfig_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:package, :reconfig, resource_name)
end

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

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

package 'apache2' do
  action :remove
end

The Examples section demonstrates the different ways to test an package resource with ChefSpec.

Examples:

Assert that an package was removed

expect(chef_run).to remove_package('apache2')

Assert that an package was removed with predicate matchers

expect(chef_run).to remove_package('apache2').with_version('1.2.3')

Assert that an package was removed with attributes

expect(chef_run).to remove_package('apache2').with(version: '1.2.3')

Assert that an package was removed using a regex

expect(chef_run).to remove_package('apache2').with(version: /(\d+\.){2}\.\d+/)

Assert that an package was not removed

expect(chef_run).to_not remove_package('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



150
151
152
# File 'lib/chefspec/api/package.rb', line 150

def remove_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:package, :remove, resource_name)
end

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

Assert that an package resource exists in the Chef run with the action :upgrade. Given a Chef Recipe that upgrades “apache2” as an package:

package 'apache2' do
  action :upgrade
end

The Examples section demonstrates the different ways to test an package resource with ChefSpec.

Examples:

Assert that an package was upgraded

expect(chef_run).to upgrade_package('apache2')

Assert that an package was upgraded with predicate matchers

expect(chef_run).to upgrade_package('apache2').with_version('1.2.3')

Assert that an package was upgraded with attributes

expect(chef_run).to upgrade_package('apache2').with(version: '1.2.3')

Assert that an package was upgraded using a regex

expect(chef_run).to upgrade_package('apache2').with(version: /(\d+\.){2}\.\d+/)

Assert that an package was not upgraded

expect(chef_run).to_not upgrade_package('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1



187
188
189
# File 'lib/chefspec/api/package.rb', line 187

def upgrade_package(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:package, :upgrade, resource_name)
end