Reputation: 1031
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
Upvotes: 1
Views: 424
Reputation: 1767
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
Upvotes: 0