Module: ChefSpec::API::RouteMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a route resource exists in the Chef run with the action :add. Given a Chef Recipe that adds “10.0.0.10/32” as a route:

route '10.0.0.10/32' do
  action :add
end

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

Examples:

Assert that a route was added

expect(chef_run).to add_route('10.0.0.10/32')

Assert that a route was added with predicate matchers

expect(chef_run).to add_route('10.0.0.10/32').with_device('eth0')

Assert that a route was added with attributes

expect(chef_run).to add_route('10.0.0.10/32').with(device: 'eth0')

Assert that a route was added using a regex

expect(chef_run).to add_route('10.0.0.10/32').with(device: /eth(\d+)/)

Assert that a route was not added

expect(chef_run).to_not add_route('10.0.0.10/32')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def add_route(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:route, :add, resource_name)
end

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

Assert that a route resource exists in the Chef run with the action :delete. Given a Chef Recipe that deletes “10.0.0.10/32” as a route:

route '10.0.0.10/32' do
  action :delete
end

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

Examples:

Assert that a route was deleteed

expect(chef_run).to delete_route('10.0.0.10/32')

Assert that a route was deleteed with predicate matchers

expect(chef_run).to delete_route('10.0.0.10/32').with_device('eth0')

Assert that a route was deleteed with attributes

expect(chef_run).to delete_route('10.0.0.10/32').with(device: 'eth0')

Assert that a route was deleteed using a regex

expect(chef_run).to delete_route('10.0.0.10/32').with(device: /eth(\d+)/)

Assert that a route was not deleteed

expect(chef_run).to_not delete_route('10.0.0.10/32')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0


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

def delete_route(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:route, :delete, resource_name)
end