I am trying to test a rails app using webrat. I have this sort of
construct:
Short Name |
...
Legal Name |
<% for entity in @entities %>
<%=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 -%> |
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?