Gherkin 语法中的数组占位符

Obi*_*Obi 6 bdd cucumber gherkin

嗨,我正在尝试用小黄瓜语法编写表达一组要求,但这需要大量重复。我在这里看到我可以使用占位符,这对我的任务来说是完美的,但是我的 Given 和 then 中的一些数据是集合。我将如何在示例中表示集合?

Given a collection of spaces <spaces>
    And a <request> to allocate space
When I allocate the request
Then I should have <allocated_spaces>

Examples:
| spaces | request | allocated_spaces |
|  ?     |  ?      |  ?               |
Run Code Online (Sandbox Code Playgroud)

jmc*_*ure 5

有点hacky,但你可以分隔一个字符串:

Given a collection of spaces <spaces>
    And a <request> to allocate space
When I allocate the request
Then I should have <allocated_spaces>

Examples:
| spaces    | request | allocated_spaces |
|   a,b,c   |  ?      |  ?               |

Given(/^a collection of spaces (.*?)$/) do |arg1|
  collection = arg1.split(",")  #=> ["a","b","c"]
end
Run Code Online (Sandbox Code Playgroud)


hid*_*dro 1

您可以使用数据表。我以前从未尝试过在数据表中包含参数,但理论上它应该有效。

Given a collection of spaces:
| space1        |
| space2        |
| <space_param> |
And a <request> to allocate space
When I allocate the request
Then I should have <allocated_spaces>

Examples:
| space_param | request | allocated_spaces |
|  ?          |  ?      |  ?               |
Run Code Online (Sandbox Code Playgroud)

给定的数据表将是 的一个实例Cucumber::Ast::Table,请查看 ruby​​doc 以了解其 API。