File: test_field_precedence.rb

package info (click to toggle)
libwww-mechanize-ruby 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 883
  • sloc: ruby: 6,621; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 845 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'helper'

class TestFieldPrecedence < Test::Unit::TestCase
  def setup
    @agent = Mechanize.new
    @page = @agent.get('http://localhost/tc_field_precedence.html')
  end

  def test_first_field_wins
    form = @page.forms.first
    assert !form.checkboxes.empty?
    assert_equal "1", form.checkboxes.first.value
    assert_equal 'ticky=1&ticky=0', form.submit.parser.at('#query').text
  end

  def test_field_sort
    doc = Nokogiri::HTML::Document.new
    node = doc.create_element('input')
    node['name'] = 'foo'
    node['value'] = 'bar'

    a = Mechanize::Form::Field.new(node)
    b = Mechanize::Form::Field.new({'name' => 'foo'}, 'bar')
    c = Mechanize::Form::Field.new({'name' => 'foo'}, 'bar')

    assert_equal [a, b], [a, b].sort
    assert_equal [a, b], [b, a].sort
    assert_equal [b, c].sort, [b, c].sort
  end
end