4

My team uses Mocha for unit testing in Ruby. I'd like to use Mocha to add a "spy" on a method. That is, I'd like to write a unit test using Mocha that verifies that the code under test calls a particular method on another class, without overriding the implementation of that method.

Is that possible? If so, how can it be done?

I've tried using Mocha's expects, like:

MyModule::MyClass.expects(:my_method)

However, that overrides the implementation of my_method. In my particular situation, I need to both verify that my_method was called, and to have the actual implementation of the method execute during the test.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Jon Schneider
  • 25,758
  • 23
  • 142
  • 170

0 Answers0