[rspec-users] cucumber, finding a row in a table

James Byrne lists at ruby-forum.com
Thu Jan 8 13:13:54 EST 2009

I am still not getting this to work.  Here is what I have done:

In index.html.erb

  <table  id="entities" caption="Entity Listing"
          title="All Entites"
          border="1" cellpadding="2"cellspacing="6"
          summary="This layout lists all of the entities on file and
          provides links to maintain dependent roles and data.">

      <th style="width:20em;">Short Name</th>


  <% for entity in @entities %>
  <tr id="<%=dom_id(entity)%>">
    <td><%=h entity.entity_name.titlecase -%></td>
    <td><%= "%06d" % entity.id -%></td>
    <td><%= link_to 'Show Entity', entity -%></td>
    <td><%= link_to 'Edit Entity', edit_entity_path(entity) -%></td>
    <td><%= link_to 'Destroy Entity', entity,
                    :confirm => 'Are you sure?',
                    :method => :delete -%></td>

In the step definition file:

When /I delete the "(.*)" entity/ do |row|
  visits entities_url
  puts entities_url
  my_entity = Entity.find_by_entity_name(
              "my entity number #{row.hll_words_to_i}")
  puts "selector found" if have_selector(
               "table > tbody > tr#" + dom_id(my_entity) + " > td > a")
  within("table > tbody > tr#" + dom_id(my_entity) + " > td > a") do
  click_link "Destroy Entity"

The results:

  Scenario: Delete entity                   # 
    Given I have "4" valid entities         # 
selector found
    When I delete the "first" entity        # 
      You have a nil object when you didn't expect it!
      The error occurred while evaluating nil.to_html (NoMethodError)

The selector is found so what is my error?

I have backed off the selector element by element to "table > tbody > 
tr#" + dom_id(myentity) with no change in the result. I always get a nil 
object error.

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list