我正在尝试为文件删除编写测试:
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
但是在调用 rspec 命令后,我得到了:
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
如果我设置 linuxlike 路径 - 一切正常,正如你所看到的,我尝试存根文件。任何想法我做错了什么?
PS:我在 linux、ruby 2.1、chefspec 4.1 上运行测试