开发者

How to use Cucumber in forms with custom labels

开发者 https://www.devze.com 2022-12-22 13:33 出处:网络
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 />

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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号