title: rspec test a private method within a private method that needs to be stubbed
body: <p>Simplecov detected that I was missing some tests on my <code>lib/api_verson.rb</code> class:</p>
  
  <pre><code>class ApiVersion
  
    def initialize(version)
      @version = version
    end
  
    def matches?(request)
      versioned_accept_header?(request) || version_one?(request)
    end
  
    private
  
    def versioned_accept_header?(request)
      accept = request.headers['Accept']
      accept &amp;&amp; accept[/application\/vnd\.#{Rails.application.secrets.my_app_accept_header}-v#{@version}\+json/]
    end
  
    def unversioned_accept_header?(request)
      accept = request.headers['Accept']
      accept.blank? || accept[/application\/vnd\.#{Rails.application.secrets.my_app_accept_header}/].nil?
    end
  
    def version_one?(request)
      @version == Rails.application.secrets.my_app_default_api_version &amp;&amp; unversioned_accept_header?(request)
    end
  
  end
  </code></pre>
  
  <p>This class is used by the routes file to help setup api versions:</p>
  
  <pre><code>namespace :api, path: "", defaults: {format: :json} do
  
  scope module: :v1, constraints: ApiVersion.new(1) do
    get '/alive', to: 'api#alive'
  end
  
  scope module: :v2, constraints: ApiVersion.new(2) do
    get '/alive', to: 'api#alive'
  end
  
  end
  </code></pre>
  
  <p>This setup was ported from <a href="http://freelancing-gods.com/posts/versioning_your_ap_is" rel="nofollow">versioning_your_ap_is</a>.</p>
  
  <p>I am trying to test the methods here that simplecov is reporting as failures, and right now I am stuck on the case where the private method contains a private method... </p>
  
  <pre><code>  def version_one?(request)
      @version == Rails.application.secrets.my_app_default_api_version &amp;&amp; unversioned_accept_header?(request)
    end
  </code></pre>
  
  <p>This is my current spec:</p>
  
  <pre><code>require 'spec_helper'
  
  describe ApiVersion do
  
    before(:each) do
      @apiversion = ApiVersion.new(1)
      @current_api_version = Rails.application.secrets.my_app_default_api_version
      @request = ActionController::TestRequest.new(host: 'localhost')
      @request.headers["Accept"] = "application/vnd.#{Rails.application.secrets.my_app_accept_header}-v#{@current_api_version}+json"
    end
  
    describe "Method #versioned_accept_header? =&gt;" do
      it "Should return false if the header accept variable contains application/vnd.#{Rails.application.secrets.my_app_accept_header}-v#{@current_api_version}+json" do
        expect(@apiversion.send(:unversioned_accept_header?, @request)).to eq(false)
      end
      it "Should return true if no version is included with the header" do
        request = @request
        request.headers["Accept"] = nil
        expect(@apiversion.send(:unversioned_accept_header?, request)).to eq(true)
      end
    end
  
    describe "Method #version_one? =&gt;" do
      it "test me" do
        # @apiversion.send(:unversioned_accept_header?, @request)
  
        binding.pry
  
        # expect(@apiversion.send(:version_one?, @request)).to eq(false)
      end
    end
  
  end
  </code></pre>
  
  <p>How do I stub the nested private method to test the version_one private method? </p>