Cookie#acceptable? should not raise ArgumentError when it takes no argument.

Let CookieJar#add convert RuntimeError raised by acceptable? to
ArgumentError.
This commit is contained in:
Akinori MUSHA 2013-04-15 10:29:07 +09:00
parent ea45ee3b38
commit d44218c2e2
3 changed files with 17 additions and 12 deletions

View file

@ -564,9 +564,9 @@ class HTTP::Cookie
def acceptable?
case
when @domain.nil?
raise ArgumentError, "domain is missing"
raise "domain is missing"
when @path.nil?
raise ArgumentError, "path is missing"
raise "path is missing"
when @origin.nil?
true
else
@ -574,8 +574,8 @@ class HTTP::Cookie
end
end
# Tests if it is OK to send this cookie to a given `uri`. A runtime
# error is raised if the cookie's domain is unknown.
# Tests if it is OK to send this cookie to a given `uri`. A
# RuntimeError is raised if the cookie's domain is unknown.
def valid_for_uri?(uri)
if @domain.nil?
raise "cannot tell if this cookie is valid because the domain is unknown"

View file

@ -69,7 +69,12 @@ class HTTP::CookieJar
# jar.origin = origin
# jar.add(cookie) # acceptance check is performed
def add(cookie)
@store.add(cookie) if cookie.acceptable?
@store.add(cookie) if
begin
cookie.acceptable?
rescue RuntimeError => e
raise ArgumentError, e.message
end
self
end
alias << add

View file

@ -523,7 +523,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'key', cookie.name
assert_equal 'value', cookie.value
assert_equal nil, cookie.expires
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
cookie.acceptable?
}
@ -534,7 +534,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'key', cookie.name
assert_equal 'value', cookie.value
assert_equal expires, cookie.expires
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
cookie.acceptable?
}
@ -543,7 +543,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'value', cookie.value
assert_equal expires, cookie.expires
assert_equal false, cookie.for_domain?
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
# domain and path are missing
cookie.acceptable?
}
@ -553,7 +553,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'value', cookie.value
assert_equal expires, cookie.expires
assert_equal true, cookie.for_domain?
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
# path is missing
cookie.acceptable?
}
@ -563,7 +563,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'value', cookie.value
assert_equal expires, cookie.expires
assert_equal false, cookie.for_domain?
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
# path is missing
cookie.acceptable?
}
@ -574,7 +574,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal expires, cookie.expires
assert_equal 'example.org', cookie.domain
assert_equal true, cookie.for_domain?
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
# path is missing
cookie.acceptable?
}
@ -849,7 +849,7 @@ class TestHTTPCookie < Test::Unit::TestCase
cookie.domain = d
assert_equal nil, cookie.domain, "domain=#{d.inspect}"
assert_equal nil, cookie.domain_name, "domain=#{d.inspect}"
assert_raises(ArgumentError) {
assert_raises(RuntimeError) {
cookie.acceptable?
}