File: tc_response_code.rb

package info (click to toggle)
libwww-mechanize-ruby 0.6.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 660 kB
  • ctags: 723
  • sloc: ruby: 5,475; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 853 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
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'test/unit'
require 'rubygems'
require 'mechanize'
require 'test_includes'

class ResponseCodeMechTest < Test::Unit::TestCase
  include TestMethods

  def setup
    @agent = WWW::Mechanize.new
  end

  def test_redirect
    @agent.get("http://localhost:#{PORT}/response_code?code=301")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)

    @agent.get("http://localhost:#{PORT}/response_code?code=302")
    assert_equal("http://localhost:#{PORT}/index.html",
      @agent.current_page.uri.to_s)
  end

  def test_error
    @agent = WWW::Mechanize.new
    begin
      @agent.get("http://localhost:#{PORT}/response_code?code=500")
    rescue WWW::Mechanize::ResponseCodeError => err
      assert_equal("500", err.response_code)
    end
  end
end