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
|
require "helper"
class ResponseCodeMechTest < Test::Unit::TestCase
def setup
@agent = Mechanize.new
end
def test_eof_error_loop
assert_raises(EOFError) {
@agent.get("http://localhost/http_headers?Content-Length=300")
}
end
def test_redirect
@agent.get("http://localhost/response_code?code=300")
assert_equal("http://localhost/index.html",
@agent.current_page.uri.to_s)
@agent.get("http://localhost/response_code?code=301")
assert_equal("http://localhost/index.html",
@agent.current_page.uri.to_s)
@agent.get("http://localhost/response_code?code=302")
assert_equal("http://localhost/index.html",
@agent.current_page.uri.to_s)
@agent.get("http://localhost/response_code?code=303")
assert_equal("http://localhost/index.html",
@agent.current_page.uri.to_s)
@agent.get("http://localhost/response_code?code=307")
assert_equal("http://localhost/index.html",
@agent.current_page.uri.to_s)
end
def test_do_not_follow_redirect
@agent.redirect_ok = false
@agent.get("http://localhost/response_code?code=302")
assert_equal("http://localhost/response_code?code=302",
@agent.current_page.uri.to_s)
end
def test_error
@agent = Mechanize.new
begin
@agent.get("http://localhost/response_code?code=500")
rescue Mechanize::ResponseCodeError => err
assert_equal("500", err.response_code)
end
end
end
|