水豚 - 识别 ajax 超时响应代码 (rspec/capybara/webkit/puffing-billy)

Capybara - Identify ajax response code for timeout (rspec/capybara/webkit/puffing-billy)

我进行了操作测试,以检查错误 404、500 的 Rails UJS/ajax 模态中是否显示了正确的消息...这是下面的示例(下面的测试通过;我我正在使用 puffing billy gem 来存根 ajax 响应)

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 => 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

但是当问题是超时时,我无法测试是否显示了正确的消息:实际上我没有在 rspec 中存根 ajax 发送的响应是超时,因为 Chrome/webkit 实际上不发送 headers 也不发送像 500 这样的 "easy" 代码,而是发送状态(已取消)。

我试过没有成功:

proxy.stub("http://127.0.0.1:59533/deals/dealname/thrill").and_return(:status => 'canceled')

proxy.stub("http://127.0.0.1:59533/deals/dealname/thrill").and_return(:status => '(canceled)')

注意:不确定它是否与相同的 chrome/webkit 行为有关,但我看到了这个 post:What does status=canceled for a resource mean in Chrome Developer Tools?

您所说的超时没有 http 状态代码,因为超时具体是指在该时间范围内没有返回 http 状态代码。如果代理的上游连接超时,代理可能会返回一些状态代码,但我认为这与您正在测试的不同。我回答了你关于如何让 Puffing Billy 建立连接的时间比你的超时设置更长的问题 -