Im trying to write test for file deletion:
test/recipes/default.rb
file 'C:/temp/1.txt' do
action :delete
end
cat spec/default_spec.rb
require_relative 'spec_helper'
describe 'test::default' do
#before do
# allow(File).to receive(:exist?).and_call_original
# allow(File).to receive(:exist?).with('C:/test/1.txt').and_return(true)
#end
let(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'windows', version: '2008R2') do |runner|
runner.automatic_attrs['hostname'] = 'somehost'
end.converge(described_recipe)
end
it 'delete scripts' do
expect(chef_run).to delete_file("C:/test/1.txt")
end
end
But after invoke rspec command I got:
F
Failures:
1) test::default delete scripts
Failure/Error: expect(chef_run).to delete_file("C\:/test/1.txt")
expected "file[C:/test/1.txt]" with action :delete to be in Chef run. Other file resources:
file[C:/temp/1.txt]
# ./spec/default_spec.rb:29:in `block (2 levels) in <top (required)>'
Finished in 0.64011 seconds (files took 1.27 seconds to load)
1 example, 1 failure
If I set linuxlike path - everything ok, also as you can see I tries to stub file. Any ideas what Im doing wrong?
P.S.: I'm running tests on linux, ruby 2.1, chefspec 4.1
It seems that you made mistake, in your recipe you have
C:/temp/1.txt
and in your test you check if fileC:/test/1.txt
is deleted.