Trying to write a ChefSpec unit test on windows. My cookbook depends on the ‘chocolatey’ and ‘windows’ cookbooks.
I’m attempting to test that a package is installed, yet I’m getting an error
STDERR: sh: powershell.exe: command not found
I’m trying to stub the return of powershell.exe, yet chefspec still fails. I’m running on a Mac, so there is no powershell.exe.
chocolatey '7zip' do action :install end
require 'spec_helper' RSpec.configure do |config| config.platform = 'windows' config.version = '2012R2' end describe 'my-cookbook::schedtasks' do context 'When all scheduled tasks are disabled' do let(:chef_run) do ChefSpec::SoloRunner.new(step_into: ['windows','chocolatey']) do |node| node.set['foo'] = 42 end.converge(described_recipe) end before do stub_command(/powershell.exe*/).and_return(true) end it 'installs 7zip' do stub_command(/powershell.exe*/).and_return(true) expect(chef_run).to_not install_chocolatey('7zip') end
How can I prevent chefspec from trying to actually run powershell on the chocolatey resource?