1

I'm trying to figure out how I can write my chefspec unit tests that will check every line on the below piece of code

Execute 'download gz' do

 cwd 'my/working/dir'

 environment ('environ' => node[:environ])

 command 'some commands here'

end

Thanks

Kgothatso Kurt
  • 951
  • 6
  • 5

1 Answers1

0

The environment map can be accessed in ChefSpec with the following example.

Given we have defined a resource such as

execute 'script.py' do
  environment(
    PATH: '/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin'
  )
  command '/path/to/script.py'
end

If we want to test for the environment in ChefSpec, we do the following

it 'Should execute script' do
  expect(chef_run).to run_execute('script.py').with(
    command: '/path/to/script.py',
    environment: { PATH: '/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin' }
  )
end
sutoL
  • 1,737
  • 10
  • 27
  • 48