title: Rails webmock stubbing out localhost api call
body: <p>I have a controller, which has a <code>post_review</code> action which calls a Rest Client API call. </p>
  
  <pre><code>def post_review
    ...
    headers = { "CONTENT_TYPE" =&gt; "application/json",
                "X_AUTH_SIG" =&gt; Rails.application.secrets[:platform_receiver_url][:token] }
    rest_client.execute(:method =&gt; :put,
                        :url =&gt; Rails.application.secrets[:platform_receiver_url][:base_url] + response_body["application_id"].to_s,
                        :content_type =&gt; :json,
                        :payload =&gt; response_body.to_json,
                        :headers =&gt; headers)
    document_manual_result(response_body)
    delete_relavent_review_queue(params[:review_queue_id])
    ...
  end
  </code></pre>
  
  <p>The <code>document_manual_result</code> is a logging method and the <code>delete_relavent_review_queue</code> is a callback type method which will delete the item.</p>
  
  <p>I have written several tests that are testing the side effects of the post_review action, namely that it documents that I have sent off the result(aka:<code>response_body</code>) and that I delete another object. </p>
  
  <pre><code>  describe "Approved#When manual decision is made" do
      it "should delete the review queue object" do
        e = Event.create!(application_id: @review_queue_application.id)
        login_user @account
        post :post_review, @params
        expect{ReviewQueueApplication.find(@review_queue_application.id)}.to raise_exception(ActiveRecord::RecordNotFound)
      end
  
      it "should update the event created for the application" do
        e = Event.create!(application_id: @review_queue_application.id)
        login_user @account
        post :post_review, @params
        expect(Event.find(e.id).manual_result).to eq(@manual_result)
      end
    end
  </code></pre>
  
  <p>Before I turned on <code>RestClient</code> the tests worked, but now that rest client is executing It is breaking the specs. <strong>I would like to stub just the <code>rest_client.execute</code> portion of the controller action, so I can test the other side effects of the method.</strong> The URL I have it pointing to is <code>localhost:3001</code> so I tried: </p>
  
  <pre><code> stub_request(:any, "localhost:3001") 
  </code></pre>
  
  <p>I used it within, my before block which didn't do anything and I tried it inside the actual test <strong><em>it</em></strong> block just before I <code>post :post_review, @params</code> and Webmock seems to be doing nothing. What I thought webmock does, is that it is listening to any requests being made to a specific URL and it returns a success by default or a block of options that you specify. I am not sure I am using this correctly. </p>