Module: ChefSpec::API::ChefGemMatchers

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

Overview

Since:

  • 0.8.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a chef_gem resource exists in the Chef run with the action :install. Given a Chef Recipe that installs “community-zero” as a chef_gem:

chef_gem 'community-zero' do
  action :install
end

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

Examples:

Assert that a chef_gem was installed

expect(chef_run).to install_chef_gem('community-zero')

Assert that a chef_gem was installed with predicate matchers

expect(chef_run).to install_chef_gem('community-zero').with_version('1.2.3')

Assert that a chef_gem was installed with attributes

expect(chef_run).to install_chef_gem('community-zero').with(version: '1.2.3')

Assert that a chef_gem was installed using a regex

expect(chef_run).to install_chef_gem('community-zero').with(version: /(\d+\.){2}\.\d+/)

Assert that a chef_gem was not installed

expect(chef_run).to_not install_chef_gem('community-zero')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.8.0


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

def install_chef_gem(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chef_gem, :install, resource_name)
end

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

Assert that a chef_gem resource exists in the Chef run with the action :purge. Given a Chef Recipe that purges “community-zero” as a chef_gem:

chef_gem 'community-zero' do
  action :purge
end

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

Examples:

Assert that a chef_gem was purgeed

expect(chef_run).to purge_chef_gem('community-zero')

Assert that a chef_gem was purgeed with predicate matchers

expect(chef_run).to purge_chef_gem('community-zero').with_version('1.2.3')

Assert that a chef_gem was purgeed with attributes

expect(chef_run).to purge_chef_gem('community-zero').with(version: '1.2.3')

Assert that a chef_gem was purgeed using a regex

expect(chef_run).to purge_chef_gem('community-zero').with(version: /(\d+\.){2}\.\d+/)

Assert that a chef_gem was not purgeed

expect(chef_run).to_not purge_chef_gem('community-zero')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.8.0


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

def purge_chef_gem(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chef_gem, :purge, resource_name)
end

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

Assert that a chef_gem resource exists in the Chef run with the action :reconfig. Given a Chef Recipe that reconfigures “community-zero” as a chef_gem:

chef_gem 'community-zero' do
  action :reconfig
end

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

Examples:

Assert that a chef_gem was reconfigured

expect(chef_run).to reconfig_chef_gem('community-zero')

Assert that a chef_gem was reconfigured with predicate matchers

expect(chef_run).to reconfig_chef_gem('community-zero').with_version('1.2.3')

Assert that a chef_gem was reconfigured with attributes

expect(chef_run).to reconfig_chef_gem('community-zero').with(version: '1.2.3')

Assert that a chef_gem was reconfigured using a regex

expect(chef_run).to reconfig_chef_gem('community-zero').with(version: /(\d+\.){2}\.\d+/)

Assert that a chef_gem was not reconfigured

expect(chef_run).to_not reconfig_chef_gem('community-zero')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.8.0


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

def reconfig_chef_gem(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chef_gem, :reconfig, resource_name)
end

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

Assert that a chef_gem resource exists in the Chef run with the action :remove. Given a Chef Recipe that removes “community-zero” as a chef_gem:

chef_gem 'community-zero' do
  action :remove
end

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

Examples:

Assert that a chef_gem was removeed

expect(chef_run).to remove_chef_gem('community-zero')

Assert that a chef_gem was removeed with predicate matchers

expect(chef_run).to remove_chef_gem('community-zero').with_version('1.2.3')

Assert that a chef_gem was removeed with attributes

expect(chef_run).to remove_chef_gem('community-zero').with(version: '1.2.3')

Assert that a chef_gem was removeed using a regex

expect(chef_run).to remove_chef_gem('community-zero').with(version: /(\d+\.){2}\.\d+/)

Assert that a chef_gem was not removeed

expect(chef_run).to_not remove_chef_gem('community-zero')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.8.0


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

def remove_chef_gem(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chef_gem, :remove, resource_name)
end

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

Assert that a chef_gem resource exists in the Chef run with the action :upgrade. Given a Chef Recipe that upgrades “community-zero” as a chef_gem:

chef_gem 'community-zero' do
  action :upgrade
end

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

Examples:

Assert that a chef_gem was upgradeed

expect(chef_run).to upgrade_chef_gem('community-zero')

Assert that a chef_gem was upgradeed with predicate matchers

expect(chef_run).to upgrade_chef_gem('community-zero').with_version('1.2.3')

Assert that a chef_gem was upgradeed with attributes

expect(chef_run).to upgrade_chef_gem('community-zero').with(version: '1.2.3')

Assert that a chef_gem was upgradeed using a regex

expect(chef_run).to upgrade_chef_gem('community-zero').with(version: /(\d+\.){2}\.\d+/)

Assert that a chef_gem was not upgradeed

expect(chef_run).to_not upgrade_chef_gem('community-zero')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.8.0


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

def upgrade_chef_gem(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:chef_gem, :upgrade, resource_name)
end