File: test_mechanize_history.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 (103 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download | duplicates (6)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'mechanize/test_case'

class TestMechanizeHistory < Mechanize::TestCase

  def setup
    super

    @uri = URI 'http://example/'
    @uri2 = @uri + '/a'
    @history = Mechanize::History.new
  end

  def test_initialize
    assert_empty @history
  end

  def test_clear
    @history.push :page, @uri

    @history.clear

    assert_empty @history
  end

  def test_pop
    assert_nil @history.pop

    @history.push :page1, @uri
    @history.push :page2, @uri2

    assert_equal :page2, @history.pop
    refute_empty @history
  end

  def test_push
    p1 = page @uri

    obj = @history.push p1

    assert_same @history, obj
    assert_equal 1, @history.length

    p2 = page @uri2

    @history.push p2

    assert_equal 2, @history.length
  end

  def test_push_max_size
    @history = Mechanize::History.new 2

    @history.push :page1, @uri

    assert_equal 1, @history.length

    @history.push :page2, @uri

    assert_equal 2, @history.length

    @history.push :page3, @uri

    assert_equal 2, @history.length
  end

  def test_push_uri
    obj = @history.push :page, @uri

    assert_same @history, obj
    assert_equal 1, @history.length

    @history.push :page2, @uri

    assert_equal 2, @history.length
  end

  def test_shift
    assert_nil @history.shift

    @history.push :page1, @uri
    @history.push :page2, @uri2

    page = @history.shift

    assert_equal :page1, page
    refute_empty @history

    @history.shift

    assert_empty @history
  end

  def test_visited_eh
    refute @history.visited? @uri

    @history.push page @uri

    assert @history.visited? URI('http://example')
    assert @history.visited? URI('http://example/')
  end

end