Ruby 'next' 语句在 'while' 循环中

Ruby 'next' statement within a 'while' loop

我正在尝试编写一个执行 while 循环的测试,该循环最终将负责遍历分布在多个场景中的 1920 个循环。

如果一个循环失败,在这种情况下,文本不匹配,我希望循环移动到下一个迭代。

这是我正确迭代的 while 循环:

And(/^click on the endorsement to confirm court description from rows "(.*?)" to "(.*?)"$/) do |first_row, last_row|


data = CsvMapper.import('C:/auto_test_data/Courts code example csv.csv') do
    [dln, ni, pc, endorse, courtdesc]
  end


    cell = first_row.to_i - 1

while cell < last_row.to_i

  endorsement = data.at(cell).endorse
  courtdescription = data.at(cell).courtdesc

  find('li.category', text: endorsement).click

  court = first('li.offence-court', text: 'Court/Fixed penalty office')


  expect(court).to have_text courtdescription
  # add 'next' statement if this step fails

find('li.category', text: endorsement).click

cell = cell + 1


puts court.text



 end
  end

在该循环中,我已经评论了故障点所在的位置,并且需要一些可以使循环移动到下一次迭代的内容。

此时错误处理是可选的。

任何帮助都将非常有用,因为我不想沿着 Cucumber 中的示例表路线进行 1920 次迭代。

谢谢

防止断言使您的测试失败是一种奇怪的方式,如果您有多个要从一个测试中报告的东西,这表明您或许应该进行多个测试。但是坚持这种策略,构建一组不匹配的数据然后在完成时断言它是空的会相当有效。然后你的测试在正确的情况下失败了,你有一个迭代导致它的列表。

failures = []
while cell < last_row.to_i
  # Gather your data
  failures << [cell, court] unless court.text.include?(courtdescription)
  # Prepare for the next iteration
end
expect(failures).to be_empty