假设我有 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/