我有两个没有类的方法,它们都有相同的代码,但返回对象不同。
def get_load_balancer(network_client, resource_group_name, load_balancer_name)
promise = network_client.load_balancers.get(resource_group_name, load_balancer_name)
load_balancer = promise.value!
return load_balancer.body
end
def get_public_ip(network_client, resource_group_name, public_ip_name)
promise = network_client.public_ip_addresses.get(resource_group_name, public_ip_name)
public_ip = promise.value!
return public_ip.body
end
我试图嘲笑它
@network_client = NetworkResourceProviderClient.new(token)
@promise_lb = Concurrent::Promise.new
allow(@network_client).to receive_message_chain(:load_balancers, :get).and_return(@promise_lb)
allow(@promise_lb).to receive(:value!).and_return(response_lb)
@promise_pip = Concurrent::Promise.new
allow(@network_client).to receive_message_chain(:public_ip_addresses, :get).and_return(@promise_pip)
allow(@promise_pip).to receive(:value!).and_return(response_pip)
问题是,在模拟中传递对象不起作用。请帮我解决这个问题。