File: test_mechanize_form_check_box.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 (48 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (3)
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
require 'mechanize/test_case'

class TestMechanizeFormCheckBox < Mechanize::TestCase

  def setup
    super

    @page = @mech.get('http://localhost/tc_checkboxes.html')
  end

  def test_search
    form = @page.forms.first

    checkbox = form.checkbox_with(name: 'green')
    assert_equal('green', checkbox.name)

    assert_equal(checkbox, form.checkbox_with('green'))
    assert_equal(checkbox, form.checkbox_with(search: 'input[@type=checkbox][@name=green]'))
  end

  def test_check
    form = @page.forms.first

    form.checkbox_with(:name => 'green').check

    assert(form.checkbox_with(:name => 'green').checked)

    %w{ red blue yellow brown }.each do |color|
      assert_equal(false, form.checkbox_with(:name => color).checked)
    end
  end

  def test_uncheck
    form = @page.forms.first

    checkbox = form.checkbox_with(:name => 'green')

    checkbox.check

    assert form.checkbox_with(:name => 'green').checked

    checkbox.uncheck

    assert !form.checkbox_with(:name => 'green').checked
  end

end