I am trying to pass the parameters from a .feature file (cucumber) to a method call in a .rb file
heres what i have:
feature file
When I set something to blah
step definition for the above feature file:
When /^I set something to (.+)$/ do |value|
methodcall(["#{value}"]))
end
method in a separate .rb file
def methodcall (a=[],b=[],c=[])
a.each {|x|
do something with x
}
b.each {|y|
do something with y
}
c.each {|z|
do something with z
}
...
end
It works fine when I give only one parameter in .feature file . I am hoping that it’ll work for one value for each of the array (not tried this though)
but what I want to do is write in feature file something like this
And I set something to "blah,blah1,blah2" and somethingelse to "blah4,blah5" and otherthings to "blah6, blah7"
for the above, step definition would look like
When /^I set something to (.+) and somethingelse to (.+) and
and otherthings to (.+)$/ do |value, value1, value2|
methodcall(["#{value}"], ["#{value1}"], ["#{value2}"]))
end
and through the above step definition, have the values in value, value1, value2 to be passed in arguments corresponding to a=[], b=[], c=[] and call the methodcall() method. can someone please help.. Thanks.
In your code
You are taking the string value and turning it into the first element of an array, which is then passed to the methodcall().
I believe what you actually want to do is
This will take your value, break it up by commas and puts each of those as an element of the array.
To illustrate with your example, given that methodcall() is:
Then
Where as