I’ve run into another functional testing issue. Odds are I’m taking the
wrong approach, so I’m back to this list again in the hopes of finding
the true path.
with assert_tag, I’d like to check the values of various table cells and
ensure that the proper values are placed in the appropriate places. I
written some tests that make good sense to me, and in general they
behave as expected. I ran into trouble with nested tables. To
demonstrate, I’ve put together a simple test that calls the index action
of some controller, and this renders a hard-coded html page.
I want to make sure the correct elements are in the “Morning” row, so I
find the “Morning” table cell and verify that it has a parent “tr” tag
that in turn has a child “td” tag that holds the values I want. These
are the first two tests.
For the next test I want to make sure the Teacher’s name (Teacher One in
this case) is not put into the cells. When I run these tests against
the html shown, the last test will fail. However, if I remove the
outer-most table (delete or comment out the first 3 lines and the last 3
lines of the html) the tests will all pass.
Am I using assert_tag incorrectly to ensure my tables are constructed
properly? If I am, how should I be traversing a table for values? These
tests seem to make sense, and the :parent appears to be acting as if it
were :ancestor.
************* Begin Functional test ***********************************
def test_general
get :index
assert_tag :tag => ‘td’, :content => ‘Morning’, :parent => {:tag =>
‘tr’, :child =>
{:tag => ‘td’, :content => ‘Subject 1’}}
assert_tag :tag => ‘td’, :content => ‘Mid-Day’, :parent => {:tag =>
‘tr’, :child => {:tag => ‘td’, :content => ‘Subject 2’}}
assert_no_tag :tag => ‘td’, :content => ‘Morning’, :parent => {:tag
=> ‘tr’, :child => {:tag => ‘td’, :content => ‘Teacher One’}}
end
*************************** Begin html *************************
Schedule for Teacher One
|