Monday, July 27, 2009

Webrat's fill_in method on cucumber

Consider the following:

In feature:

And I fill in "Telephone (Home)" with "61234567"

In webrat steps:

When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
(field, :with => value)

The error encountered:

Could not find field: "Telephone (Home)" (Webrat::NotFoundError)

At first I thought the regex couldn't parse "(Home)" properly as "(" & ")" are control characters in regex. Turns out it's because the way webrat's fill_in method looks for the field. I had to use the following instead for the nested form field.

And I fill in "enrollment_addresses_attributes_0_telephone_home" with "61234567"

No comments:

Blog Archive