title: How to mock classes in Rails controller with mocha
body: <p>I'm having a hard time understanding how to use mocha mocking library for certain type of unit tests in Rails.</p>
  
  <p>I have a controller, which initializes an object from a helper library, and then calls a function on it. My code looks similar to</p>
  
  <pre><code>class ObjectsController &lt; ApplicationController
    before_action :set_adapter
  
    def index
      response = @adapter.get_objects
  
      render json: response
    end
  
    private
      def set_adapter
        arg = request.headers["X-ARG"]
        @adapter = Adapter::Adapter.new(arg)
      end
  end
  </code></pre>
  
  <p>In my tests, I want mock the adapter to make sure that the get_objects() method is called. I'm trying to figure out what is the best way to implement this kind of tests, but I seem to be stuck on getting the idea on how to mock an existing object within a class.</p>
  
  <p>Can anyone help me out?</p>