Using dom_id to localize testing

I am trying to test a rails app using webrat. I have this sort of


<% for entity in @entities %>


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”

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)


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?

Short Name
Legal Name
<%=h entity.entity_name.titlecase -%> <%= link_to 'Show Entity', entity -%> <%= link_to 'Edit Entity', edit_entity_path(entity) -%> <%= link_to 'Destroy Entity', entity, :confirm => 'Are you sure?', :method => :delete -%>