How to call original method in btakita/rr ?

476 views Asked by At

I need to check that particular method is called. Is it possible in btakita/rr?

rspec example from: https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/calling-the-original-method!

    Addition.should_receive(:two_plus_two).and_call_original
1

There are 1 answers

4
Peter Alfvin On BEST ANSWER

According to the original rr announcement, you'd need to use the following approach:

original_two_plus_two = Addition.method(:two_plus_two)
mock(Addition).two_plus_two {original_two_plus_two.call}

However, if you'd be ok with the double being called after the original, then you can use rr's proxy feature, described at https://github.com/rr/rr#proxies, as follows:

mock.proxy(Addition).two_plus_two

(Nod to @ElliotWinkler for clarifying that no block is required in this case.)