Chef如何处理open.file?



我有一个chef-cookbook-recipe使用ruby File.open:

File.open('/tmp/test.txt', 'r') do |file|

如果单元测试中没有任何内容,使用

就会失败
expected no Exception, got #<Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/test.txt> with backtrace:

我该如何处理?我试图找到任何与存根文件有关的东西。但一切都很开放,并不多,不适合我。也许你能帮我?提前感谢!

也许这样的东西能帮上忙=>

before do
allow(File).to receive(:open).and_return('the contents of the file')
end

最新更新