Module: ChefSpec::API::IfconfigMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that an ifconfig resource exists in the Chef run with the action :add. Given a Chef Recipe that adds “10.0.0.1” as an ifconfig:

ifconfig '10.0.0.1' do
  action :add
end

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

Examples:

Assert that an ifconfig was added

expect(chef_run).to add_ifconfig('10.0.0.1')

Assert that an ifconfig was added with predicate matchers

expect(chef_run).to add_ifconfig('10.0.0.1').with_device('eth0')

Assert that an ifconfig was added with attributes

expect(chef_run).to add_ifconfig('10.0.0.1').with(device: 'eth0')

Assert that an ifconfig was added using a regex

expect(chef_run).to add_ifconfig('10.0.0.1').with(device: /eth(\d+)/)

Assert that an ifconfig was not added

expect(chef_run).to_not add_ifconfig('10.0.0.1')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def add_ifconfig(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ifconfig, :add, resource_name)
end

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

Assert that an ifconfig resource exists in the Chef run with the action :delete. Given a Chef Recipe that deletes “10.0.0.1” as an ifconfig:

ifconfig '10.0.0.1' do
  action :delete
end

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

Examples:

Assert that an ifconfig was deleted

expect(chef_run).to delete_ifconfig('10.0.0.1')

Assert that an ifconfig was deleted with predicate matchers

expect(chef_run).to delete_ifconfig('10.0.0.1').with_device('eth0')

Assert that an ifconfig was deleted with attributes

expect(chef_run).to delete_ifconfig('10.0.0.1').with(device: 'eth0')

Assert that an ifconfig was deleted using a regex

expect(chef_run).to delete_ifconfig('10.0.0.1').with(device: /eth(\d+)/)

Assert that an ifconfig was not deleted

expect(chef_run).to_not delete_ifconfig('10.0.0.1')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def delete_ifconfig(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ifconfig, :delete, resource_name)
end

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

Assert that an ifconfig resource exists in the Chef run with the action :disable. Given a Chef Recipe that disables “10.0.0.1” as an ifconfig:

ifconfig '10.0.0.1' do
  action :disable
end

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

Examples:

Assert that an ifconfig was disabled

expect(chef_run).to disable_ifconfig('10.0.0.1')

Assert that an ifconfig was disabled with predicate matchers

expect(chef_run).to disable_ifconfig('10.0.0.1').with_device('eth0')

Assert that an ifconfig was disabled with attributes

expect(chef_run).to disable_ifconfig('10.0.0.1').with(device: 'eth0')

Assert that an ifconfig was disabled using a regex

expect(chef_run).to disable_ifconfig('10.0.0.1').with(device: /eth(\d+)/)

Assert that an ifconfig was not disabled

expect(chef_run).to_not disable_ifconfig('10.0.0.1')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def disable_ifconfig(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ifconfig, :disable, resource_name)
end

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

Assert that an ifconfig resource exists in the Chef run with the action :enable. Given a Chef Recipe that enables “10.0.0.1” as an ifconfig:

ifconfig '10.0.0.1' do
  action :enable
end

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

Examples:

Assert that an ifconfig was enabled

expect(chef_run).to enable_ifconfig('10.0.0.1')

Assert that an ifconfig was enabled with predicate matchers

expect(chef_run).to enable_ifconfig('10.0.0.1').with_device('eth0')

Assert that an ifconfig was enabled with attributes

expect(chef_run).to enable_ifconfig('10.0.0.1').with(device: 'eth0')

Assert that an ifconfig was enabled using a regex

expect(chef_run).to enable_ifconfig('10.0.0.1').with(device: /eth(\d+)/)

Assert that an ifconfig was not enabled

expect(chef_run).to_not enable_ifconfig('10.0.0.1')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def enable_ifconfig(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:ifconfig, :enable, resource_name)
end