Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Mocha: is there an equivalent to rspec-mocks' #and_call_original?

Tags:

Rspec-mocks has expect(some_object).to receive(:some_method).and_call_original. Can I do this with Mocha, and if so, how? some_object.expects(:some_method).... ...what?

like image 745
L2G Avatar asked Feb 11 '14 23:02

L2G


People also ask

What is Rspec mock?

rspec-mocks helps to control the context in a code example by letting you set known return. values, fake implementations of methods, and even set expectations that specific messages. are received by an object.

What is a mock in Ruby?

Mocks are “smart” stubs, their purpose is to verify that some method was called. They are created with some expectations (expected method calls) and can then be verified to ensure those methods were called.


1 Answers

I'm fairly sure that there isn't a way to do this.

Looking through the source code, there's a comment that mentions that the original method is completely replaced.

# The original implementation of the method is replaced during the test and then restored at the end of the test. The temporary replacement method has the same visibility as the original method.
like image 129
Benny Hallett Avatar answered Oct 02 '22 22:10

Benny Hallett