如果完成时间超过n秒,我想失败(或继续)RSpec测试。我正在使用它来调试应用程序在测试期间停止的位置。
Timeout
块,但是数据库没有被清理,一个线程保持打开状态。也许database_cleaner可以帮到这里...... 'Forced Timeout'
我知道将fail
置于测试中,但只有在读取该行时才有效。相反,如果测试已经在同一行上,比如10秒,我希望它通过失败或调用某些continue
方法进入下一个测试。
Capybara失败消息示例:
1) Exercise Login page - log in as user type
Failure/Error: fill_in "Username", with: @user.name
Capybara::ElementNotFound:
Unable to find field "Username"
答案 0 :(得分:1)
你可以结合使用RSpec around hook和Ruby的Timeout。 在全球范围内,您可以像这样设置它,但如果您知道哪个是问题,您甚至可以在特定测试中进行设置。
require 'timeout'
time_limit = n
RSpec.configure do |c|
c.around(:each) do |example|
Timeout::timeout(time_limit) {
example.run
}
end
end