我的食谱里有这样的条件:
install_action = (::Win32::Service.exists?(windows_service['name']) ? :configure : :create)并在spec文件中为此提供了一个ChefSpec:
#1: not working
allow_any_instance_of(Win32::Service)
.to receive(:exists?)
.with(windows_service[:name])
.and_return(true)
#2: also not working
stub_command("::Win32::Service.exists?(#{windows_service[:name]})").and_return(true)请您帮忙找出我在ChefSpec测试中漏掉了哪些不起作用的内容,并模拟返回值。谢谢
发布于 2019-06-17 07:04:19
这应该是可行的:
allow(::Win32::Service).to receive(:exists?).with(windows_service[:name]).and_return(true)重点是您对类方法exists?进行存根,而不是实例方法。这就是为什么allow_any_instance_of不能工作的原因。stub_command实际上是用于shell命令,比如stub_command('cat file | grep "hello"')
https://stackoverflow.com/questions/56623285
复制相似问题