Module: ChefSpec::API::MdadmMatchers

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

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

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

Assert that a mdadm resource exists in the Chef run with the action :assemble. Given a Chef Recipe that assembles “/dev/md0” as a mdadm:

mdadm '/dev/md0' do
  action :assemble
end

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

Examples:

Assert that a mdadm was assembled

expect(chef_run).to assemble_mdadm('/dev/md0')

Assert that a mdadm was assembled with predicate matchers

expect(chef_run).to assemble_mdadm('/dev/md0').with_devices(['/dev/sda'])

Assert that a mdadm was assembled with attributes

expect(chef_run).to assemble_mdadm('/dev/md0').with(devices: ['/dev/sda'])

Assert that a mdadm was assembled using a regex

expect(chef_run).to assemble_mdadm('/dev/md0').with(devices: '/dev/sda')

Assert that a mdadm was not assembled

expect(chef_run).to_not assemble_mdadm('/dev/md0')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def assemble_mdadm(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :assemble, resource_name)
end

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

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

mdadm '/dev/md0' do
  action :create
end

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

Examples:

Assert that a mdadm was createed

expect(chef_run).to create_mdadm('/dev/md0')

Assert that a mdadm was createed with predicate matchers

expect(chef_run).to create_mdadm('/dev/md0').with_devices(['/dev/sda'])

Assert that a mdadm was createed with attributes

expect(chef_run).to create_mdadm('/dev/md0').with(devices: ['/dev/sda'])

Assert that a mdadm was createed using a regex

expect(chef_run).to create_mdadm('/dev/md0').with(devices: '/dev/sda')

Assert that a mdadm was not createed

expect(chef_run).to_not create_mdadm('/dev/md0')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def create_mdadm(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :create, resource_name)
end

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

Assert that a mdadm resource exists in the Chef run with the action :stop. Given a Chef Recipe that stops “/dev/md0” as a mdadm:

mdadm '/dev/md0' do
  action :stop
end

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

Examples:

Assert that a mdadm was stopped

expect(chef_run).to stop_mdadm('/dev/md0')

Assert that a mdadm was stopped with predicate matchers

expect(chef_run).to stop_mdadm('/dev/md0').with_devices(['/dev/sda'])

Assert that a mdadm was stopped with attributes

expect(chef_run).to stop_mdadm('/dev/md0').with(devices: ['/dev/sda'])

Assert that a mdadm was stopped using a regex

expect(chef_run).to stop_mdadm('/dev/md0').with(devices: '/dev/sda')

Assert that a mdadm was not stopped

expect(chef_run).to_not stop_mdadm('/dev/md0')

Parameters:

  • resource_name (String, Regex)

    the name of the resource to match

Returns:

Since:

  • 3.0.0



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

def stop_mdadm(resource_name)
  ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :stop, resource_name)
end