mechanize 0.4.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

Files changed (48) hide show
  1. data/CHANGELOG +17 -0
  2. data/EXAMPLES +23 -44
  3. data/NOTES +49 -0
  4. data/lib/mechanize.rb +95 -80
  5. data/lib/mechanize/cookie.rb +147 -148
  6. data/lib/mechanize/cookie.rb.rej +16 -0
  7. data/lib/mechanize/errors.rb +29 -0
  8. data/lib/mechanize/form.rb +211 -186
  9. data/lib/mechanize/form_elements.rb +31 -71
  10. data/lib/mechanize/list.rb +34 -0
  11. data/lib/mechanize/mech_version.rb +3 -1
  12. data/lib/mechanize/module.rb +1 -1
  13. data/lib/mechanize/page.rb +162 -180
  14. data/lib/mechanize/page_elements.rb +53 -40
  15. data/lib/mechanize/parsing.rb +11 -3
  16. data/lib/mechanize/pluggable_parsers.rb +147 -0
  17. data/test/data/server.crt +14 -0
  18. data/test/data/server.csr +11 -0
  19. data/test/data/server.key +18 -0
  20. data/test/data/server.pem +15 -0
  21. data/test/htdocs/no_title_test.html +6 -0
  22. data/test/parse.rb +39 -0
  23. data/test/proxy.rb +30 -0
  24. data/test/server.rb +2 -0
  25. data/test/servlets.rb +8 -0
  26. data/test/ssl_server.rb +49 -0
  27. data/test/tc_authenticate.rb +8 -6
  28. data/test/tc_cookie_class.rb +28 -18
  29. data/test/tc_cookie_jar.rb +88 -27
  30. data/test/tc_cookies.rb +41 -44
  31. data/test/tc_errors.rb +9 -23
  32. data/test/tc_forms.rb +36 -32
  33. data/test/tc_frames.rb +6 -4
  34. data/test/tc_links.rb +7 -6
  35. data/test/tc_mech.rb +43 -46
  36. data/test/tc_page.rb +24 -0
  37. data/test/tc_pluggable_parser.rb +103 -0
  38. data/test/tc_post_form.rb +41 -0
  39. data/test/tc_proxy.rb +25 -0
  40. data/test/tc_response_code.rb +13 -10
  41. data/test/tc_save_file.rb +25 -0
  42. data/test/tc_ssl_server.rb +27 -0
  43. data/test/tc_upload.rb +8 -6
  44. data/test/tc_watches.rb +5 -2
  45. data/test/test_includes.rb +3 -3
  46. data/test/ts_mech.rb +11 -2
  47. metadata +100 -86
  48. data/test/tc_filter.rb +0 -34
data/test/servlets.rb CHANGED
@@ -9,6 +9,14 @@ class BadContentTypeTest < WEBrick::HTTPServlet::AbstractServlet
9
9
  end
10
10
  end
11
11
 
12
+ class ContentTypeTest < WEBrick::HTTPServlet::AbstractServlet
13
+ def do_GET(req, res)
14
+ ct = req.query['ct'] || "text/html; charset=utf-8"
15
+ res['Content-Type'] = ct
16
+ res.body = "Hello World"
17
+ end
18
+ end
19
+
12
20
  class FileUploadTest < WEBrick::HTTPServlet::AbstractServlet
13
21
  def do_POST(req, res)
14
22
  res.body = req.body
@@ -0,0 +1,49 @@
1
+ require 'webrick'
2
+ require 'webrick/https'
3
+ require 'servlets'
4
+ require 'logger'
5
+
6
+ base_dir = FileTest.exists?(Dir::pwd + '/test') ? Dir::pwd + '/test' : Dir::pwd
7
+
8
+ s = WEBrick::HTTPServer.new(
9
+ :Port => 2002,
10
+ :DocumentRoot => base_dir + "/htdocs",
11
+ :SSLEnable => true,
12
+ :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
13
+ :SSLCertificate => OpenSSL::X509::Certificate.new(
14
+ File.read("data/server.crt")
15
+ ),
16
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(
17
+ File.read("data/server.pem")
18
+ ),
19
+ :Logger => Logger.new(nil),
20
+ :AccessLog => Logger.new(nil)
21
+ )
22
+ s.mount("/one_cookie", OneCookieTest)
23
+ s.mount("/one_cookie_no_space", OneCookieNoSpacesTest)
24
+ s.mount("/many_cookies", ManyCookiesTest)
25
+ s.mount("/many_cookies_as_string", ManyCookiesAsStringTest)
26
+ s.mount("/send_cookies", SendCookiesTest)
27
+ s.mount("/form_post", FormTest)
28
+ s.mount("/form post", FormTest)
29
+ s.mount("/response_code", ResponseCodeTest)
30
+ s.mount("/file_upload", FileUploadTest)
31
+ s.mount("/bad_content_type", BadContentTypeTest)
32
+ s.mount("/content_type_test", ContentTypeTest)
33
+
34
+ htpasswd = WEBrick::HTTPAuth::Htpasswd.new(base_dir + '/data/htpasswd')
35
+ auth = WEBrick::HTTPAuth::BasicAuth.new(
36
+ :UserDB => htpasswd,
37
+ :Realm => 'mechanize',
38
+ :Logger => Logger.new(nil),
39
+ :AccessLog => Logger.new(nil)
40
+ )
41
+ s.mount_proc('/htpasswd_auth') { |req, res|
42
+ auth.authenticate(req, res)
43
+ res.body = "You are authenticated"
44
+ }
45
+
46
+ trap("INT") { s.stop }
47
+
48
+ s.start
49
+
@@ -8,18 +8,20 @@ require 'test_includes'
8
8
  class BasicAuthTest < Test::Unit::TestCase
9
9
  include TestMethods
10
10
 
11
+ def setup
12
+ @agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
13
+ end
14
+
11
15
  def test_auth_success
12
- agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
13
- agent.basic_auth('mech', 'password')
14
- page = agent.get("http://localhost:#{@port}/htpasswd_auth")
16
+ @agent.basic_auth('mech', 'password')
17
+ page = @agent.get("http://localhost:#{PORT}/htpasswd_auth")
15
18
  assert_equal('You are authenticated', page.body)
16
19
  end
17
20
 
18
21
  def test_auth_failure
19
- agent = WWW::Mechanize.new { |a| a.log = Logger.new(nil) }
20
22
  begin
21
- page = agent.get("http://localhost:#{@port}/htpasswd_auth")
22
- rescue WWW::ResponseCodeError => e
23
+ page = @agent.get("http://localhost:#{PORT}/htpasswd_auth")
24
+ rescue WWW::Mechanize::ResponseCodeError => e
23
25
  assert_equal("401", e.response_code)
24
26
  end
25
27
  end
@@ -26,7 +26,7 @@ class CookieClassTest < Test::Unit::TestCase
26
26
  def test_parse_dates
27
27
  url = URI.parse('http://localhost/')
28
28
 
29
- yesterday = DateTime.now - 1
29
+ yesterday = Time.now - 86400
30
30
 
31
31
  dates = [ "14 Apr 89 03:20:12",
32
32
  "14 Apr 89 03:20 GMT",
@@ -41,18 +41,33 @@ class CookieClassTest < Test::Unit::TestCase
41
41
  "22-AUG-1993 12:59 PM",
42
42
  #"Friday, August 04, 1995 3:54 PM",
43
43
  "06/21/95 04:24:34 PM",
44
- "20/06/95 21:07",
44
+ #"20/06/95 21:07",
45
45
  "95-06-08 19:32:48 EDT",
46
46
  ]
47
47
 
48
48
  dates.each do |date|
49
49
  cookie = "PREF=1; expires=#{date}"
50
- WWW::Cookie.parse(url, cookie) { |cookie|
50
+ WWW::Mechanize::Cookie.parse(url, cookie) { |cookie|
51
51
  assert_equal(true, cookie.expires < yesterday)
52
52
  }
53
53
  end
54
54
  end
55
55
 
56
+ def test_parse_date_fail
57
+ url = URI.parse('http://localhost/')
58
+
59
+ dates = [
60
+ "20/06/95 21:07",
61
+ ]
62
+
63
+ dates.each do |date|
64
+ cookie = "PREF=1; expires=#{date}"
65
+ WWW::Mechanize::Cookie.parse(url, cookie) { |cookie|
66
+ assert_equal(true, cookie.expires > (Time.now - 86400))
67
+ }
68
+ end
69
+ end
70
+
56
71
  def test_parse_valid_cookie
57
72
  url = URI.parse('http://rubyforge.org/')
58
73
  cookie_params = {}
@@ -62,8 +77,7 @@ class CookieClassTest < Test::Unit::TestCase
62
77
  cookie_params['httponly'] = 'HttpOnly'
63
78
  cookie_value = '12345%7D=ASDFWEE345%3DASda'
64
79
 
65
- expires = DateTime.strptime('Sun, 27-Sep-2037 00:00:00 GMT',
66
- '%a, %d-%b-%Y %T %Z')
80
+ expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
67
81
 
68
82
  cookie_params.keys.combine.each do |c|
69
83
  cookie_text = "#{cookie_value}; "
@@ -75,7 +89,7 @@ class CookieClassTest < Test::Unit::TestCase
75
89
  end
76
90
  end
77
91
  cookie = nil
78
- WWW::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
92
+ WWW::Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
79
93
  assert_not_nil(cookie)
80
94
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
81
95
  assert_equal('/', cookie.path)
@@ -100,8 +114,7 @@ class CookieClassTest < Test::Unit::TestCase
100
114
  cookie_params['httponly'] = 'HttpOnly'
101
115
  cookie_value = '12345%7D=ASDFWEE345%3DASda'
102
116
 
103
- expires = DateTime.strptime('Sun, 27-Sep-2037 00:00:00 GMT',
104
- '%a, %d-%b-%Y %T %Z')
117
+ expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
105
118
 
106
119
  cookie_params.keys.combine.each do |c|
107
120
  next if c.find { |k| k == 'path' }
@@ -114,7 +127,7 @@ class CookieClassTest < Test::Unit::TestCase
114
127
  end
115
128
  end
116
129
  cookie = nil
117
- WWW::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
130
+ WWW::Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
118
131
  assert_not_nil(cookie)
119
132
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
120
133
  assert_equal('rubyforge.org', cookie.domain)
@@ -139,8 +152,7 @@ class CookieClassTest < Test::Unit::TestCase
139
152
  cookie_params['secure'] = 'secure'
140
153
  cookie_value = '12345%7D=ASDFWEE345%3DASda'
141
154
 
142
- expires = DateTime.strptime('Sun, 27-Sep-2037 00:00:00 GMT',
143
- '%a, %d-%b-%Y %T %Z')
155
+ expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
144
156
 
145
157
  cookie_params.keys.combine.each do |c|
146
158
  next unless c.find { |k| k == 'secure' }
@@ -153,7 +165,7 @@ class CookieClassTest < Test::Unit::TestCase
153
165
  end
154
166
  end
155
167
  cookie = nil
156
- WWW::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
168
+ WWW::Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
157
169
  assert_not_nil(cookie)
158
170
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
159
171
  assert_equal('rubyforge.org', cookie.domain)
@@ -179,8 +191,7 @@ class CookieClassTest < Test::Unit::TestCase
179
191
  cookie_params['httponly'] = 'HttpOnly'
180
192
  cookie_value = '12345%7D=ASDFWEE345%3DASda'
181
193
 
182
- expires = DateTime.strptime('Sun, 27-Sep-2037 00:00:00 GMT',
183
- '%a, %d-%b-%Y %T %Z')
194
+ expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
184
195
 
185
196
  cookie_params.keys.combine.each do |c|
186
197
  next if c.find { |k| k == 'domain' }
@@ -193,7 +204,7 @@ class CookieClassTest < Test::Unit::TestCase
193
204
  end
194
205
  end
195
206
  cookie = nil
196
- WWW::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
207
+ WWW::Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
197
208
  assert_not_nil(cookie)
198
209
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
199
210
  assert_equal('/', cookie.path)
@@ -218,8 +229,7 @@ class CookieClassTest < Test::Unit::TestCase
218
229
  cookie_params['httponly'] = 'HttpOnly'
219
230
  cookie_value = '12345%7D=ASDFWEE345%3DASda'
220
231
 
221
- expires = DateTime.strptime('Sun, 27-Sep-2037 00:00:00 GMT',
222
- '%a, %d-%b-%Y %T %Z')
232
+ expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
223
233
 
224
234
  cookie_params.keys.combine.each do |c|
225
235
  cookie_text = "#{cookie_value};"
@@ -231,7 +241,7 @@ class CookieClassTest < Test::Unit::TestCase
231
241
  end
232
242
  end
233
243
  cookie = nil
234
- WWW::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
244
+ WWW::Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
235
245
  assert_not_nil(cookie)
236
246
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
237
247
  assert_equal('/', cookie.path)
@@ -4,27 +4,28 @@ require 'test/unit'
4
4
  require 'mechanize/cookie'
5
5
  require 'uri'
6
6
  require 'test_includes'
7
+ require 'fileutils'
7
8
 
8
9
  class CookieJarTest < Test::Unit::TestCase
9
10
  def test_add_future_cookies
10
11
  values = { :name => 'Foo',
11
12
  :value => 'Bar',
12
13
  :path => '/',
13
- :expires => DateTime.now + 10,
14
+ :expires => Time.now + (10 * 86400),
14
15
  :domain => 'rubyforge.org'
15
16
  }
16
17
  url = URI.parse('http://rubyforge.org/')
17
18
 
18
- jar = WWW::CookieJar.new
19
+ jar = WWW::Mechanize::CookieJar.new
19
20
  assert_equal(0, jar.cookies(url).length)
20
21
 
21
22
  # Add one cookie with an expiration date in the future
22
- cookie = WWW::Cookie.new(values)
23
+ cookie = WWW::Mechanize::Cookie.new(values)
23
24
  jar.add(cookie)
24
25
  assert_equal(1, jar.cookies(url).length)
25
26
 
26
27
  # Add the same cookie, and we should still only have one
27
- jar.add(WWW::Cookie.new(values))
28
+ jar.add(WWW::Mechanize::Cookie.new(values))
28
29
  assert_equal(1, jar.cookies(url).length)
29
30
 
30
31
  # Make sure we can get the cookie from different paths
@@ -38,21 +39,21 @@ class CookieJarTest < Test::Unit::TestCase
38
39
  values = { :name => 'Foo',
39
40
  :value => 'Bar',
40
41
  :path => '/',
41
- :expires => DateTime.now + 10,
42
+ :expires => Time.now + (10 * 86400),
42
43
  :domain => 'rubyforge.org'
43
44
  }
44
45
  url = URI.parse('http://rubyforge.org/')
45
46
 
46
- jar = WWW::CookieJar.new
47
+ jar = WWW::Mechanize::CookieJar.new
47
48
  assert_equal(0, jar.cookies(url).length)
48
49
 
49
50
  # Add one cookie with an expiration date in the future
50
- cookie = WWW::Cookie.new(values)
51
+ cookie = WWW::Mechanize::Cookie.new(values)
51
52
  jar.add(cookie)
52
53
  assert_equal(1, jar.cookies(url).length)
53
54
 
54
55
  # Add the same cookie, and we should still only have one
55
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz' )))
56
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
56
57
  assert_equal(2, jar.cookies(url).length)
57
58
 
58
59
  # Make sure we can get the cookie from different paths
@@ -62,37 +63,87 @@ class CookieJarTest < Test::Unit::TestCase
62
63
  assert_equal(0, jar.cookies(URI.parse('http://google.com/')).length)
63
64
  end
64
65
 
66
+ def test_clear_cookies
67
+ values = { :name => 'Foo',
68
+ :value => 'Bar',
69
+ :path => '/',
70
+ :expires => Time.now + (10 * 86400),
71
+ :domain => 'rubyforge.org'
72
+ }
73
+ url = URI.parse('http://rubyforge.org/')
74
+
75
+ jar = WWW::Mechanize::CookieJar.new
76
+ assert_equal(0, jar.cookies(url).length)
77
+
78
+ # Add one cookie with an expiration date in the future
79
+ cookie = WWW::Mechanize::Cookie.new(values)
80
+ jar.add(cookie)
81
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
82
+ assert_equal(2, jar.cookies(url).length)
83
+
84
+ jar.clear!
85
+
86
+ assert_equal(0, jar.cookies(url).length)
87
+ end
88
+
89
+ def test_save_cookies
90
+ values = { :name => 'Foo',
91
+ :value => 'Bar',
92
+ :path => '/',
93
+ :expires => Time.now + (10 * 86400),
94
+ :domain => 'rubyforge.org'
95
+ }
96
+ url = URI.parse('http://rubyforge.org/')
97
+
98
+ jar = WWW::Mechanize::CookieJar.new
99
+ assert_equal(0, jar.cookies(url).length)
100
+
101
+ # Add one cookie with an expiration date in the future
102
+ cookie = WWW::Mechanize::Cookie.new(values)
103
+ jar.add(cookie)
104
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
105
+ assert_equal(2, jar.cookies(url).length)
106
+
107
+ jar.save_as("cookies.yml")
108
+ jar.clear!
109
+ assert_equal(0, jar.cookies(url).length)
110
+
111
+ jar.load("cookies.yml")
112
+ assert_equal(2, jar.cookies(url).length)
113
+ FileUtils.rm("cookies.yml")
114
+ end
115
+
65
116
  def test_expire_cookies
66
117
  values = { :name => 'Foo',
67
118
  :value => 'Bar',
68
119
  :path => '/',
69
- :expires => DateTime.now + 10,
120
+ :expires => Time.now + (10 * 86400),
70
121
  :domain => 'rubyforge.org'
71
122
  }
72
123
  url = URI.parse('http://rubyforge.org/')
73
124
 
74
- jar = WWW::CookieJar.new
125
+ jar = WWW::Mechanize::CookieJar.new
75
126
  assert_equal(0, jar.cookies(url).length)
76
127
 
77
128
  # Add one cookie with an expiration date in the future
78
- cookie = WWW::Cookie.new(values)
129
+ cookie = WWW::Mechanize::Cookie.new(values)
79
130
  jar.add(cookie)
80
131
  assert_equal(1, jar.cookies(url).length)
81
132
 
82
133
  # Add a second cookie
83
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz' )))
134
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
84
135
  assert_equal(2, jar.cookies(url).length)
85
136
 
86
137
  # Make sure we can get the cookie from different paths
87
138
  assert_equal(2, jar.cookies(URI.parse('http://rubyforge.org/login')).length)
88
139
 
89
140
  # Expire the first cookie
90
- jar.add(WWW::Cookie.new(values.merge( :expires => DateTime.now - 10)))
141
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
91
142
  assert_equal(1, jar.cookies(url).length)
92
143
 
93
144
  # Expire the second cookie
94
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz',
95
- :expires => DateTime.now - 10)))
145
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz',
146
+ :expires => Time.now - (10 * 86400))))
96
147
  assert_equal(0, jar.cookies(url).length)
97
148
  end
98
149
 
@@ -105,29 +156,39 @@ class CookieJarTest < Test::Unit::TestCase
105
156
  }
106
157
  url = URI.parse('http://rubyforge.org/')
107
158
 
108
- jar = WWW::CookieJar.new
159
+ jar = WWW::Mechanize::CookieJar.new
109
160
  assert_equal(0, jar.cookies(url).length)
110
161
 
111
162
  # Add one cookie with an expiration date in the future
112
- cookie = WWW::Cookie.new(values)
163
+ cookie = WWW::Mechanize::Cookie.new(values)
113
164
  jar.add(cookie)
114
165
  assert_equal(1, jar.cookies(url).length)
115
166
 
116
167
  # Add a second cookie
117
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz' )))
168
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
118
169
  assert_equal(2, jar.cookies(url).length)
119
170
 
120
171
  # Make sure we can get the cookie from different paths
121
172
  assert_equal(2, jar.cookies(URI.parse('http://rubyforge.org/login')).length)
122
173
 
123
174
  # Expire the first cookie
124
- jar.add(WWW::Cookie.new(values.merge( :expires => DateTime.now - 10)))
175
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
125
176
  assert_equal(1, jar.cookies(url).length)
126
177
 
127
178
  # Expire the second cookie
128
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz',
129
- :expires => DateTime.now - 10)))
179
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz',
180
+ :expires => Time.now - (10 * 86400))))
130
181
  assert_equal(0, jar.cookies(url).length)
182
+
183
+ # When given a URI with a blank path, CookieJar#cookies should return
184
+ # cookies with the path '/':
185
+ url = URI.parse('http://rubyforge.org')
186
+ assert_equal '', url.path
187
+ assert_equal(0, jar.cookies(url).length)
188
+ # Now add a cookie with the path set to '/':
189
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'has_root_path',
190
+ :path => '/')))
191
+ assert_equal(1, jar.cookies(url).length)
131
192
  end
132
193
 
133
194
  def test_paths
@@ -139,16 +200,16 @@ class CookieJarTest < Test::Unit::TestCase
139
200
  }
140
201
  url = URI.parse('http://rubyforge.org/login')
141
202
 
142
- jar = WWW::CookieJar.new
203
+ jar = WWW::Mechanize::CookieJar.new
143
204
  assert_equal(0, jar.cookies(url).length)
144
205
 
145
206
  # Add one cookie with an expiration date in the future
146
- cookie = WWW::Cookie.new(values)
207
+ cookie = WWW::Mechanize::Cookie.new(values)
147
208
  jar.add(cookie)
148
209
  assert_equal(1, jar.cookies(url).length)
149
210
 
150
211
  # Add a second cookie
151
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz' )))
212
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz' )))
152
213
  assert_equal(2, jar.cookies(url).length)
153
214
 
154
215
  # Make sure we don't get the cookie in a different path
@@ -156,12 +217,12 @@ class CookieJarTest < Test::Unit::TestCase
156
217
  assert_equal(0, jar.cookies(URI.parse('http://rubyforge.org/')).length)
157
218
 
158
219
  # Expire the first cookie
159
- jar.add(WWW::Cookie.new(values.merge( :expires => DateTime.now - 10)))
220
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
160
221
  assert_equal(1, jar.cookies(url).length)
161
222
 
162
223
  # Expire the second cookie
163
- jar.add(WWW::Cookie.new(values.merge( :name => 'Baz',
164
- :expires => DateTime.now - 10)))
224
+ jar.add(WWW::Mechanize::Cookie.new(values.merge( :name => 'Baz',
225
+ :expires => Time.now - (10 * 86400))))
165
226
  assert_equal(0, jar.cookies(url).length)
166
227
  end
167
228
  end