http-cookie 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,14 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
2
3
 
3
- if RUBY_VERSION >= '1.9.0'
4
- require 'rake/testtask'
5
- Rake::TestTask
6
- else
7
- require 'rcov/rcovtask'
8
- Rcov::RcovTask
9
- end.new(:test) do |test|
10
- test.libs << 'lib' << 'test'
11
- test.ruby_opts << '-r./test/simplecov_start.rb' if !defined?(Rcov)
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.ruby_opts << '-r./test/simplecov_start.rb' if defined?(SimbleCov)
12
6
  test.pattern = 'test/**/test_*.rb'
13
7
  test.verbose = true
14
8
  end
@@ -7,6 +7,17 @@ module HTTP
7
7
  autoload :CookieJar, 'http/cookie_jar'
8
8
  end
9
9
 
10
+ # In Ruby < 1.9.3 URI() does not accept an URI object.
11
+ if RUBY_VERSION < "1.9.3"
12
+ begin
13
+ URI(URI(''))
14
+ rescue
15
+ def URI(url)
16
+ url.is_a?(URI) ? url : URI.parse(url)
17
+ end
18
+ end
19
+ end
20
+
10
21
  # This class is used to represent an HTTP Cookie.
11
22
  class HTTP::Cookie
12
23
  # Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least)
@@ -25,16 +36,6 @@ class HTTP::Cookie
25
36
  expires created_at accessed_at
26
37
  ]
27
38
 
28
- # In Ruby < 1.9.3 URI() does not accept an URI object.
29
- if RUBY_VERSION < "1.9.3"
30
- module URIFix
31
- def URI(url)
32
- url.is_a?(URI) ? url : Kernel::URI(url)
33
- end
34
- private :URI
35
- end
36
- end
37
-
38
39
  if String.respond_to?(:try_convert)
39
40
  def check_string_type(object)
40
41
  String.try_convert(object)
@@ -52,8 +53,6 @@ class HTTP::Cookie
52
53
  private :check_string_type
53
54
  end
54
55
 
55
- include URIFix if defined?(URIFix)
56
-
57
56
  attr_reader :name, :domain, :path, :origin
58
57
  attr_accessor :secure, :httponly, :value, :version
59
58
  attr_reader :domain_name, :expires
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  class Cookie
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -5,8 +5,8 @@ require 'http/cookie'
5
5
  # any particular website.
6
6
 
7
7
  class HTTP::CookieJar
8
- autoload :AbstractSaver, 'http/cookie_jar/abstract_saver'
9
- autoload :AbstractStore, 'http/cookie_jar/abstract_store'
8
+ require 'http/cookie_jar/abstract_store'
9
+ require 'http/cookie_jar/abstract_saver'
10
10
 
11
11
  attr_reader :store
12
12
 
@@ -136,7 +136,7 @@ class HTTP::CookieJar
136
136
 
137
137
  begin
138
138
  saver = AbstractSaver.implementation(opthash[:format]).new(opthash)
139
- rescue KeyError => e
139
+ rescue IndexError => e
140
140
  raise ArgumentError, e.message
141
141
  end
142
142
 
@@ -197,7 +197,7 @@ class HTTP::CookieJar
197
197
 
198
198
  begin
199
199
  saver = AbstractSaver.implementation(opthash[:format]).new(opthash)
200
- rescue KeyError => e
200
+ rescue IndexError => e
201
201
  raise ArgumentError, e.message
202
202
  end
203
203
 
@@ -6,15 +6,15 @@ class HTTP::CookieJar::AbstractSaver
6
6
 
7
7
  # Gets an implementation class by the name, optionally trying to
8
8
  # load "http/cookie_jar/*_saver" if not found. If loading fails,
9
- # KeyError is raised.
9
+ # IndexError is raised.
10
10
  def implementation(symbol)
11
11
  @@class_map.fetch(symbol)
12
- rescue KeyError
12
+ rescue IndexError
13
13
  begin
14
14
  require 'http/cookie_jar/%s_saver' % symbol
15
15
  @@class_map.fetch(symbol)
16
- rescue LoadError, KeyError => e
17
- raise KeyError, 'cookie saver unavailable: %s' % symbol.inspect
16
+ rescue LoadError, IndexError => e
17
+ raise IndexError, 'cookie saver unavailable: %s' % symbol.inspect
18
18
  end
19
19
  end
20
20
 
@@ -6,15 +6,15 @@ class HTTP::CookieJar::AbstractStore
6
6
 
7
7
  # Gets an implementation class by the name, optionally trying to
8
8
  # load "http/cookie_jar/*_store" if not found. If loading fails,
9
- # KeyError is raised.
9
+ # IndexError is raised.
10
10
  def implementation(symbol)
11
11
  @@class_map.fetch(symbol)
12
- rescue KeyError
12
+ rescue IndexError
13
13
  begin
14
14
  require 'http/cookie_jar/%s_store' % symbol
15
15
  @@class_map.fetch(symbol)
16
- rescue LoadError, KeyError => e
17
- raise KeyError, 'cookie store unavailable: %s' % symbol.inspect
16
+ rescue LoadError, IndexError => e
17
+ raise IndexError, 'cookie store unavailable: %s' % symbol.inspect
18
18
  end
19
19
  end
20
20
 
@@ -5,14 +5,6 @@ class TestHTTPCookieJar < Test::Unit::TestCase
5
5
  @jar = HTTP::CookieJar.new
6
6
  end
7
7
 
8
- def in_tmpdir
9
- Dir.mktmpdir do |dir|
10
- Dir.chdir dir do
11
- yield
12
- end
13
- end
14
- end
15
-
16
8
  def cookie_values(options = {})
17
9
  {
18
10
  :name => 'Foo',
@@ -310,12 +302,12 @@ class TestHTTPCookieJar < Test::Unit::TestCase
310
302
 
311
303
  assert_equal(3, @jar.cookies(url).length)
312
304
 
313
- in_tmpdir do
314
- value = @jar.save("cookies.yml")
305
+ Dir.mktmpdir do |dir|
306
+ value = @jar.save(File.join(dir, "cookies.yml"))
315
307
  assert_same @jar, value
316
308
 
317
309
  jar = HTTP::CookieJar.new
318
- jar.load("cookies.yml")
310
+ jar.load(File.join(dir, "cookies.yml"))
319
311
  cookies = jar.cookies(url).sort_by { |cookie| cookie.name }
320
312
  assert_equal(2, cookies.length)
321
313
  assert_equal('Baz', cookies[0].name)
@@ -342,11 +334,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
342
334
 
343
335
  assert_equal(3, @jar.cookies(url).length)
344
336
 
345
- in_tmpdir do
346
- @jar.save("cookies.yml", :format => :yaml, :session => true)
337
+ Dir.mktmpdir do |dir|
338
+ @jar.save(File.join(dir, "cookies.yml"), :format => :yaml, :session => true)
347
339
 
348
340
  jar = HTTP::CookieJar.new
349
- jar.load("cookies.yml")
341
+ jar.load(File.join(dir, "cookies.yml"))
350
342
  assert_equal(3, jar.cookies(url).length)
351
343
  end
352
344
 
@@ -374,11 +366,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
374
366
 
375
367
  assert_equal(3, @jar.cookies(url).length)
376
368
 
377
- in_tmpdir do
378
- @jar.save("cookies.txt", :cookiestxt)
369
+ Dir.tmpdir do |dir|
370
+ @jar.save(File.join(dir, "cookies.txt"), :cookiestxt)
379
371
 
380
372
  jar = HTTP::CookieJar.new
381
- jar.load("cookies.txt", :cookiestxt) # HACK test the format
373
+ jar.load(File.join(dir, "cookies.txt"), :cookiestxt) # HACK test the format
382
374
  cookies = jar.cookies(url)
383
375
  assert_equal(2, cookies.length)
384
376
  cookies.each { |cookie|
@@ -533,7 +525,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
533
525
  :domain => uri.host,
534
526
  :for_domain => true,
535
527
  :path => '/dir%d/' % (i / 2),
536
- :origin => uri,
528
+ :origin => uri
537
529
  )).tap { |cookie|
538
530
  cookie.created_at = i == 42 ? date - i : date
539
531
  }
@@ -543,8 +535,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
543
535
  count = jar.to_a.size
544
536
  assert_equal limit_per_domain, count
545
537
  assert_equal [*1..41] + [*43..(limit_per_domain + 1)], jar.map { |cookie|
546
- cookie.name[/(?<=^Foo)(\d+)$/].to_i
547
- }
538
+ cookie.name[/(\d+)$/].to_i
539
+ }.sort
548
540
 
549
541
  hlimit = HTTP::Cookie::MAX_COOKIES_TOTAL
550
542
  slimit = hlimit + HTTP::CookieJar::HashStore::GC_THRESHOLD
@@ -560,7 +552,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
560
552
  :domain => uri.host,
561
553
  :for_domain => true,
562
554
  :path => '/dir%d/' % (i / 2),
563
- :origin => uri,
555
+ :origin => uri
564
556
  )).tap { |cookie|
565
557
  cookie.created_at = i == j ? date - i : date
566
558
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-cookie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: