My controller class inherits from ActionController::Base.
I am using rails 2 and ruby 1.9.3.
I am using Mocha to stub out calls to Perforce so my tests are not dependent on connections to perforce.
In my rails after_filter, I call one of my stubbed methods, hoping that it has not yet been unstubbed. In the normal application, it releases the Perforce connections.
I get this error message:
unexpected invocation: Api::BuildsController.perforce_service()
The method perforce_service is the method I stubbed out. I suspect that it is being called after it has already been unstubbed by Mocha, but I am not sure. When is the Mocha unstubbing done relative to the after_filter? How should I architect this?
When I try manually stubbing and unstubbing an object's method in pry, the method is still callable after I call unstub, which is not what I expect. I expect that unstub will restore the original method, or if it had no original method, to restore it to a state of being an undefined method. What does it really do?
NOTE:
Mocha documentation says to put this in test_helper.rb if you use rails:
require 'mocha/mini_test'
However, if I add this to my Gemfile and run bundle install:
gem 'mocha/mini_test'
then I get an error:
Could not find gem 'mocha/mini_test (>= 0) ruby' in the gems available on this machine
What am I doing wrong here?