File: test_hash_api.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 (45 lines) | stat: -rw-r--r-- 1,184 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "helper"

class TestHashApi < Test::Unit::TestCase
  def setup
    @agent = Mechanize.new
  end

  def test_title
    page = @agent.get(:url => "http://localhost/file_upload.html")
    assert_equal('File Upload Form', page.title)
  end

  def test_page_gets_yielded
    pages = nil
    @agent.get(:url => "http://localhost/file_upload.html") { |page|
      pages = page
    }
    assert pages
    assert_equal('File Upload Form', pages.title)
  end

  def test_get_with_params
    page = @agent.get(:url => 'http://localhost/', :params => { :q => 'hello' })
    assert_equal('http://localhost/?q=hello', page.uri.to_s)
  end

  def test_get_with_referer
    request = nil
    @agent.pre_connect_hooks << lambda { |params|
      request = params[:request]
    }

    @agent.get( :url => 'http://localhost/',
                :referer => URI.parse('http://google.com/')
              )

    assert request
    assert_equal 'http://google.com/', request['Referer']

    @agent.get( :url => 'http://localhost/',
                :params => [],
                :referer => 'http://tenderlovemaking.com/')
    assert_equal 'http://tenderlovemaking.com/', request['Referer']
  end
end