如何正确地从存根返回hash对象,以便不总是为nil:nilclass获取错误消息“nomethoderror:undefined method'each”?
# ruby code to test
env_json = JSON.parse(Chef::ServerAPI.new.get("test").to_json)
env_json ['versions'].each do |name, version|
# things to do
end
在测试中,我想模拟serverapi调用。
before(:each) do
query = double
allow(query).to receive(:get) do |arg1|
case arg1.downcase
when %r{\test}
{"versions" => { "flag2" => false } } ## return hash value
else
{"versions2" => { "flag2" => true } } ## return hash value
end
end
allow(Chef::ServerAPI).to receive(:new).and_return(query)
end
有人知道如何在查询中传递哈希值吗?
暂无答案!
目前还没有任何答案,快来回答吧!