本文介绍了使用rr屈服到一个块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用rr
测试以下代码:
I'm trying to test the following code using rr
:
response = RestClient.get(url, {:params => params}){|response, request, result| response }
在香草rspec
中,您将执行以下操作:
In vanilla rspec
, you would do something like this:
RestClient.should_receive(:get).with(url, {:params => params}).and_yield(response, request, result)
我如何对rr
做同样的事情?
How would I do the same with rr
?
设置:
let(:url) { "http://localhost/" }
let(:params) { {:item_id => 1234, :n => 5} }
let(:response) { Object.new }
let(:request) { Object.new }
let(:result) { Object.new }
我在以下方面尝试了多种变体:
I've tried a bunch of variations on:
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
但它们都不起作用.
推荐答案
最后得到了它.该请求请求帮助: https://github.com/btakita/rr/pull/82
Finally got it. This pull request helped: https://github.com/btakita/rr/pull/82
mock(RestClient).get(url, {:params => params}).yields(response, request, result) { response }
这篇关于使用rr屈服到一个块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!