title: Capybara - Identify ajax response code for timeout (rspec/capybara/webkit/puffing-billy)
body: <p>I have operationnal tests to check that the right message is displayed in a Rails UJS/ajax modal for error 404, 500... Here is an example below (the test below passes; I'm using <a href="https://github.com/oesmith/puffing-billy" rel="nofollow noreferrer">puffing billy gem</a> to stub the ajax response)</p>
  
  <pre><code>it " displays correct modal message appears  correctly after relevant 500 xhr / ajax response is received" do
    visit deal_page_path(deal)    
    proxy.stub("http://127.0.0.1:59533/deals/dealname/thrill").and_return(:code =&gt; 500)
    first('a.button').click 
    wait_for_ajax
    within('ul.messenger') do           
      expect(page).to have_content('So sorry, we had a bug, try again')
    end
  end
  </code></pre>
  
  <p>But I fail to test that the correct message is displayed when the problem is a timeout: indeed i don't stub  inside rspec that the response sent by ajax is a timeout because Chrome/webkit actually does not send headers nor an "easy" code like 500 but sends the status (canceled).</p>
  
  <p><a href="https://i.stack.imgur.com/trIzW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/trIzW.png" alt="enter image description here"></a></p>
  
  <p>I tried with no success: </p>
  
  <p><code>proxy.stub("http://127.0.0.1:59533/deals/dealname/thrill").and_return(:status =&gt; 'canceled')</code> </p>
  
  <p><code>proxy.stub("http://127.0.0.1:59533/deals/dealname/thrill").and_return(:status =&gt; '(canceled)')</code> </p>
  
  <p>Note: not sure it's related to the same chrome/webkit behavior but I saw this post: <a href="https://stackoverflow.com/questions/12009423/what-does-status-canceled-for-a-resource-mean-in-chrome-developer-tools">What does status=canceled for a resource mean in Chrome Developer Tools?</a></p>