Is there a way to undo Mocha stubbing of any_instance in Test::Unit?

Mocha does not provide such a functionality. However you can implement it yourself The first thing we should know about mocha is that mocha actually replaces the original methods when you stub them. So in order to be able to restore these methods later, you must keep a reference to the former ones.It can be easily achieved by: alias new_method old_method It must be done before mocking the old_method Now, to unmock a method, you only need to alias old_method new_method Consider the following code: class A def a true end end class TestA Any_instance.

Stubs(:a). Returns("b") assert a. A, "b" A.

Class_eval {alias a unmocked_a} assert a. A, "a" end end.

Mocha does not provide such a functionality. However you can implement it yourself. The first thing we should know about mocha is that mocha actually replaces the original methods when you stub them.So in order to be able to restore these methods later, you must keep a reference to the former ones.

It can be easily achieved by: alias new_method old_method. It must be done before mocking the old_method. Now, to unmock a method, you only need to alias old_method new_method.

Consider the following code: class A def a true end end class TestA Class_eval {alias unmocked_a a} A. Any_instance. Stubs(:a).

Returns("b") assert a. A, "b" A. Class_eval {alias a unmocked_a} assert a.

A, "a" end end.

Excellent. This looks like something that could be added/monkeypatched into Mocha too. – Craig Walker May 24 '10 at 16:05 I've never felt the need for this functionality, but there is a ticket - floehopper.lighthouseapp.Com/projects/22289-mocha/tickets/… if you want to lobby for the change.

It would be great if you have some examples of why you'd want to use it. – floehopper Sep 26 '10 at 16:51 I have added unstubbing functionality - Mocha::ObjectMethods#unstub - see mocha.rubyforge.Org/classes/Mocha/ObjectMethods. Html#M000009 – floehopper Dec 2 '10 at 11:08.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions