3

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

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         |

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

4

2 回答 2

2

将单元格数据放在单引号(或您喜欢的分隔符)中,并添加一个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

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

于 2014-01-05T17:48:51.650 回答
1

我相信解决方案是将单元格数据放在引号中:

Scenario Outline:
Given foo
When <bar>
Then the output should be <output_string>
Examples:
| bar | output_string |
| meh | "hello"       |
| blah| "hello "      |
于 2012-10-16T12:34:44.017 回答