Over a million developers have joined DZone.

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
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}