views:

127

answers:

2

I'm trying to learn how to use cucumber and got this issue:

I have a form that as:

  <p>
    <%= f.label :name, "Nome" %><br />
    <%= f.text_field :name %>
  </p>

And in my cucumber feature I have:

  And I fill in "name" with "Reitoria do Porto"

This make the test fail with:

And I fill in "name" with "Reitoria do Porto"       # features/step_definitions/web_steps.rb:34
      Could not find field: "name" (Webrat::NotFoundError)
      (eval):2:in `fill_in'
      ./features/step_definitions/web_steps.rb:35:in `/^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/'
      features/manage_institutions.feature:10:in `And I fill in "name" with "Reitoria do Porto"'

However if I just make the form like this:

  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>

The test passes.

How can I keep my custom label name and make the test pass?

+1  A: 

You can also use the field name as it appears in HTML. So if the model namebelongs to is lets say Userthan you should be able to access it via

And I fill in "user_name" with "Reitoria do Porto"

If in doubt, just have a look at the generated HTML code and take the field name from there.

ajmurmann
+1  A: 

Webrat uses the label text to locate the field to fill in. In your first example, are you not setting this label to "Nome"?

Does And I fill in "Nome" with "Reitoria do Porto" work?

Rodreegez
Yes it works! Gezz I should have tryed that one.
Victor Martins