test/cookie0_test.rb in rufus-verbs-0.10 vs test/cookie0_test.rb in rufus-verbs-1.0.0
- old
+ new
@@ -5,141 +5,139 @@
# jmettraux@gmail.com
#
# Sat Jan 19 18:22:48 JST 2008
#
-require 'test/unit'
-#require 'testbase'
-require 'rufus/verbs'
-require 'rufus/verbs/cookies'
+require File.dirname(__FILE__) + '/base.rb'
+#require 'rufus/verbs/cookies'
class Cookie0Test < Test::Unit::TestCase
- #include TestBaseMixin
+ #include TestBaseMixin
- include Rufus::Verbs::CookieMixin
- include Rufus::Verbs::HostMixin
+ include Rufus::Verbs::CookieMixin
+ include Rufus::Verbs::HostMixin
- #
- # testing split_host(s)
- #
- def test_0
+ #
+ # testing split_host(s)
+ #
+ def test_0
- assert_equal [ 'localhost', nil ], split_host('localhost')
- assert_equal [ 'benz', '.car.co.nz' ], split_host('benz.car.co.nz')
- assert_equal [ '127.0.0.1', nil ], split_host('127.0.0.1')
- assert_equal [ '::1', nil ], split_host('::1')
- end
+ assert_equal [ 'localhost', nil ], split_host('localhost')
+ assert_equal [ 'benz', '.car.co.nz' ], split_host('benz.car.co.nz')
+ assert_equal [ '127.0.0.1', nil ], split_host('127.0.0.1')
+ assert_equal [ '::1', nil ], split_host('::1')
+ end
- #
- # testing the CookieJar
- #
- def test_1
+ #
+ # testing the CookieJar
+ #
+ def test_1
- cookie0 = TestCookie.new
- cookie1 = TestCookie.new
+ cookie0 = TestCookie.new
+ cookie1 = TestCookie.new
- jar = Rufus::Verbs::CookieJar.new 77
- assert_equal 0, jar.size
+ jar = Rufus::Verbs::CookieJar.new 77
+ assert_equal 0, jar.size
- jar.add_cookie(".rubyforge.org", "/", cookie0)
- assert_equal 1, jar.size
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
+ jar.add_cookie(".rubyforge.org", "/", cookie0)
+ assert_equal 1, jar.size
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
- jar.add_cookie("rufus.rubyforge.org", "/sub", cookie1)
- assert_equal 2, jar.size
- assert_equal [ cookie1, cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/sub/0")
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/")
+ jar.add_cookie("rufus.rubyforge.org", "/sub", cookie1)
+ assert_equal 2, jar.size
+ assert_equal [ cookie1, cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/sub/0")
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/")
- jar.remove_cookie("rufus.rubyforge.org", "/sub", cookie1)
- assert_equal 1, jar.size
- end
+ jar.remove_cookie("rufus.rubyforge.org", "/sub", cookie1)
+ assert_equal 1, jar.size
+ end
- #
- # testing cookie_acceptable?(opts, cookie)
- #
- def test_2
+ #
+ # testing cookie_acceptable?(opts, cookie)
+ #
+ def test_2
- jar = Rufus::Verbs::CookieJar.new 77
+ jar = Rufus::Verbs::CookieJar.new 77
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
- c = TestCookie.new '.rubyforge.org', '/'
- r = TestResponse.new opts
- assert cookie_acceptable?(opts, r, c)
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
+ c = TestCookie.new '.rubyforge.org', '/'
+ r = TestResponse.new opts
+ assert cookie_acceptable?(opts, r, c)
- # * The value for the Domain attribute contains no embedded dots
- # or does not start with a dot.
+ # * The value for the Domain attribute contains no embedded dots
+ # or does not start with a dot.
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
- c = TestCookie.new 'rufus.rubyforge.org', '/'
- r = TestResponse.new opts
- assert ! cookie_acceptable?(opts, r, c)
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
+ c = TestCookie.new 'rufus.rubyforge.org', '/'
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
- c = TestCookie.new 'org', '/'
- r = TestResponse.new opts
- assert ! cookie_acceptable?(opts, r, c)
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
+ c = TestCookie.new 'org', '/'
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
- # * The value for the Path attribute is not a prefix of the
- # request-URI.
+ # * The value for the Path attribute is not a prefix of the
+ # request-URI.
- opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
- c = TestCookie.new '.rubyforge.org', '/that'
- r = TestResponse.new opts
- assert ! cookie_acceptable?(opts, r, c)
+ opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
+ c = TestCookie.new '.rubyforge.org', '/that'
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
- # * The value for the request-host does not domain-match the
- # Domain attribute.
+ # * The value for the request-host does not domain-match the
+ # Domain attribute.
- opts = { :host => 'rufus.rubyforg.org', :path => '/' }
- c = TestCookie.new '.rubyforge.org', '/'
- r = TestResponse.new opts
- assert ! cookie_acceptable?(opts, r, c)
+ opts = { :host => 'rufus.rubyforg.org', :path => '/' }
+ c = TestCookie.new '.rubyforge.org', '/'
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
- # * The request-host is a FQDN (not IP address) and has the form
- # HD, where D is the value of the Domain attribute, and H is a
- # string that contains one or more dots.
-
- # implicit...
- end
+ # * The request-host is a FQDN (not IP address) and has the form
+ # HD, where D is the value of the Domain attribute, and H is a
+ # string that contains one or more dots.
- #def test_webrick_cookie
- # require 'webrick/cookie'
- # cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
- # p WEBrick::Cookie.parse_set_cookie(cookie)
- # p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
- #end
+ # implicit...
+ end
- protected
+ #def test_webrick_cookie
+ # require 'webrick/cookie'
+ # cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
+ # p WEBrick::Cookie.parse_set_cookie(cookie)
+ # p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
+ #end
- class TestCookie
+ protected
- attr_reader :domain, :path, :name
+ class TestCookie
- def initialize (domain=nil, path=nil, name='whatever')
+ attr_reader :domain, :path, :name
- @domain = domain
- @path = path
- @name = name
- end
- end
+ def initialize (domain=nil, path=nil, name='whatever')
- class TestResponse
+ @domain = domain
+ @path = path
+ @name = name
+ end
+ end
- def initialize (opts)
+ class TestResponse
- @path = opts[:path]
- end
+ def initialize (opts)
- def request
+ @path = opts[:path]
+ end
- r = Object.new
- class << r
- attr_accessor :path
- end
- r.path = @path
- r
- end
- end
+ def request
+
+ r = Object.new
+ class << r
+ attr_accessor :path
+ end
+ r.path = @path
+ r
+ end
+ end
end