0

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
gayavat
  • 18,910
  • 11
  • 45
  • 55

1 Answers1

0

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.)

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • Thanks for accepting my answer. :-) As an experiment, I'm making this comment on my ten most recent accepted-without-an-upvote answers and providing the link to http://meta.stackexchange.com/questions/686/accepting-answer-without-upvoting to see what the response is. Note that I fully respect everyone's right to upvote, downvote or do neither as they see fit. :-) – Peter Alfvin Dec 03 '13 at 19:17
  • You don't need the block. Just use `mock.proxy(Addition).two_plus_two`. – Elliot Winkler Dec 04 '13 at 19:24
  • @ElliotWinkler Thanks. I believe you and I'll update my answer, but if you happen to know if this is documented anywhere else but the code, I'd appreciate a reference. – Peter Alfvin Dec 04 '13 at 19:27
  • I moved the repo to http://github.com/rr/rr. There's a section on proxies [here](https://github.com/rr/rr#proxies) and also some more information about it [here](https://github.com/rr/rr/blob/master/doc/03_api_overview.md#mockproxy) (although it doesn't really explain proxies very well, I need to do an overhaul of this document). EDIT: Oh you were talking about that #proxy doesn't have to take a block. No unfortunately that is not documented, I just happen to know that. – Elliot Winkler Dec 05 '13 at 07:32