Module: ChefSpec::API::DirectoryMatchers

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

Overview

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

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

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

directory '/tmp' do
  action :create
end

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

Examples:

Assert that a directory was createed

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

Assert that a directory was createed with predicate matchers

expect(chef_run).to create_directory('/tmp').with_user('svargo')

Assert that a directory was createed with attributes

expect(chef_run).to create_directory('/tmp').with(user: 'svargo')

Assert that a directory was createed using a regex

expect(chef_run).to create_directory('/tmp').with(user: /sva(.+)/)

Assert that a directory was not createed

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

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


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

def create_directory(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:directory, :create, resource_name)
end

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

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

directory '/tmp' do
  action :delete
end

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

Examples:

Assert that a directory was deleteed

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

Assert that a directory was deleteed with predicate matchers

expect(chef_run).to delete_directory('/tmp').with_user('svargo')

Assert that a directory was deleteed with attributes

expect(chef_run).to delete_directory('/tmp').with(user: 'svargo')

Assert that a directory was deleteed using a regex

expect(chef_run).to delete_directory('/tmp').with(user: /sva(.+)/)

Assert that a directory was not deleteed

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

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.0.1


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

def delete_directory(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:directory, :delete, resource_name)
end