2014-11-25 257 views
0

我試着寫一個文件刪除測試:Chefspec刪除文件,windowslike路徑

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上運行,紅寶石2.1測試,chefspec 4.1

回答

1

看來你犯的錯誤,在你的食譜,你有C:/temp/1.txt並在測試你是否文件C:/test/1.txt被刪除。

+0

噢,我的天啊,謝謝,它那麼簡單的錯誤... – user3484021 2014-11-26 12:59:08