Reputation: 289
I have a string: I attach "dog.png", "cat.png", and "alphabet.doc"
This is what I want matched:
1. dog.png
2. cat.png
3. alphabet.doc
I can do this by doing "([^"]*)"
, however, the string has to start with 'I attach'
This is the current rule I have in my step definition: /^I attach "([^"]*)"$/
but this doesn't work.
This is for cucumber/gherkin, I can figure something out using scan
but I don't think you can use that in cuke/gherkin?
Any suggestions on how to do this?
Thanks
Upvotes: 2
Views: 608
Reputation: 46836
If you want to capture a variable number of inputs in a single step, I think the best option is to use scan
. While you cannot use scan directly in the step name, you can capture the full list of files and then parse the captured result.
Try the following step definition:
Given /^I attach (.*)$/ do |file_list|
files = file_list.scan(/"(.+?)"/).flatten
#=> ["dog.png", "cat.png", "alphabet.doc"]
end
This will create an array of files to attach. It can handle 1 to infinite files.
Upvotes: 2
Reputation: 2937
This seems like a good place to use the #And alias.
Given I attach dog.png
And I attach cat.png
And I attach alphabet.doc
...
Alternatively you can use data tables for easy multiline arguments
Upvotes: 2