我正在尝试编写文件删除测试:
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路径 - 一切正常,也可以看到我尝试存根文件。 我做错了什么想法?
P.S。:我正在linux上运行测试,ruby 2.1,chefspec 4.1
答案 0 :(得分:1)
您似乎犯了错误,在您的食谱中C:/temp/1.txt
并且在测试中检查文件C:/test/1.txt
是否已删除。