Module: ChefSpec::API::RemoteDirectoryMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

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

remote_directory '/tmp' do
  action :create
end

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

Examples:

Assert that a remote_directory was createed

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

Assert that a remote_directory was createed with predicate matchers

expect(chef_run).to create_remote_directory('/tmp').with_overwrite(true)

Assert that a remote_directory was createed with attributes

expect(chef_run).to create_remote_directory('/tmp').with(overwrite: true)

Assert that a remote_directory was createed using a regex

expect(chef_run).to create_remote_directory('/tmp').with(overwrite: /true/)

Assert that a remote_directory was not createed

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

Since:

  • 3.0.0


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

def create_remote_directory(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :create, resource_name)
end

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

Assert that a remote_directory resource exists in the Chef run with the action :create_if_missing. Given a Chef Recipe that creates “/tmp/config” if missing as a remote_directory:

remote_directory '/tmp/config' do
  action :create_if_missing
end

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

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

Examples:

Assert that a remote_directory was created if missing

expect(chef_run).to create_remote_directory_if_missing('/tmp/config')

Assert that a remote_directory was created if missing with predicate matchers

expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with_overwrite(true)

Assert that a remote_directory was created if missing with attributes

expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with(overwrite: true)

Assert that a remote_directory was created if missing using a regex

expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with(overwrite: /true/)

Assert that a remote_directory was not created if missing

expect(chef_run).to_not create_remote_directory('/tmp/config')

Since:

  • 3.0.0


79
80
81
# File 'lib/chefspec/api/remote_directory.rb', line 79

def create_remote_directory_if_missing(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :create_if_missing, resource_name)
end

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

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

remote_directory '/tmp' do
  action :delete
end

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

Examples:

Assert that a remote_directory was deleteed

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

Assert that a remote_directory was deleteed with predicate matchers

expect(chef_run).to delete_remote_directory('/tmp').with_overwrite(true)

Assert that a remote_directory was deleteed with attributes

expect(chef_run).to delete_remote_directory('/tmp').with(overwrite: true)

Assert that a remote_directory was deleteed using a regex

expect(chef_run).to delete_remote_directory('/tmp').with(overwrite: /true/)

Assert that a remote_directory was not deleteed

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

Since:

  • 3.0.0


116
117
118
# File 'lib/chefspec/api/remote_directory.rb', line 116

def delete_remote_directory(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :delete, resource_name)
end