2010-09-06 5 views
0

J'essaie d'obtenir un webrat pour sélectionner un bouton radio dans une liste, en utilisant du concombre.Cucumber & webrat, sélection dans une liste de boutons radio

Je ce scénario:

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 

Et moi CONTIENT:

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

Le problème est que je besoin de mon id bouton radio pour le titre de l'article ainsi rat web peut choisir à partir de mon scénario de concombre, au moment où ma sortie pour un article ressemble à:

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

Toutes les idées comment je devrais faire ça?

+0

'Lorsque je choisis" article_big_bananas "' ne fonctionne pas? – jdl

Répondre

1

J'ai résolu ce problème maintenant, mais l'ai fait légèrement différemment. J'ai un tas si modifier les liens que j'ai mis l'ID à Edit_ *, où * est l'id de l'article. J'ai alors une étape de concombre qui récupère l'ID d'article de la base de données en utilisant le nom, puis suit le lien avec ID Edit_ *. Voici mon code mis à jour:

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" 

Voir

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

étape de concombre à cliquer sur le lien modifier correct

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

Espoir qui aide tous ceux qui ont le même problème.