chef-infrachefspec

How to check if windows_path was being assigned in chef recipe?


I have just started to use ChefSpec and am just investigating exactly what it allows

I have a chef recipe that installs Sublime and adds sublime to the path variable on windows:

chocolatey_package 'sublimetext3' do 
    action :upgrade 
end

windows_path node['sublime']['installation_path'] do 
    action :add 
    only_if { node['platform_family'] == 'windows' } 
end

Is it possible to test such a thing?

For example, something like:

it 'adds sublime to the machines path variable' do 
    expect(chef_run).to set_windows_path('pathtocheck')
end

I can't seem to find any documentation on this, or exactly what ChefSpec allows you to check for.

Thank you


Solution

  • So all resources follow the same pattern with matchers, $action_$resourcetype('$resourcename'). So in this case it would be:

    expect(chef_run).to add_windows_path('pathtocheck')
    

    Make sure that you set the platform and version options to ChefSpec so that you are using a Windows Fauxhai dump otherwise your only_if won't fire. (random protip you can use platform_family?('windows') in most contexts to save a bit of typing)