DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Using Xpath To Test The Rails
Originally posted in #rubyonrails by ? springjp
def test_account_list
# There should be some accounts to test
assert @ttrueheart.accounts.count > 0
@request.session[:user] = @ttrueheart
get :list
assert_success
xml = nil
assert_nothing_thrown { xml = REXML::Document.new(@response.body) }
@ttrueheart.accounts.each do |account|
td = REXML::XPath.match(xml, "//td[text()=\"#{account.display_string}\"]")
assert_equal(1, td.size) # Unique entry
assert_equal(3, REXML::XPath.match(td, 'following-sibling::td/a').size)
href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/activity_list/#{account.id}']")
assert_equal(1, href.size)
href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/edit/#{account.id}']")
assert_equal(1, href.size)
href = REXML::XPath.match(td, "following-sibling::td/a[@href='/account/delete/#{account.id}']")
assert_equal(1, href.size)
end
end





