Module: ChefSpec::API::LinkMatchers

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

Overview

Since:

  • 1.1.0

Instance Method Summary collapse

Instance Method Details

Assert that a link resource exists in the Chef run with the action :create. Given a Chef Recipe that creates “/tmp” as a link:

link '/tmp' do
  action :create
end

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

Examples:

Assert that a link was createed

expect(chef_run).to create_link('/tmp')

Assert that a link was createed with predicate matchers

expect(chef_run).to create_link('/tmp').with_link_type(:hard)

Assert that a link was createed with attributes

expect(chef_run).to create_link('/tmp').with(link_type: :hard)

Assert that a link was createed using a regex

expect(chef_run).to create_link('/tmp').with(link_type: Symbol)

Assert that a link was not createed

expect(chef_run).to_not create_link('/tmp')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.1.0


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

def create_link(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:link, :create, resource_name)
end

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

link '/tmp' do
  action :delete
end

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

Examples:

Assert that a link was deleteed

expect(chef_run).to delete_link('/tmp')

Assert that a link was deleteed with predicate matchers

expect(chef_run).to delete_link('/tmp').with_link_type(:hard)

Assert that a link was deleteed with attributes

expect(chef_run).to delete_link('/tmp').with(link_type: :hard)

Assert that a link was deleteed using a regex

expect(chef_run).to delete_link('/tmp').with(link_type: Symbol)

Assert that a link was not deleteed

expect(chef_run).to_not delete_link('/tmp')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.1.0


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

def delete_link(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:link, :delete, resource_name)
end

Assert that a symlink links to a specific path. This is really syntactic sugar for the following:

expect(chef_run).to create_link('/tmp/thing').with(to: '/tmp/other_thing')

Examples:

Using link_to with a String path

link = chef_run.link('/tmp/thing')
expect(link).to link_to('/tmp/other_thing')

Using link_to with a regular expression

expect(link).to link_to(/\/tmp/(.+)/)

Parameters:

  • path (String, Regex)

    the path to link to

Returns:

Since:

  • 1.1.0


98
99
100
# File 'lib/chefspec/api/link.rb', line 98

def link_to(path)
  ChefSpec::Matchers::LinkToMatcher.new(path)
end