JackNova
JackNova

Reputation: 3931

I see that I'm missing something. What am I doing wrong? Troubles with cucumber and regex

When /I (un)?check the following items: (.*)/ do |uncheck, items_list|
  items_list.split(/,\s?/).each do |item|
    step %Q{I #{uncheck}check "items_#{item.gsub! /"/, ''}"}
  end
end

I have a check and uncheck step defined in another file that works great if in my feature I call

When I check the following items: "A,B,C"

it works

if I call

When I uncheck the following items: "D,E,F"

it happens that cucumber tryes to uncheck 'items_' <<-- ??? why this doesn't contain D, E or F???

Upvotes: 0

Views: 232

Answers (1)

rafaelkin
rafaelkin

Reputation: 425

Try to remove the bang "!" from:

step %Q{I #{uncheck}check "items_#{item.gsub! /"/, ''}"}

Use:

step %Q{I #{uncheck}check "items_#{item.gsub /"/, ''}"}

Or better:

When /I (un)?check the following items: (.*)/ do |uncheck, items_list|
  items_list.gsub! /"/, ''
  items_list.split(/,\s?/).each do |item|
    step %Q{I #{uncheck}check "items_#{item}"}
  end
end

Upvotes: 1

Related Questions