我正在尝试使用以下代码测试rr
:
response = RestClient.get(url, {:params => params}){|response, request, result| response }
在 vanillarspec
中,你会做这样的事情:
RestClient.should_receive(:get).with(url, {:params => params}).and_yield(response, request, result)
我将如何做同样的事情rr
?
设置:
let(:url) { "http://localhost/" }
let(:params) { {:item_id => 1234, :n => 5} }
let(:response) { Object.new }
let(:request) { Object.new }
let(:result) { Object.new }
我尝试了很多变化:
mock(RestClient).get(url, {:params => params}) { response, request, result }
和
mock(RestClient).get(url, {:params => params}, &proc/lambda{}).return(result)
和
mock(RestClient).get(url, {:params => params}).yields(response, request, result)
和
mock(RestClient).get(url, {:params => params}).returns do |proc_as_block|
response
end
但它们都不起作用。