13

It appears as though setting any method-call expectation with Mocha prevent the original implementation from being called.

This seems to cover calling the original method with rspec.

Is there a way to do this with Mocha? Or does anyone know why this wouldn't be supported?

Vega
  • 27,856
  • 27
  • 95
  • 103
aceofspades
  • 7,568
  • 1
  • 35
  • 48

1 Answers1

-8

This is not possible for a couple reasons. One reason is that testing the side effect of a method and testing the invocation of a method can be done more clearly in two separate tests. Another reason I've read is that in purist unit testing, you wouldn't make an assertion about another method's side effect. You would test the invocation and then test the called methods side effects in unit tests for that specific method.

joshs
  • 1,890
  • 1
  • 17
  • 20
  • Downvoting: I think you're confusing return values and side effects. – Marnen Laibow-Koser Jan 24 '14 at 21:51
  • @MarnenLaibow-Koser Could you be more specific? I can make a correction if there is a mistake but please remove the downvote. – joshs Feb 12 '14 at 13:38
  • You're talking about making "an assertion about another method's side effect", but what the OP *appears* to be doing (though I admit it's vague) is trying to rely on the *return value* of another method. That's quite different from the side effect. As for the downvote, I downvoted because I think your answer was incorrect and misleading (for the reasons already given). I won't remove the downvote unless I no longer believe that to be the case. – Marnen Laibow-Koser Feb 13 '14 at 20:02
  • I agree that the return value and the side effects are two different things. I am in a situation where I need to assert that a given method is called during a test, but I also need it to return the value resulting from the original invocation. Rspec mocks handles this, so I can't see why mocha can't. – Ernesto Mar 31 '14 at 13:45