You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi - How do you write the ChefSpec test when you use the registry_data_exists method as a guard? I don't see any example on how to test or stub that method. When I run ChefSpec it always failing with the following error message:
Chef::Exceptions::Win32RegKeyMissing:
Registry key HKLM\SOFTWARE\Regkey does not exist
Here's how I use that method:
registry_key 'Set Data value to Auto' do
key 'HKLM\SOFTWARE\RegKey'
values [{ name: 'MaintenanceGroup', type: :string, data: 'Auto' }]
recursive true
action :create
only_if { registry_data_exists?('HKLM\SOFTWARE\RegKey', { name: 'MaintenanceGroup', type: :string, data: '' }, :machine) }
end
The text was updated successfully, but these errors were encountered:
I got passed the error message: Chef::Exceptions::Win32RegKeyMissing:
Registry key HKLM\SOFTWARE\Regkey does not exist
by adding the registry_key_exists? guard in the registry_key resource and mock it in the corresponding ChefSpec test:
in my recipe:
registry_key 'Set Data value to Auto' do
key 'HKLM\SOFTWARE\RegKey'
values [{ name: 'MaintenanceGroup', type: :string, data: 'Auto' }]
recursive true
action :create
only_if { registry_key_exists?('HKLM\SOFTWARE\RegKey', :machine) }
only_if { registry_data_exists?('HKLM\SOFTWARE\RegKey', { name: 'MaintenanceGroup', type: :string, data: '' }, :machine) }
end
in my spec file:
before(:all) do
RSpec::Mocks.with_temporary_scope do
allow_any_instance_of(Chef::Resource)
.to receive(:registry_key_exists?)
.with('HKLM\SOFTWARE\RegKey', :machine)
.and_return(true)
allow_any_instance_of(Chef::Provider)
.to receive(:registry_key_exists?)
.with('HKLM\SOFTWARE\RegKey', :machine)
.and_return(true)
end
end
But I am not sure if that's really how it should be done or if I still need to mock the registry_data_exists? guard. Still looking for some guidance.
Hi - How do you write the ChefSpec test when you use the registry_data_exists method as a guard? I don't see any example on how to test or stub that method. When I run ChefSpec it always failing with the following error message:
Chef::Exceptions::Win32RegKeyMissing:
Registry key HKLM\SOFTWARE\Regkey does not exist
Here's how I use that method:
registry_key 'Set Data value to Auto' do
key 'HKLM\SOFTWARE\RegKey'
values [{ name: 'MaintenanceGroup', type: :string, data: 'Auto' }]
recursive true
action :create
only_if { registry_data_exists?('HKLM\SOFTWARE\RegKey', { name: 'MaintenanceGroup', type: :string, data: '' }, :machine) }
end
The text was updated successfully, but these errors were encountered: