Module: ChefSpec::API::EnvMatchers

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

Overview

Since:

  • 0.9.0

Instance Method Summary collapse

Instance Method Details

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

Assert that an env resource exists in the Chef run with the action :create. Given a Chef Recipe that creates “HOME” as an env:

env 'HOME' do
  action :create
end

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

Examples:

Assert that an env was created

expect(chef_run).to create_env('HOME')

Assert that an env was created with predicate matchers

expect(chef_run).to create_env('HOME').with_value('/home')

Assert that an env was created with attributes

expect(chef_run).to create_env('HOME').with(value: 'home')

Assert that an env was created using a regex

expect(chef_run).to create_env('HOME').with(value: /\/ho(.+)/)

Assert that an env was not created

expect(chef_run).to_not create_env('HOME')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.9.0



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

def create_env(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:env, :create, resource_name)
end

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

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

env 'HOME' do
  action :delete
end

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

Examples:

Assert that an env was deleted

expect(chef_run).to delete_env('HOME')

Assert that an env was deleted with predicate matchers

expect(chef_run).to delete_env('HOME').with_value('/home')

Assert that an env was deleted with attributes

expect(chef_run).to delete_env('HOME').with(value: 'home')

Assert that an env was deleted using a regex

expect(chef_run).to delete_env('HOME').with(value: /\/ho(.+)/)

Assert that an env was not deleted

expect(chef_run).to_not delete_env('HOME')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.9.0



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

def delete_env(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:env, :delete, resource_name)
end

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

Assert that an env resource exists in the Chef run with the action :modify. Given a Chef Recipe that modifies “HOME” as an env:

env 'HOME' do
  action :modify
end

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

Examples:

Assert that an env was modified

expect(chef_run).to modify_env('HOME')

Assert that an env was modified with predicate matchers

expect(chef_run).to modify_env('HOME').with_value('/home')

Assert that an env was modified with attributes

expect(chef_run).to modify_env('HOME').with(value: 'home')

Assert that an env was modified using a regex

expect(chef_run).to modify_env('HOME').with(value: /\/ho(.+)/)

Assert that an env was not modified

expect(chef_run).to_not modify_env('HOME')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 0.9.0



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

def modify_env(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:env, :modify, resource_name)
end