2010-09-06 61 views
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> 

任何想法我应该怎么做?

+0

'当我选择“article_big_bananas”'不起作用? – jdl 2010-09-06 22:05:07

回答

1

我现在解决了这个问题,但是做的稍微不同。如果编辑链接将ID设置为Edit_ *,其中*是文章ID,那么我有一堆。然后我有一个黄瓜步骤,使用名称从数据库中检索文章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 

希望能帮助任何有同样问题的人。