title: Testing Network Timeouts and Errors with Ruby
body: <p>I'm writing a wrapper for a flakey 3rd party API and would like some way to test my code's error handling.  </p>
  
  <p>What do people do when they want to test things like: </p>
  
  <ul>
  <li>API responding with various http codes (400-599)</li>
  <li>Connection timeouts (host is down, dns issues, etc)</li>
  </ul>
  
  <p>Is there a correct way to do this?  Right now i'm simply using a test host, adding mod_rewrite rules such as: </p>
  
  <pre><code>RewriteRule ^500.html$ / [R=500,L,NE]
  RewriteRule ^501.html$ / [R=501,L,NE]
  RewriteRule ^404.html$ / [R=404,L,NE]
  </code></pre>
  
  <p>I then make sure my code handles those use cases appropriately but it feels wrong and provides no way to test a timeout error.</p>