Implement HTTP::CookieJar#empty? without an argument.

This commit is contained in:
Akinori MUSHA 2013-03-15 00:11:31 +09:00
parent 3b38cd2ffd
commit fd7450717a
2 changed files with 18 additions and 2 deletions

View file

@ -46,8 +46,15 @@ class HTTP::CookieJar
}.sort
end
def empty?(url)
cookies(url).empty?
# Tests if the jar is empty. If url is given, tests if there is no
# cookie for the URL.
def empty?(url = nil)
if url
each(url) { return false }
return true
else
@jar.empty?
end
end
# Iterate over cookies. If +uri+ is given, cookies not for the

View file

@ -25,6 +25,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
}.merge(options)
end
def test_empty?
assert_equal true, @jar.empty?
cookie = HTTP::Cookie.new(cookie_values)
@jar.add(cookie)
assert_equal false, @jar.empty?
assert_equal false, @jar.empty?('http://rubyforge.org/')
assert_equal true, @jar.empty?('http://example.local/')
end
def test_two_cookies_same_domain_and_name_different_paths
url = URI 'http://rubyforge.org/'