2010-09-06 56 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 

希望能幫助任何有同樣問題的人。