簡體   English   中英

黃瓜紅寶石救援例外情況名稱

[英]cucumber ruby rescue exception Scenario name

我正在編寫一些使用Cucumbers數據表的測試。 它遍歷11個場景,並且如果第1行出現故障,則以下內容將被忽略(眾所周知)。 希望我為此添加一些異常處理,以便無論如何都要檢查整個表。 這是我的桌子:

 | Row | add_line_1    | add_line_2 | add_line_3     | post_town | post_code | error                                                                                                                              |
      | 1   | 123           | Over There | And down a bit | Swansea   | SA9 2NG   | Building/number and street must contain between 4 and 30 farts                                                                |
      | 2   | 1234          | Over There | And down a bit | Swansea   | SA9 2NG   | Must have at least 3 alpha characters                                                                                              |
      | 3   | ****          | Over There | And down a bit | Swansea   | SA9 2BG   | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
      | 4   | ***           | Over There | And down a bit | Swansea   | SA9 2BG   | Building/number and street must contain between 4 and 30 characters                                                                |
      | 5   | 1 High Street | ***        | And down a bit | Swansea   | SA9 2BG   | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
      | 6   | 1 High Street | Over There | ***            | Swansea   | SA9 2BG   | The first character of the address must be alphanumeric. Other characters must be valid (a-z, A-Z, 0-9, &, -, (), /, ' and , or .) |
      | 7   | 1 High Street | Over There | And down a bit | ****      | SA9 2BG   | Post town contains invalid characters                                                                                              |
      | 8   | 1 High Street | Over There | And down a bit | ***       | SA9 2BG   | Post town contains invalid characters                                                                                              |
      | 9   | 1 High Street | Over There | And down a bit | A         | SA9 2BG   | Post town requires a minimum length of three characters                                                                            |
      | 10  | 1 High Street | Over There | And down a bit | Swansea   | ***       | Must be between five and eight characters and in a valid format, e.g. AB1 2BA or AB12BA      

測試通常在第一行失敗,因為預期的錯誤文本不正確。

因此,我已將此代碼寫入我的代碼中:

begin
    expect(all_text).to have_text @error
rescue Exception => e
  puts "#{scenario.name} >>"
  puts "Table row #{@row}: #{e}"
end

如果您認為整個測試包中有40多個表,那么異常處理本身不會告訴您發生故障的位置。

我想捕獲方案名稱,並將其包含在異常處理中,但是我收到一條錯誤消息,指出方案的未定義方法。

有什么方法可以將其添加到代碼塊中嗎?

謝謝

我讀得越多,就越意識到我無法用我想要的方式做到這一點。 所以我做了以下事情:

Before do |scenario|
  @feature_name = scenario.feature.name
  @scenario_name = scenario.name
end

begin
  expect(all_text).to have_text @error
  rescue Exception => e
  puts @feature_name + ' : ' + @scenario_name
  puts "Table row #{@row}: #{e}"
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM