File: test_mechanize_form_option.rb

package info (click to toggle)
ruby-mechanize 2.7.6-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,480 kB
  • sloc: ruby: 11,380; makefile: 5; sh: 4
file content (59 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (5)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'mechanize/test_case'

class TestMechanizeFormOption < Mechanize::TestCase

  def setup
    super

    page = html_page <<-BODY
<form name="form1" method="post" action="/form_post">
  <select name="select">
    <option value="1">Option 1</option>
    <option value="2" selected>Option 2</option>
  </select>
</form>
    BODY

    form = page.forms.first
    @select = form.fields.first
    @option1 = @select.options.first
    @option2 = @select.options.last
  end

  def test_inspect
    assert_match "value: 2", @select.inspect
  end

  def test_value_missing_value
    option = node 'option'
    option.inner_html = 'blah'
    option = Mechanize::Form::Option.new option, nil

    assert_equal 'blah', option.value
  end

  def test_click
    @option1.click

    assert @option1.selected?
  end

  def test_select
    @option1.select

    assert @option1.selected?
  end

  def test_unselect
    @option2.unselect

    refute @option2.selected?
  end

  def test_selected_eh
    refute @option1.selected?
    assert @option2.selected?
  end

end