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
|
require File.dirname(__FILE__) + "/helper"
class MechErrorsTest < Test::Unit::TestCase
def setup
@agent = WWW::Mechanize.new
end
def test_bad_form_method
page = @agent.get("http://localhost/bad_form_test.html")
assert_raise(RuntimeError) {
@agent.submit(page.forms.first)
}
end
def test_non_exist
begin
page = @agent.get("http://localhost/bad_form_test.html")
rescue RuntimeError => ex
assert_equal("404", ex.inspect)
end
end
def test_too_many_radio
page = @agent.get("http://localhost/form_test.html")
form = page.forms.name('post_form1').first
form.radiobuttons.each { |r| r.checked = true }
assert_raise(RuntimeError) {
@agent.submit(form)
}
end
def test_unknown_agent
assert_raise(RuntimeError) {
@agent.user_agent_alias = "Aaron's Browser"
}
end
def test_bad_url
assert_raise(RuntimeError) {
@agent.get('/foo.html')
}
end
def test_unsupported_scheme
assert_raise(WWW::Mechanize::UnsupportedSchemeError) {
@agent.get('ftp://server.com/foo.html')
}
end
end
|