黄瓜和黄瓜webrat,从单选按钮列表中选择

发布于 2024-09-18 03:43:41 字数 1297 浏览 1 评论 0原文

我试图让 webrat 使用黄瓜从列表中选择一个单选按钮。

我有这样的场景:

Scenario: Update an existing article
    Given I have an article with title Big Bananas and body text Big yellow bananas are good for you
    And I am on the list of articles
    When I choose "Big Bananas"
    And press "Update article"
    And I fill in "Title" with "Massive Bananas"
    And I press "Save"
    Then I should have an article titled Massive Bananas
    And I should not have an article titled Big Bananas

我的视图包含:

.
.
<% @articles.each do |article| %>
  <tr>
    <td><%= radio_button_tag "article", article.title %></td>
    <td><%= article.title %></td>
    <td>
      <%article.tags.each do |tag|%>
        <div><%= tag.name %></div>
      <%end%>
    </td>
  </tr>
<%end%>
.
.

问题是我需要我的单选按钮 id 作为文章的标题,以便网络老鼠可以从我的黄瓜场景中选取它,目前我的项目输出如下所示:

<tr>
  <td><input id="article_big_bananas" name="article" type="radio" value="Big Bananas" /></td>  
  <td>Big Bananas</td>
  <td>  
    <div>fruit</div>
    <div>yellow</div>
  </td>
</tr>

有什么想法我应该如何做到这一点?

I'm trying to get webrat to select a radio button from a list, using cucumber.

I have this scenario:

Scenario: Update an existing article
    Given I have an article with title Big Bananas and body text Big yellow bananas are good for you
    And I am on the list of articles
    When I choose "Big Bananas"
    And press "Update article"
    And I fill in "Title" with "Massive Bananas"
    And I press "Save"
    Then I should have an article titled Massive Bananas
    And I should not have an article titled Big Bananas

And my view contains:

.
.
<% @articles.each do |article| %>
  <tr>
    <td><%= radio_button_tag "article", article.title %></td>
    <td><%= article.title %></td>
    <td>
      <%article.tags.each do |tag|%>
        <div><%= tag.name %></div>
      <%end%>
    </td>
  </tr>
<%end%>
.
.

The problem is that I need my radio button id to be the title of the article so web rat can pick it up from my cucumber scenario, at the moment my output for an item looks like:

<tr>
  <td><input id="article_big_bananas" name="article" type="radio" value="Big Bananas" /></td>  
  <td>Big Bananas</td>
  <td>  
    <div>fruit</div>
    <div>yellow</div>
  </td>
</tr>

Any ideas how I should do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2024-09-25 03:43:41

我现在解决了这个问题,但做法略有不同。我有一堆 if edit 链接,我将其 ID 设置为 Edit_*,其中 * 是文章 id。然后,我执行一个 Cucumber 步骤,使用名称从数据库中检索文章 ID,然后点击 ID Edit_* 的链接。这是我更新的代码:

功能

  Scenario: Update an existing article
    Given I have an article with title "Big Bananas" and body text "Big yellow bananas are good for you"
    And I am on the list of articles
    When I follow "Edit" for "Big Bananas"
    And press "Update article"
    And I fill in "Title" with "Massive Bananas"
    And I press "Save"
    Then I should have an article titled "Massive Bananas"
    And I should not have an article titled "Big Bananas"

查看

<table>
  <tr>
    <th>Articles</th>
    <th>Tags</th>
    <td></td>
  </tr>
  <% @articles.each do |article| %>
  <tr>
    <td><%= article.title %></td>
    <td>
      <%article.tags.each do |tag|%>
      <div><%= tag.name %></div>
      <%end%>
    </td>
    <td><%= link_to "Edit", {:controller => "articles", :action => "edit", :id => article.id}, :id => "Edit_" + article.id.to_s %></td>
  </tr>
  <%end%>
</table>
<%= link_to "New article", :action => "new" %>
<% if flash[:notice] %>
   <%= flash[:notice] %>
<% end %>

点击正确编辑链接的黄瓜步骤

When /^I follow "([^\"]*)" for "([^\"]*)"$/ do |link, article_title|
  article = Article.find_by_title article_title
  click_link link + "_" + article.id.to_s
end

希望这对遇到同样问题的人有所帮助。

I solved this problem now, but did it slightly differently. I have a bunch if edit links which I set the ID to be Edit_*, where * is the article id. I then have a cucumber step which retrieves the article ID from the database using the name and then follows the link with ID Edit_*. Here's my updated code:

Feature

  Scenario: Update an existing article
    Given I have an article with title "Big Bananas" and body text "Big yellow bananas are good for you"
    And I am on the list of articles
    When I follow "Edit" for "Big Bananas"
    And press "Update article"
    And I fill in "Title" with "Massive Bananas"
    And I press "Save"
    Then I should have an article titled "Massive Bananas"
    And I should not have an article titled "Big Bananas"

View

<table>
  <tr>
    <th>Articles</th>
    <th>Tags</th>
    <td></td>
  </tr>
  <% @articles.each do |article| %>
  <tr>
    <td><%= article.title %></td>
    <td>
      <%article.tags.each do |tag|%>
      <div><%= tag.name %></div>
      <%end%>
    </td>
    <td><%= link_to "Edit", {:controller => "articles", :action => "edit", :id => article.id}, :id => "Edit_" + article.id.to_s %></td>
  </tr>
  <%end%>
</table>
<%= link_to "New article", :action => "new" %>
<% if flash[:notice] %>
   <%= flash[:notice] %>
<% end %>

Cucumber step to click the correct edit link

When /^I follow "([^\"]*)" for "([^\"]*)"$/ do |link, article_title|
  article = Article.find_by_title article_title
  click_link link + "_" + article.id.to_s
end

Hope that helps anyone who's having the same problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文