2016-04-15 52 views
0

升級到Qt5後,我之前通過的一些規格開始失敗。某些失敗與不可靠的傳出請求有關。例如,在一個規範中,我正在檢查是否有10個請求已經完成,並且規範將失敗,只有n個請求發生,n有時是2或3或另一個,不可靠。我嘗試改變水豚的默認等待時間,但沒有運氣。在升級到Qt5後,RSpec查看規格失敗,因爲capybara-webkit

這是另一個更簡單的故障。它檢查是否點擊一個鏈接後,鏈接改變:

it 'shows sorting with correct link', js: true do 
    expect(page).to have_content(/Sorted by/i) 
    expect(page).to have_selector(:link_or_button, text: /Most Recent/i) 
    page.find(:link_or_button, text: /A-Z/i).click 
    expect(current_url).to include 'sort=name' 
end 

而且它給我的失敗:

Failure/Error: expect(current_url).to include 'sort=name' 
    expected "http://127.0.0.1:51355/shows" to include "sort=name" 

我打開水豚,WebKit的調試模式,它看起來像它實際上並沒有響應寫入新的網址:

(... previous logs ignored...) 

Received "Node.leftClick" 
Started "Node.leftClick" 
Started request to "http://127.0.0.1:51355/shows?sort=name&status=" 
Finished "Node.leftClick" with response "Success()" 
Wrote response true "" 
Received "CurrentUrl()" 
Started "CurrentUrl()" 
Finished "CurrentUrl()" with response "Success(http://127.0.0.1:51355/shows)" 
Wrote response true "http://127.0.0.1:51355/shows" 
Received 200 from "http://127.0.0.1:51355/shows?sort=name&status=" 
Received "Reset()" 
Started "Reset()" 
Finished "Reset()" with response "Success()" 
Wrote response true "" 
Received "EnableLogging()" 
Started "EnableLogging()" 
Finished "EnableLogging()" with response "Success()" 
Wrote response true "" 
Received "SetUnknownUrlMode(block)" 
Started "SetUnknownUrlMode(block)" 
Finished "SetUnknownUrlMode(block)" with response "Success()" 
Wrote response true "" 
Received "SetTimeout(300)" 
Started "SetTimeout(300)" 
Finished "SetTimeout(300)" with response "Success()" 
Wrote response true "" 
     shows sorting with correct link (FAILED - 1) 

我不知道是否有人已經經歷過類似的故障或者我如何進一步調查此問題。該規格通過與Qt4構建的capybara-webkit傳遞,但不知道爲什麼他們與Qt5失敗。關於我的設置更多信息:

capybara (2.7.0) 
capybara-webkit (1.10.1) 
rails (4.2.5.1) 
rspec (3.3) 

謝謝!

回答

1

使用Capybara時,不保證動作是同步的,這意味着您需要使用由Capybara提供的匹配器,它將等待/重試一點點。在應寫爲

expect(page).to have_current_path(/sort=name/) 

爲貴「提出的要求數」你expect(current_url).to include 'sort=name'例子的情況下,規範我們需要看到的代碼。

+0

是的!謝謝!使用水豚匹配器解決了這個規範。關於「請求數量」規範,我認爲capybara-webkit現在是[緩存請求](https://github.com/thoughtbot/capybara-webkit/issues/724)。在將隨機查詢字符串追加到url後,它的行爲如預期。不知道如何解決這個問題,或禁用瀏覽器緩存。因爲這個,我當然不想改變實際的代碼。你有什麼想法? – 322896

+0

@ 322896對不起 - 除了在測試模式下只添加隨機查詢字符串時,不知道如何解決這個問題 - 儘管如果您確實需要在生產中創建請求的數量,那麼您仍然需要某些方法來緩存緩存。 –

+0

是的,謝謝。也許我必須讓規格更真實或者解決它。 – 322896