2016-06-14 52 views
1

我有operationnal測試,以檢查正確的消息顯示在Rails UJS/ajax模態的錯誤404,500 ...這裏低於一個例子(以下測試通過;我使用puffing billy gem末梢Ajax響應)水豚 - 識別阿賈克斯超時響應代碼(rspec /水豚/ webkit /膨化比利)

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 

但我不測試顯示正確的消息時,問題是超時:確實我不t stub在rspec裏面,由ajax發送的響應是一個超時,因爲Chrome/webkit實際上不會發送頭文件,也不是像500那樣的「簡單」代碼,而是發送狀態(取消)。

enter image description here

我嘗試沒有成功:

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)')

注:不知道它與同一鉻/ WebKit的行爲,但我看到了這個帖子:What does status=canceled for a resource mean in Chrome Developer Tools?

回答

1

tim沒有http狀態碼你要說的是,因爲超時特別是在那個時間範圍內沒有返回http狀態碼。如果上游連接超時,代理可能會返回一些狀態碼,但我認爲這與您正在測試的不同。我回答了你的另一個問題,那就是如何讓連接爆裂以便連接的時間超過你的超時設置 - Rails - How to stub a certain response time for a stubbed/fake http or ajax response