ruby - 捕获小 cucumber 表中的尾随空格

标签 ruby cucumber bdd gherkin

假设我有 2 个这样的场景:

Scenario: scenario 1
  Given foo
  When "meh"
  Then the output should be "hello"

Scenario: scenario 2
  Given foo
  When "blah"
  Then the output should be "hello "

然后我尝试将它们转换成这样的场景大纲

Scenario Outline:
  Given foo
  When <bar>
  Then the output should be <output_string>
  Examples:
  | bar | output_string |
  | meh | hello         |
  | blah| hello         |

事情失败了,因为 gherkin 表格单元格在处理之前已经修剪了它们的空白。有什么方法可以捕获第二个示例中“hello”的尾随空格吗?

最佳答案

将单元格数据放在单引号(或您喜欢的分隔符)中,并添加 Transform这将去掉分隔符。

foo.feature 中:

Scenario Outline:
Given foo
When <bar>
Then the output should be <output_string>
Examples:
| bar | output_string |
| meh | 'hello'       |
| blah| 'hello '      |

features/support/quoted_string_transform.rb 中:

Transform /^'(.*)'$/ do |quoted_string|
  quoted_string
end

转换将应用于所有匹配的捕获,因此请相应地选择分隔符。

关于ruby - 捕获小 cucumber 表中的尾随空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12914618/

相关文章:

python - 假设我们想要设计 django polls 应用程序,那么我们如何继续进行 BDD

ruby-on-rails - Rails 5 default_url_options 怪事

ruby-on-rails - 在 Sublime Text 编辑器中构建 Ruby 时出错

ruby - Watir 和 Cucumber 无法在 win xp 上运行

linux - Linux 上的 Cucumber 与 Windows 上的 Cucumber - 需要了解优缺点

ruby-on-rails - 使用 Cucumber 测试场景的正确方法 (rails 2.3.8)

ruby - 如何在 Ubuntu 14.04 LTS 上使用 Apache2 + Ruby on Rails 配置乘客

ruby - 使用 Ruby 发出 HTTP 请求时出现 EOFError

.net - Ansicon 和 cucumber : 'Ruby interpreter (CUI) 1.9.3p194 [1386-mingw] has stopped working'

javascript - 当我尝试创建提交时出现错误 "Cannot find module ' eslint-config-strict/es 5'"