Since I didn''t get any response I quickly created my own:
I''m sure there is a better way, but seems to work for now (Have not put
it through any rigurous testing)
def get_table_tag(table_id)
{:tag => ''table'', :attributes => {:id => table_id}}
end
def assert_table_row(table_id, row_number, expected_cell_contents)
tr_nodes = find_all_tag(:tag =>''tr'', :parent =>
get_table_tag(table_id))
assert row_number < tr_nodes.size, "Table: #{table_id}. Looking for
row #{row_number}, but table only has #{tr_nodes.size} rows"
td_nodes = tr_nodes[row_number].find_all(:tag =>''td'')
assert expected_cell_contents.size < td_nodes.size, "Table:
#{table_id}. Expecting at least #{expected_cell_contents.size} cells however,
row only has #{td_nodes.size}"
expected_cell_contents.each_with_index do |expected_cell_content, idx|
assert td_nodes[idx].find(:content => expected_cell_content),
"Unexpected cell contents. Table: #{table_id}. Row: #{row_number}. Column:
#{idx}. Expected: #{expected_cell_content}."
end
end
example usage:
assert_table_row ''table_name'', 0, ["row 0 col 0",
"row 0 col 1", "row 0 col 2"]
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org on behalf
of Michael Fuller
Sent: Mon 11/14/2005 2:37 PM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: assert HTML table contents
Hello,
Is there a nice was to assert the contents of HTML table?
I could do this:
def get_table_tag(table_id)
{:tag => ''table'', :attributes => {:id => table_id}}
end
assert_tag :tag =>"td", :content => "cell content",
:parent => {:tag =>''tr'', :parent =>
get_table_tag(table_id)}
But even doing this only proves there is a cell with "cell content"
anywhere in the table. It does not proves it''s in the right row or
column. I suppose I could use the :sibling condition but it seems the assert
would become rather ugly.
Coming from Java using jWebUnit I could do:
assertTableRowsEqual(java.lang.String tableSummaryOrId, int startRow,
java.lang.String[][] expectedCellValues)
Is there anything similiar?
Thanks.
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails