我试图为文件删除编写测试:
test/recipes/default.rb
file 'C:/temp/1.txt' do
action :delete
endcat 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
发布于 2014-11-25 15:25:36
您似乎犯了错误,在您的菜谱中有C:/temp/1.txt,在测试中您检查文件C:/test/1.txt是否被删除。
https://stackoverflow.com/questions/27125058
复制相似问题