如何在Cucumber表(多行参数)中使用正则表达式来对表进行区分?

Ali*_*ott 6 ruby regex cucumber

我正在使用场景表(多行步骤参数)使用内置的.diff来检查使用黄瓜的屏幕中的一些数据!黄瓜AST表上的方法.

我想检查与正则表达式匹配的内容.

Scenario: One
    Then the table appears as:
    | One   | Two   | Three |
    | /\d+/ | /\d+/ | /\d+/ |
Run Code Online (Sandbox Code Playgroud)

实际的表可能看起来像

| One | Two | Three |
| 123 | 456 | 789   |
Run Code Online (Sandbox Code Playgroud)

这种情况被翻译为"只要有一些数字,我不在乎"

失败的示例步骤实现:

Then /^the table appears as:$/ do |expected_table|
  actual_table  = [['One','Two', 'Three'],['123', '456', '789']]
  expected_table.diff! actual_table
end
Run Code Online (Sandbox Code Playgroud)

错误:

Then the table appears as: # features/step_definitions/my_steps.rb:230
      | One    | Two    | Three  |
      | /\\d+/ | /\\d+/ | /\\d+/ |
      | 123    | 456    | 789    |
      Tables were not identical (Cucumber::Ast::Table::Different)
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用步骤变换将单元格转换为正则表达式,但它们仍然不相同.

转换代码:

 expected_table.raw[0].each do |column|
    expected_table.map_column! column do |cell|
      if cell.respond_to? :start_with?
        if cell.start_with? "/"
          cell.to_regexp
        else
          cell
        end
      else
        cell
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

这提供了错误:

Then the table appears as: # features/step_definitions/my_steps.rb:228
      | One          | Two          | Three        |
      | (?-mix:\\d+) | (?-mix:\\d+) | (?-mix:\\d+) |
      | 123          | 456          | 789          |
      Tables were not identical (Cucumber::Ast::Table::Different)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我被卡住了.

And*_*ite 4

在场景中使用正则表达式几乎肯定是错误的方法。Cucumber 功能旨在供以业务为中心的利益相关者阅读和理解。

如何在更高层次上编写该步骤,例如:

Then the first three columns of the table should contain a digit
Run Code Online (Sandbox Code Playgroud)