On Nov 22, 4:00 pm, Julie <[email protected]> wrote:
> Hello,
>
> I'm fairly new to Ruby, cucumber, and WebDriver and ran into what
> seems to be a Ruby issue. It doesn't seem to be handling my .intern
> or .to_sym in this mock-up inline form, ele.send_keys(x[i],
> x[i].intern, x[i], x[i].intern)
>
> I tried both intern and to_sym with the same result, as expected.
>
> I'm trying to parse a string and output a string with symbol
> parameter.
>
> Input string: 'Student One', :return, 'Student Two', :return
> Output: ele.send_keys('Student One', :return, 'Student Two', :return)
>
> def fill_in(field_name,text)
> # ele = Find.Element(find_locator(:text_field,field_name))
> # ele.clear
> #The above correctly obtains the text:
> # 'Student One', :return, 'Student Two', :return
> #Therefore, hard code to test:
> text = "'Student One', :return, 'Student Two', :return"
> items = text.split(/,\s?/)
> ele.send_keys(items.each_index {|x|
> next if x % 2 == 1
> if (x<items.size-1) then items[x] +', ' else items[x] end
> items[x+1].intern
> })
Couple problems here:
- each_index returns the original array. You're not assigning any new
values to it, so of course .intern isn't having any effect.
- not sure exactly what you're doing with the +', ' there, but I
suspect you really want Ruby's "splat" operator. It takes an array and
fills in the arguments to the method with each element (simplified
description). Your code would end up looking like:
items = text.split(/,\s?/)
ele.send_keys(*items.map {|x|
case x
when /^'(.*)'$/ then $1 # "'Student One'" => "Student One"
when /^:(.*)$/ then $1.to_sym # ":return" => :return
end
})
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.