有没有一种方法可以用测试值来存根方法调用?例如,我希望get_folder_name在我的ChefSpec测试期间返回‘test
directory 'Log_Folder' do
def get_folder_name
'c:\temp\folder'
end
action :create
path get_folder_name
end我试过了,但它不会替换这个值。
before do
allow_any_instance_of(Chef::Resource).to receive(:get_folder_name).and_return('test')
end发布于 2017-04-04 10:11:30
因此,问题可能是因为该方法是以内联方式声明的,所以它会一直覆盖存根。您可以尝试使用allow_any_instance_of(Chef::Resource::Directory)或类似的方法,但我可能会将此逻辑转移到自定义资源,以便更自然地将其存根。
https://stackoverflow.com/questions/43196694
复制相似问题