title: Testing Net::HTTP.get_Response()
body: <p>I'm trying to test a method I have on one of my rails models. I am returning the HTTP status from a url and don't know how I can stub the return to test out different return codes to make sure my code works for different situations.</p>
  
  <p>Here's the line of code I want to mock:</p>
  
  <pre><code>response = Net::HTTP.get_response(URI.parse(self.url))
  </code></pre>
  
  <p>I want to have the <code>Net:HTTP.get_response</code> to return a specific HTTPResponse for each of the tests I have in my spec.  </p>
  
  <pre><code>describe Site do
    before :each do
      FactoryGirl.build :site
    end
    context "checking site status" do
      it "should be true when 200" do
        c = FactoryGirl.build :site, url:"http://www.example.com/value.html"
        #something to mock the Net::HTTP.get_response to return and instance of Net::HTTPOK
        c.ping.should == true
      end      
      it "should be false when 404" do
        c = FactoryGirl.build :site, url:"http://www.example.com/value.html"
        #something to mock the Net::HTTP.get_response to return and instance of Net::HTTPNotFound
        c.ping.should == false       
      end
    end
  end
  </code></pre>
  
  <p>How would I stub out the return values from get_response?</p>