Forum: Ruby on Rails Using dom_id to localize testing.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-01-08 22:40
I am trying to test a rails app using webrat.  I have this sort of
construct:

  <table  id="entities" caption="Entity Listing" ...>

  <thead>
    <tr>
      <th style="width:20em;">Short Name</th>
...
    </tr>
    <tr>
      <th colspan="2">Legal Name</th>
    </tr>
  </thead>

  <tbody>

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

I am trying to test the destroy link using this webrat code:

  my_entity = Entity.find_by_entity_name(
    "my entity number #{row.hll_words_to_i}")
  within("body > table > tbody > tr#" + dom_id(my_entity, :list) +
         " > td#" + dom_id(my_entity, :delete)) do
    click_link "Destroy Entity"
  end

This fails with a nil exception error:

      You have a nil object when you didn't expect it!
      The error occurred while evaluating nil.to_html (NoMethodError)
      /usr/lib64/ruby/gems/1.8/gems/webrat-0.3.4/lib/webrat/core/scope.rb:176:in
`scoped_dom'
...


I have tried with other variants of the selector.  If I check for the
selector using have_selector("td#" + dom_id(my_entity, :delete)) then it
passes.  If I use the long form above it also passes.  I test for a
missing selector then have_selector fails as expected. Therefore, I am
reasonably certain that the selector is indeed being found on the page.

Any ideas as to what I am doing wrong?
This topic is locked and can not be replied to.