1

I'm trying to test the following code using rr:

response = RestClient.get(url, {:params => params}){|response, request, result| response }

In vanilla rspec, you would do something like this:

RestClient.should_receive(:get).with(url, {:params => params}).and_yield(response, request, result)

How would I do the same with rr?

Setup:

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 }

and

mock(RestClient).get(url, {:params => params}, &proc/lambda{}).return(result)

and

mock(RestClient).get(url, {:params => params}).yields(response, request, result)

and

mock(RestClient).get(url, {:params => params}).returns do |proc_as_block|
  response
end

but none of them work.

Raphael
  • 1,701
  • 15
  • 26

1 Answers1

3

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 }
Raphael
  • 1,701
  • 15
  • 26
  • Thx, you helped with this [answer](http://stackoverflow.com/a/19201353/449531), another example of using rr yields. – zhon Oct 05 '13 at 18:44