升级到Qt5后,我之前传递的一些规格开始失败。某些故障与不可靠的传出请求有关。例如,在一个规范中,我正在检查是否已经发出10个请求,并且规范将失败,只有n个请求,n有时是2或3或另一个,不可靠。我尝试改变Capybara的默认等待时间,但没有运气。
这是另一个更简单的失败。它在点击链接后检查网址是否发生了变化:
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"
我打开了capybara-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)
谢谢!
答案 0 :(得分:1)
使用Capybara时,不保证动作是同步的,这意味着你需要使用Capybara提供的匹配/重试一下的匹配器。如果您的expect(current_url).to include 'sort=name'
示例应该写为
expect(page).to have_current_path(/sort=name/)
对于您的“请求数量”规范,我们需要查看代码。