Module: ChefSpec::API::GroupMatchers

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

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

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

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

group 'apache2' do
  action :create
end

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

Examples:

Assert that a group was createed

expect(chef_run).to create_group('apache2')

Assert that a group was createed with predicate matchers

expect(chef_run).to create_group('apache2').with_gid(1234)

Assert that a group was createed with attributes

expect(chef_run).to create_group('apache2').with(gid: 1234)

Assert that a group was createed using a regex

expect(chef_run).to create_group('apache2').with(gid: /\d+/)

Assert that a group was not createed

expect(chef_run).to_not create_group('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


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

def create_group(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:group, :create, resource_name)
end

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

Assert that a group resource exists in the Chef run with the action :manage. Given a Chef Recipe that manages “apache2” as a group:

group 'apache2' do
  action :manage
end

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

Examples:

Assert that a group was managed

expect(chef_run).to manage_group('apache2')

Assert that a group was managed with predicate matchers

expect(chef_run).to manage_group('apache2').with_gid(1234)

Assert that a group was managed with attributes

expect(chef_run).to manage_group('apache2').with(gid: 1234)

Assert that a group was managed using a regex

expect(chef_run).to manage_group('apache2').with(gid: /\d+/)

Assert that a group was not managed

expect(chef_run).to_not manage_group('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


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

def manage_group(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:group, :manage, resource_name)
end

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

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

group 'apache2' do
  action :modify
end

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

Examples:

Assert that a group was modified

expect(chef_run).to modify_group('apache2')

Assert that a group was modified with predicate matchers

expect(chef_run).to modify_group('apache2').with_gid(1234)

Assert that a group was modified with attributes

expect(chef_run).to modify_group('apache2').with(gid: 1234)

Assert that a group was modified using a regex

expect(chef_run).to modify_group('apache2').with(gid: /\d+/)

Assert that a group was not modified

expect(chef_run).to_not modify_group('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


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

def modify_group(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:group, :modify, resource_name)
end

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

Assert that a group resource exists in the Chef run with the action :remove. Given a Chef Recipe that removes “apache2” as a group:

group 'apache2' do
  action :remove
end

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

Examples:

Assert that a group was removed

expect(chef_run).to remove_group('apache2')

Assert that a group was removed with predicate matchers

expect(chef_run).to remove_group('apache2').with_gid(1234)

Assert that a group was removed with attributes

expect(chef_run).to remove_group('apache2').with(gid: 1234)

Assert that a group was removed using a regex

expect(chef_run).to remove_group('apache2').with(gid: /\d+/)

Assert that a group was not removed

expect(chef_run).to_not remove_group('apache2')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 1.0.0


150
151
152
# File 'lib/chefspec/api/group.rb', line 150

def remove_group(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:group, :remove, resource_name)
end