【发布时间】:2016-03-10 18:18:52
【问题描述】:
我有一些错误情况要记录并移动,然后循环进行下一个测试。
下面发现的错误处理 & rescue 是方法 by_the_test 的一部分,next 语句在其中;在这完成它的工作之后。
下面的单个rescue 单独工作,在错误日志中创建一个条目并继续进行下一个测试。迷人的。
rescue RSpec::Expectations::ExpectationNotMetError
$logfile.puts "#{Date.today}: Error for Row #{$row} - Expected #{@ct_cd}, but got #{@court.text}"
puts "Error for Row #{$row} - Expected #{@ct_cd}, but got #{@court.text}"
当我添加了以下额外的 rescue 语句并且测试命中其中一个时,rescue 不起作用。
rescue Capybara::ElementNotFound
$logfile.puts "#{Date.today}: Error for Row #{$row} - Entry #{@endor_cd} not found"
rescue Capybara::Ambiguous
$logfile.puts "#{Date.today}: Error for Row #{$row} - Duplicated entry on record #{@endor_cd}"
我还尝试了以下方法:
rescue RSpec::Expectations::ExpectationNotMetError, Capybara::ElementNotFound, Capybara::Ambiguous
我在日志文件中收到一般错误消息。
【问题讨论】:
-
显示你得到的错误
-
我得到的错误是:无法找到带有文本“ZZ20”的css“li.category”(Capybara::ElementNotFound)
-
解决了 - 救援声明需要在不同的地方。为编辑干杯 @EVAL。
-
@Peter 请回答您自己的问题以关闭它并在将来帮助其他人。我总是很高兴看到专家回答他们自己的问题。
标签: ruby error-handling capybara rescue