Oddness with fieldnames containing an underscore


#1

Hi all,

I’m not sure if this is a cucumber or webrat thing given that I only
starting tinkering with both last night for the first time (testing
newb as well), but I’ve come across an oddity when trying to write a
scenario to create a user.

Scenario: Register new user
Given I am on the new user page
And I fill in “login” with “fredf”
And I fill in “password” with “somepassword”
And I fill in “password_confirmation” with “somepassword”
And I select “Mr” from “title”
And I fill in “given_names” with “Fred”
And I fill in “surname” with “Flintstone”
And I fill in “email” with “removed_email_address@domain.invalid”
And I press “Create”
Then there should be 1 more user

When I ‘rake features’ it halts at the password_confirmation line…

Scenario: Register new user # features/
manage_users.feature:16
Given I am on the new user page # features/
step_definitions/user_steps.rb:5
And I fill in “login” with “johnm” # features/
step_definitions/webrat_steps.rb:12
And I fill in “password” with “Lmmsoht” # features/
step_definitions/webrat_steps.rb:12
And I fill in “password_confirmation” with “Lmmsoht” # features/
step_definitions/webrat_steps.rb:12
Could not find field:
“password_confirmation” (Webrat::NotFoundError)

The test passes if I prepend “user_” to the field name ie.
“user_password_confirmation”. Same applies to the ‘given_names’ field.

Is this a bug or am I making an incorrect assumption on how things are
supposed to work?

TIA,

JohnM

“I’m not dumb. I just have a command of thoroughly useless information”

  • Calvin & Hobbes

#2

Probably not a bug, if you look at the id’s of the fields your matching
by
viewing source in your browser you’ll see that they have an id that
begins
with ‘user’. So when webrat fails to match on the label text it then
tries
to match on the id. You can use the debugger to step into the webrat
code
and see this yourself if you want
HTH

2008/12/10 John M. removed_email_address@domain.invalid