gayavat
gayavat

Reputation: 19398

How to call original method in btakita/rr ?

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

Upvotes: 0

Views: 482

Answers (1)

Peter Alfvin
Peter Alfvin

Reputation: 29379

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

Upvotes: 0

Related Questions