Module: ChefSpec::API::RegistryKeyMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a registry_key resource exists in the Chef run with the action :create. Given a Chef Recipe that creates “HKEY_LOCAL_MACHINE\SOFTWARE” as a registry_key:

registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
  action :create
end

To test the content rendered by a registry_key, see ChefSpec::API::RenderFileMatchers.

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

Examples:

Assert that a registry_key was created

expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Assert that a registry_key was created with predicate matchers

expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)

Assert that a registry_key was created with attributes

expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)

Assert that a registry_key was created using a regex

expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)

Assert that a registry_key was not created

expect(chef_run).to_not create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def create_registry_key(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :create, resource_name)
end

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

Assert that a registry_key resource exists in the Chef run with the action :create_if_missing. Given a Chef Recipe that creates “HKEY_LOCAL_MACHINE\SOFTWARE” if missing as a registry_key:

registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
  action :create_if_missing
end

To test the content rendered by a registry_key, see ChefSpec::API::RenderFileMatchers.

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

Examples:

Assert that a registry_key was created if missing

expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE')

Assert that a registry_key was created if missing with predicate matchers

expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)

Assert that a registry_key was created if missing with attributes

expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)

Assert that a registry_key was created if missing using a regex

expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)

Assert that a registry_key was not created if missing

expect(chef_run).to_not create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def create_registry_key_if_missing(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :create_if_missing, resource_name)
end

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

Assert that a registry_key resource exists in the Chef run with the action :delete_key. Given a Chef Recipe that delete_keys “HKEY_LOCAL_MACHINE\SOFTWARE” as a registry_key:

registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
  action :delete_key
end

To test the content rendered by a registry_key, see ChefSpec::API::RenderFileMatchers.

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

Examples:

Assert that a registry_key was delete_keyd

expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Assert that a registry_key was delete_keyd with predicate matchers

expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)

Assert that a registry_key was delete_keyd with attributes

expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)

Assert that a registry_key was delete_keyd using a regex

expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)

Assert that a registry_key was not delete_keyd

expect(chef_run).to_not delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



162
163
164
# File 'lib/chefspec/api/registry_key.rb', line 162

def delete_key_registry_key(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :delete_key, resource_name)
end

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

Assert that a registry_key resource exists in the Chef run with the action :delete. Given a Chef Recipe that deletes “HKEY_LOCAL_MACHINE\SOFTWARE” as a registry_key:

registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
  action :delete
end

To test the content rendered by a registry_key, see ChefSpec::API::RenderFileMatchers.

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

Examples:

Assert that a registry_key was deleted

expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Assert that a registry_key was deleted with predicate matchers

expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)

Assert that a registry_key was deleted with attributes

expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)

Assert that a registry_key was deleted using a regex

expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)

Assert that a registry_key was not deleted

expect(chef_run).to_not delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



122
123
124
# File 'lib/chefspec/api/registry_key.rb', line 122

def delete_registry_key(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :delete, resource_name)
end