How to use Cucumber in forms with custom labels
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::Not开发者_如何学GoFoundError)
(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?
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?
You can also use the field name as it appears in HTML. So if the model name
belongs to is lets say User
than 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.
精彩评论