Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array placeholder in Gherkin syntax

Hi I am trying to write express a set of requirements in gherkin syntax, but it requires a good deal of repetition. I saw here that I can use placeholders which would be perfect for my task, however some of the data in my Given and in my then are collections. How would I go about representing collections in the examples?

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 |
|  ?     |  ?      |  ?               |
like image 640
Obi Avatar asked Mar 12 '15 15:03

Obi


2 Answers

A bit hacky, but you can delimit a string:

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
like image 97
jmccure Avatar answered Sep 28 '22 17:09

jmccure


You can use Data Tables. I never try to have param in data table before, but in theory it should work.

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 |
|  ?          |  ?      |  ?               |

The given data table would be an instance of Cucumber::Ast::Table, checkout the rubydoc for its API.

like image 43
hidro Avatar answered Sep 28 '22 19:09

hidro