mechanize 1.0.0 → 1.0.1.beta.20110107104205
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.
- data/CHANGELOG.rdoc +19 -0
- data/EXAMPLES.rdoc +13 -13
- data/Manifest.txt +0 -1
- data/Rakefile +4 -9
- data/lib/mechanize/chain/body_decoding_handler.rb +2 -0
- data/lib/mechanize/chain/connection_resolver.rb +6 -55
- data/lib/mechanize/chain/header_resolver.rb +3 -12
- data/lib/mechanize/chain/parameter_resolver.rb +2 -2
- data/lib/mechanize/chain/request_resolver.rb +1 -0
- data/lib/mechanize/chain/response_body_parser.rb +4 -6
- data/lib/mechanize/chain/response_header_handler.rb +1 -15
- data/lib/mechanize/chain/uri_resolver.rb +2 -2
- data/lib/mechanize/chain.rb +4 -1
- data/lib/mechanize/cookie.rb +1 -1
- data/lib/mechanize/file.rb +7 -0
- data/lib/mechanize/form/field.rb +6 -0
- data/lib/mechanize/form.rb +16 -4
- data/lib/mechanize/headers.rb +14 -0
- data/lib/mechanize/page/link.rb +7 -1
- data/lib/mechanize/page/meta.rb +3 -5
- data/lib/mechanize/page.rb +17 -4
- data/lib/mechanize/util.rb +8 -4
- data/lib/mechanize.rb +82 -56
- data/test/chain/test_header_resolver.rb +0 -2
- data/test/chain/test_parameter_resolver.rb +1 -1
- data/test/helper.rb +20 -13
- data/test/htdocs/form_multival.html +2 -2
- data/test/htdocs/form_test.html +2 -2
- data/test/htdocs/tc_links.html +1 -1
- data/test/htdocs/tc_referer.html +2 -0
- data/test/servlets.rb +41 -5
- data/test/test_authenticate.rb +3 -3
- data/test/test_cookies.rb +10 -4
- data/test/test_errors.rb +1 -1
- data/test/test_field_precedence.rb +4 -1
- data/test/test_follow_meta.rb +3 -3
- data/test/test_form_button.rb +8 -0
- data/test/test_forms.rb +63 -42
- data/test/test_gzipping.rb +1 -1
- data/test/test_headers.rb +33 -0
- data/test/test_history.rb +2 -2
- data/test/test_history_added.rb +1 -1
- data/test/test_links.rb +9 -0
- data/test/test_mech.rb +22 -7
- data/test/test_mech_proxy.rb +4 -4
- data/test/test_meta.rb +5 -3
- data/test/test_no_attributes.rb +1 -1
- data/test/test_referer.rb +21 -3
- data/test/test_relative_links.rb +4 -4
- data/test/test_response_code.rb +1 -1
- data/test/test_scheme.rb +7 -0
- metadata +61 -18
- data/test/test_keep_alive.rb +0 -31
data/test/test_forms.rb
CHANGED
@@ -5,6 +5,12 @@ class FormsMechTest < Test::Unit::TestCase
|
|
5
5
|
@agent = Mechanize.new
|
6
6
|
end
|
7
7
|
|
8
|
+
def test_post_with_rails_3_encoding_hack
|
9
|
+
page = @agent.get("http://localhost/rails_3_encoding_hack_form_test.html")
|
10
|
+
form = page.forms.first
|
11
|
+
form.submit
|
12
|
+
end
|
13
|
+
|
8
14
|
def test_post_with_blank_encoding
|
9
15
|
page = @agent.get("http://localhost/form_test.html")
|
10
16
|
form = page.form('post_form1')
|
@@ -143,8 +149,8 @@ class FormsMechTest < Test::Unit::TestCase
|
|
143
149
|
|
144
150
|
# Now set all the fields
|
145
151
|
post_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
|
146
|
-
post_form.radiobuttons.find { |f|
|
147
|
-
f.name == "gender" && f.value == "male"
|
152
|
+
post_form.radiobuttons.find { |f|
|
153
|
+
f.name == "gender" && f.value == "male"
|
148
154
|
}.checked = true
|
149
155
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
150
156
|
post_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
|
@@ -180,12 +186,12 @@ class FormsMechTest < Test::Unit::TestCase
|
|
180
186
|
assert_not_nil(post_form, "Post form is null")
|
181
187
|
assert_equal("post", post_form.method.downcase)
|
182
188
|
assert_equal("/form_post", post_form.action)
|
183
|
-
|
189
|
+
|
184
190
|
assert_equal(1, post_form.fields.size)
|
185
191
|
assert_equal(1, post_form.buttons.size)
|
186
|
-
|
192
|
+
|
187
193
|
page = @agent.submit(post_form, post_form.buttons.first)
|
188
|
-
|
194
|
+
|
189
195
|
assert_not_nil(page)
|
190
196
|
end
|
191
197
|
|
@@ -257,8 +263,8 @@ class FormsMechTest < Test::Unit::TestCase
|
|
257
263
|
img.y = "10"
|
258
264
|
# Now set all the fields
|
259
265
|
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
|
260
|
-
get_form.radiobuttons.find { |f|
|
261
|
-
f.name == "gender" && f.value == "male"
|
266
|
+
get_form.radiobuttons.find { |f|
|
267
|
+
f.name == "gender" && f.value == "male"
|
262
268
|
}.checked = true
|
263
269
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
264
270
|
get_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
|
@@ -326,8 +332,8 @@ class FormsMechTest < Test::Unit::TestCase
|
|
326
332
|
|
327
333
|
# Now set all the fields
|
328
334
|
post_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
|
329
|
-
post_form.radiobuttons.find { |f|
|
330
|
-
f.name == "gender" && f.value == "male"
|
335
|
+
post_form.radiobuttons.find { |f|
|
336
|
+
f.name == "gender" && f.value == "male"
|
331
337
|
}.checked = true
|
332
338
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
333
339
|
page = @agent.submit(post_form, post_form.buttons.first)
|
@@ -378,8 +384,8 @@ class FormsMechTest < Test::Unit::TestCase
|
|
378
384
|
|
379
385
|
# Now set all the fields
|
380
386
|
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
|
381
|
-
get_form.radiobuttons.find { |f|
|
382
|
-
f.name == "gender" && f.value == "male"
|
387
|
+
get_form.radiobuttons.find { |f|
|
388
|
+
f.name == "gender" && f.value == "male"
|
383
389
|
}.checked = true
|
384
390
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
385
391
|
page = @agent.submit(get_form, get_form.buttons.first)
|
@@ -410,46 +416,45 @@ class FormsMechTest < Test::Unit::TestCase
|
|
410
416
|
assert_equal(1, post_form.buttons.size)
|
411
417
|
assert_equal(2, post_form.radiobuttons.size)
|
412
418
|
assert_equal(2, post_form.checkboxes.size)
|
419
|
+
|
413
420
|
assert_not_nil(post_form.fields.find { |f| f.name == "first_name" },
|
414
|
-
|
415
|
-
)
|
416
|
-
assert_not_nil(
|
417
|
-
post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
|
418
|
-
"Gender male button was nil"
|
419
|
-
)
|
421
|
+
"First name field was nil")
|
420
422
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
)
|
423
|
+
male_button = post_form.radiobuttons.find { |f|
|
424
|
+
f.name == "gender" && f.value == "male"
|
425
|
+
}
|
426
|
+
assert_not_nil(male_button, "Gender male button was nil")
|
427
|
+
|
428
|
+
female_button = post_form.radiobuttons.find { |f|
|
429
|
+
f.name == "gender" && f.value == "female"
|
430
|
+
}
|
431
|
+
|
432
|
+
assert_not_nil(female_button, "Gender female button was nil")
|
425
433
|
|
426
434
|
assert_not_nil(post_form.checkbox_with(:name => "cool person"),
|
427
|
-
|
435
|
+
"couldn't find cool person checkbox")
|
436
|
+
|
428
437
|
assert_not_nil(post_form.checkboxes.find { |f| f.name == "likes ham" },
|
429
|
-
|
438
|
+
"couldn't find likes ham checkbox")
|
430
439
|
|
431
440
|
# Now set all the fields
|
432
441
|
post_form.field_with(:name => 'first_name').value = "Aaron"
|
433
|
-
post_form.radiobuttons.find { |f|
|
434
|
-
f.name == "gender" && f.value == "male"
|
442
|
+
post_form.radiobuttons.find { |f|
|
443
|
+
f.name == "gender" && f.value == "male"
|
435
444
|
}.checked = true
|
436
445
|
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
446
|
+
|
437
447
|
page = @agent.submit(post_form, post_form.buttons.first)
|
438
448
|
|
439
449
|
# Check that the submitted fields exist
|
440
450
|
assert_equal(3, page.links.size, "Not enough links")
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
)
|
449
|
-
assert_not_nil(
|
450
|
-
page.links.find { |l| l.text == "gender:male" },
|
451
|
-
"gender field missing"
|
452
|
-
)
|
451
|
+
|
452
|
+
assert_not_nil(page.links.find { |l| l.text == "likes ham:on" },
|
453
|
+
"likes ham check box missing")
|
454
|
+
assert_not_nil(page.links.find { |l| l.text == "first_name:Aaron" },
|
455
|
+
"first_name field missing")
|
456
|
+
assert_not_nil(page.links.find { |l| l.text == "gender:male" },
|
457
|
+
"gender field missing")
|
453
458
|
end
|
454
459
|
|
455
460
|
def test_get_with_param_in_action
|
@@ -482,8 +487,8 @@ class FormsMechTest < Test::Unit::TestCase
|
|
482
487
|
|
483
488
|
# Now set all the fields
|
484
489
|
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
|
485
|
-
get_form.radiobuttons.find { |f|
|
486
|
-
f.name == "gender" && f.value == "male"
|
490
|
+
get_form.radiobuttons.find { |f|
|
491
|
+
f.name == "gender" && f.value == "male"
|
487
492
|
}.checked = true
|
488
493
|
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
|
489
494
|
page = @agent.submit(get_form, get_form.buttons.first)
|
@@ -507,7 +512,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
507
512
|
page = @agent.get("http://localhost/form_test.html")
|
508
513
|
get_form = page.forms.find { |f| f.name == "get_form1" }
|
509
514
|
get_form.field("first_name").value = "Gregory"
|
510
|
-
assert_equal( "Gregory", get_form.field("first_name").value )
|
515
|
+
assert_equal( "Gregory", get_form.field("first_name").value )
|
511
516
|
end
|
512
517
|
|
513
518
|
def test_fields_as_accessors
|
@@ -521,6 +526,22 @@ class FormsMechTest < Test::Unit::TestCase
|
|
521
526
|
assert_equal('Aaron', form.first)
|
522
527
|
end
|
523
528
|
|
529
|
+
def test_form_and_fields_dom_id
|
530
|
+
# blatant copypasta of test above
|
531
|
+
page = @agent.get("http://localhost/form_test.html")
|
532
|
+
form = page.form_with(:dom_id => 'generic_form')
|
533
|
+
form_by_id = page.form_with(:id => 'generic_form')
|
534
|
+
|
535
|
+
|
536
|
+
assert_not_nil(form)
|
537
|
+
assert_equal(1, form.fields_with(:dom_id => 'name_first').length)
|
538
|
+
assert_equal('first_name', form.field_with(:dom_id => 'name_first').name)
|
539
|
+
|
540
|
+
# *_with(:id => blah) should work exactly like (:dom_id => blah)
|
541
|
+
assert_equal(form, form_by_id)
|
542
|
+
assert_equal(form.fields_with(:dom_id => 'name_first'), form.fields_with(:id => 'name_first'))
|
543
|
+
end
|
544
|
+
|
524
545
|
def test_add_field
|
525
546
|
page = @agent.get("http://localhost/form_multival.html")
|
526
547
|
form = page.form_with(:name => 'post_form')
|
@@ -532,7 +553,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
532
553
|
assert_not_nil(f)
|
533
554
|
assert_equal(number_of_fields + 1, form.fields.length)
|
534
555
|
end
|
535
|
-
|
556
|
+
|
536
557
|
def test_delete_field
|
537
558
|
page = @agent.get("http://localhost/form_multival.html")
|
538
559
|
form = page.form_with(:name => 'post_form')
|
@@ -543,7 +564,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
543
564
|
|
544
565
|
form.delete_field!('first')
|
545
566
|
assert_nil(form['first'])
|
546
|
-
assert_equal(number_of_fields - 2, form.fields.length)
|
567
|
+
assert_equal(number_of_fields - 2, form.fields.length)
|
547
568
|
end
|
548
569
|
|
549
570
|
def test_has_field
|
data/test/test_gzipping.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestHeaders < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@headers = Mechanize::Headers.new
|
6
|
+
@headers['content-type'] = 'text/html'
|
7
|
+
@headers['Content-encoding'] = 'gzip'
|
8
|
+
@headers['SERVER'] = 'Apache/2.2'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_aref
|
12
|
+
assert_equal('Apache/2.2', @headers['server'])
|
13
|
+
assert_equal('text/html', @headers['Content-Type'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_key?
|
17
|
+
assert_equal(true, @headers.key?('content-Encoding'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_canonical_each
|
21
|
+
all_keys = ['Content-Type', 'Content-Encoding', 'Server']
|
22
|
+
keys = all_keys.dup
|
23
|
+
@headers.canonical_each { |key, value|
|
24
|
+
case keys.delete(key)
|
25
|
+
when *all_keys
|
26
|
+
# ok
|
27
|
+
else
|
28
|
+
raise "unexpected key: #{key}"
|
29
|
+
end
|
30
|
+
}
|
31
|
+
assert_equal([], keys)
|
32
|
+
end
|
33
|
+
end
|
data/test/test_history.rb
CHANGED
@@ -107,7 +107,7 @@ class TestHistory < Test::Unit::TestCase
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def test_no_slash
|
110
|
-
|
110
|
+
@agent.get('http://localhost')
|
111
111
|
|
112
112
|
node = Struct.new(:href, :inner_text).new('http://localhost/', 'blah')
|
113
113
|
link = Mechanize::Page::Link.new(node, nil, nil)
|
@@ -119,7 +119,7 @@ class TestHistory < Test::Unit::TestCase
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def test_with_slash
|
122
|
-
|
122
|
+
@agent.get('http://localhost/')
|
123
123
|
|
124
124
|
node = Struct.new(:href, :inner_text).new('http://localhost/', 'blah')
|
125
125
|
link = Mechanize::Page::Link.new(node, nil, nil)
|
data/test/test_history_added.rb
CHANGED
@@ -10,7 +10,7 @@ class HistoryAddedTest < Test::Unit::TestCase
|
|
10
10
|
@agent.history_added = lambda { |page|
|
11
11
|
onload += 1
|
12
12
|
}
|
13
|
-
|
13
|
+
@agent.get('http://localhost/tc_blank_form.html')
|
14
14
|
assert_equal(1, onload)
|
15
15
|
end
|
16
16
|
end
|
data/test/test_links.rb
CHANGED
@@ -125,4 +125,13 @@ class LinksMechTest < Test::Unit::TestCase
|
|
125
125
|
link = page.link_with(:text => 'unusual characters')
|
126
126
|
assert_nothing_raised { @agent.click link }
|
127
127
|
end
|
128
|
+
|
129
|
+
def test_links_dom_id
|
130
|
+
page = @agent.get("http://localhost/tc_links.html")
|
131
|
+
link = page.links_with(:dom_id => 'bold_aaron_link')
|
132
|
+
link_by_id = page.links_with(:id => 'bold_aaron_link')
|
133
|
+
assert_equal(1, link.length)
|
134
|
+
assert_equal('Aaron Patterson', link.first.text)
|
135
|
+
assert_equal(link, link_by_id)
|
136
|
+
end
|
128
137
|
end
|
data/test/test_mech.rb
CHANGED
@@ -111,7 +111,7 @@ class TestMechMethods < Test::Unit::TestCase
|
|
111
111
|
def test_history
|
112
112
|
0.upto(25) do |i|
|
113
113
|
assert_equal(i, @agent.history.size)
|
114
|
-
|
114
|
+
@agent.get("http://localhost/")
|
115
115
|
end
|
116
116
|
page = @agent.get("http://localhost/form_test.html")
|
117
117
|
|
@@ -151,12 +151,12 @@ class TestMechMethods < Test::Unit::TestCase
|
|
151
151
|
@agent.max_history = 10
|
152
152
|
0.upto(10) do |i|
|
153
153
|
assert_equal(i, @agent.history.size)
|
154
|
-
|
154
|
+
@agent.get("http://localhost/")
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
0.upto(10) do |i|
|
158
158
|
assert_equal(10, @agent.history.size)
|
159
|
-
|
159
|
+
@agent.get("http://localhost/")
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -180,9 +180,9 @@ class TestMechMethods < Test::Unit::TestCase
|
|
180
180
|
def test_back_button
|
181
181
|
0.upto(5) do |i|
|
182
182
|
assert_equal(i, @agent.history.size)
|
183
|
-
|
183
|
+
@agent.get("http://localhost/")
|
184
184
|
end
|
185
|
-
|
185
|
+
@agent.get("http://localhost/form_test.html")
|
186
186
|
|
187
187
|
assert_equal("http://localhost/form_test.html",
|
188
188
|
@agent.history.last.uri.to_s)
|
@@ -255,7 +255,7 @@ class TestMechMethods < Test::Unit::TestCase
|
|
255
255
|
end
|
256
256
|
|
257
257
|
def test_transact
|
258
|
-
|
258
|
+
@agent.get("http://localhost/frame_test.html")
|
259
259
|
assert_equal(1, @agent.history.length)
|
260
260
|
@agent.transact { |a|
|
261
261
|
5.times {
|
@@ -265,4 +265,19 @@ class TestMechMethods < Test::Unit::TestCase
|
|
265
265
|
}
|
266
266
|
assert_equal(1, @agent.history.length)
|
267
267
|
end
|
268
|
+
|
269
|
+
def test_click2
|
270
|
+
@agent.get 'http://localhost/test_click.html'
|
271
|
+
@agent.click 'A Button'
|
272
|
+
assert_equal 'http://localhost/frame_test.html?words=nil',
|
273
|
+
@agent.page.uri.to_s
|
274
|
+
@agent.back
|
275
|
+
@agent.click 'A Link'
|
276
|
+
assert_equal 'http://localhost/index.html',
|
277
|
+
@agent.page.uri.to_s
|
278
|
+
@agent.back
|
279
|
+
@agent.click @agent.page.link_with(:text => 'A Link')
|
280
|
+
assert_equal 'http://localhost/index.html',
|
281
|
+
@agent.page.uri.to_s
|
282
|
+
end
|
268
283
|
end
|
data/test/test_mech_proxy.rb
CHANGED
@@ -8,9 +8,9 @@ class TestMechProxy< Test::Unit::TestCase
|
|
8
8
|
def test_set_proxy
|
9
9
|
@agent.set_proxy('www.example.com', 9001, 'joe', 'lol')
|
10
10
|
|
11
|
-
assert_equal(@agent.
|
12
|
-
assert_equal(@agent.
|
13
|
-
assert_equal(@agent.
|
14
|
-
assert_equal(@agent.
|
11
|
+
assert_equal(@agent.http.proxy_uri.host, 'www.example.com')
|
12
|
+
assert_equal(@agent.http.proxy_uri.port, 9001)
|
13
|
+
assert_equal(@agent.http.proxy_uri.user, 'joe')
|
14
|
+
assert_equal(@agent.http.proxy_uri.password, 'lol')
|
15
15
|
end
|
16
16
|
end
|
data/test/test_meta.rb
CHANGED
@@ -48,11 +48,13 @@ class MetaTest < Test::Unit::TestCase
|
|
48
48
|
#
|
49
49
|
|
50
50
|
def test_parse_documentation
|
51
|
-
uri = URI.parse('http://current.com/')
|
51
|
+
uri = URI.parse('http://current.com/here/')
|
52
52
|
|
53
53
|
assert_equal ['5', 'http://example.com/'], Meta.parse("5;url=http://example.com/", uri)
|
54
|
-
assert_equal ['5', 'http://current.com/'], Meta.parse("5;url=", uri)
|
55
|
-
assert_equal ['5', 'http://current.com/'], Meta.parse("5", uri)
|
54
|
+
assert_equal ['5', 'http://current.com/here/test'], Meta.parse("5;url=test", uri)
|
55
|
+
assert_equal ['5', 'http://current.com/test'], Meta.parse("5;url=/test", uri)
|
56
|
+
assert_equal ['5', 'http://current.com/here/'], Meta.parse("5;url=", uri)
|
57
|
+
assert_equal ['5', 'http://current.com/here/'], Meta.parse("5", uri)
|
56
58
|
assert_equal nil, Meta.parse("invalid content", uri)
|
57
59
|
end
|
58
60
|
|
data/test/test_no_attributes.rb
CHANGED
data/test/test_referer.rb
CHANGED
@@ -18,22 +18,40 @@ class RefererTest < Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
def test_fetch_two
|
20
20
|
page1 = @agent.get("http://localhost/tc_referer.html")
|
21
|
-
|
21
|
+
@agent.get("http://localhost/tc_pretty_print.html")
|
22
22
|
page = @agent.click page1.links.first
|
23
23
|
assert_equal("http://localhost/tc_referer.html", page.body)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_fetch_two_first
|
27
27
|
page1 = @agent.get("http://localhost/tc_referer.html")
|
28
|
-
|
28
|
+
@agent.get("http://localhost/tc_pretty_print.html")
|
29
29
|
page = @agent.click page1.links.first
|
30
30
|
assert_equal("http://localhost/tc_referer.html", page.body)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_post_form
|
34
34
|
page1 = @agent.get("http://localhost/tc_referer.html")
|
35
|
-
|
35
|
+
@agent.get("http://localhost/tc_pretty_print.html")
|
36
36
|
page = @agent.submit page1.forms.first
|
37
37
|
assert_equal("http://localhost/tc_referer.html", page.body)
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_http_to_https
|
41
|
+
page = @agent.get("http://localhost/tc_referer.html")
|
42
|
+
page = @agent.click page.links.last
|
43
|
+
assert_equal("http://localhost/tc_referer.html", page.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_https_to_https
|
47
|
+
page = @agent.get("https://localhost/tc_referer.html")
|
48
|
+
page = @agent.click page.links.last
|
49
|
+
assert_equal("https://localhost/tc_referer.html", page.body)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_https_to_http
|
53
|
+
page = @agent.get("https://localhost/tc_referer.html")
|
54
|
+
page = @agent.click page.links[1]
|
55
|
+
assert_equal("", page.body)
|
56
|
+
end
|
39
57
|
end
|
data/test/test_relative_links.rb
CHANGED
@@ -7,7 +7,7 @@ class TestRelativeLinks < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def test_dot_dot_slash
|
9
9
|
@page = @agent.get("http://localhost/relative/tc_relative_links.html")
|
10
|
-
|
10
|
+
@page.links.first.click
|
11
11
|
assert_equal('http://localhost/tc_relative_links.html', @agent.current_page.uri.to_s)
|
12
12
|
end
|
13
13
|
|
@@ -26,15 +26,15 @@ class TestRelativeLinks < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
def test_frame_dot_dot_slash
|
28
28
|
@page = @agent.get("http://localhost/relative/tc_relative_links.html")
|
29
|
-
|
29
|
+
@agent.click(@page.frame_with(:text => 'frame1'))
|
30
30
|
assert_equal('http://localhost/tc_relative_links.html', @agent.current_page.uri.to_s)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_frame_forward_back_forward
|
34
34
|
@page = @agent.get("http://localhost/tc_relative_links.html")
|
35
|
-
|
35
|
+
@agent.click @page.frame_with(:name => 'frame1')
|
36
36
|
assert_equal('http://localhost/relative/tc_relative_links.html', @agent.current_page.uri.to_s)
|
37
|
-
|
37
|
+
@agent.click @page.frame_with(:name => 'frame2')
|
38
38
|
assert_equal('http://localhost/relative/tc_relative_links.html', @agent.current_page.uri.to_s)
|
39
39
|
end
|
40
40
|
end
|
data/test/test_response_code.rb
CHANGED
data/test/test_scheme.rb
CHANGED
@@ -30,6 +30,13 @@ class SchemeTest < Test::Unit::TestCase
|
|
30
30
|
assert_kind_of(Mechanize::Page, page)
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_file_scheme_with_embedded_spaces
|
34
|
+
f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs/dir with spaces/foo.html"))
|
35
|
+
page = @agent.get("file://#{f}")
|
36
|
+
assert_equal(File.read(f), page.body)
|
37
|
+
assert_kind_of(Mechanize::Page, page)
|
38
|
+
end
|
39
|
+
|
33
40
|
def test_click_file_link
|
34
41
|
f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs"))
|
35
42
|
page = @agent.get("file://#{f}")
|
metadata
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mechanize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 40220156341521
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- beta
|
11
|
+
- 20110107104205
|
12
|
+
version: 1.0.1.beta.20110107104205
|
5
13
|
platform: ruby
|
6
14
|
authors:
|
7
15
|
- Aaron Patterson
|
@@ -10,29 +18,56 @@ autorequire:
|
|
10
18
|
bindir: bin
|
11
19
|
cert_chain: []
|
12
20
|
|
13
|
-
date:
|
21
|
+
date: 2011-01-07 00:00:00 -08:00
|
14
22
|
default_executable:
|
15
23
|
dependencies:
|
16
24
|
- !ruby/object:Gem::Dependency
|
17
25
|
name: nokogiri
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
21
29
|
requirements:
|
22
30
|
- - ">="
|
23
31
|
- !ruby/object:Gem::Version
|
32
|
+
hash: 29
|
33
|
+
segments:
|
34
|
+
- 1
|
35
|
+
- 2
|
36
|
+
- 1
|
24
37
|
version: 1.2.1
|
25
|
-
|
38
|
+
type: :runtime
|
39
|
+
version_requirements: *id001
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: net-http-persistent
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 13
|
49
|
+
segments:
|
50
|
+
- 1
|
51
|
+
- 1
|
52
|
+
version: "1.1"
|
53
|
+
type: :runtime
|
54
|
+
version_requirements: *id002
|
26
55
|
- !ruby/object:Gem::Dependency
|
27
56
|
name: hoe
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
31
60
|
requirements:
|
32
61
|
- - ">="
|
33
62
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
63
|
+
hash: 47
|
64
|
+
segments:
|
65
|
+
- 2
|
66
|
+
- 8
|
67
|
+
- 0
|
68
|
+
version: 2.8.0
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id003
|
36
71
|
description: |-
|
37
72
|
The Mechanize library is used for automating interaction with websites.
|
38
73
|
Mechanize automatically stores and sends cookies, follows redirects,
|
@@ -202,7 +237,6 @@ files:
|
|
202
237
|
- test/test_history_added.rb
|
203
238
|
- test/test_html_unscape_forms.rb
|
204
239
|
- test/test_if_modified_since.rb
|
205
|
-
- test/test_keep_alive.rb
|
206
240
|
- test/test_links.rb
|
207
241
|
- test/test_mech.rb
|
208
242
|
- test/test_mech_proxy.rb
|
@@ -235,6 +269,7 @@ files:
|
|
235
269
|
- test/test_upload.rb
|
236
270
|
- test/test_util.rb
|
237
271
|
- test/test_verbs.rb
|
272
|
+
- test/test_headers.rb
|
238
273
|
has_rdoc: true
|
239
274
|
homepage: http://mechanize.rubyforge.org
|
240
275
|
licenses: []
|
@@ -246,21 +281,29 @@ rdoc_options:
|
|
246
281
|
require_paths:
|
247
282
|
- lib
|
248
283
|
required_ruby_version: !ruby/object:Gem::Requirement
|
284
|
+
none: false
|
249
285
|
requirements:
|
250
286
|
- - ">="
|
251
287
|
- !ruby/object:Gem::Version
|
288
|
+
hash: 3
|
289
|
+
segments:
|
290
|
+
- 0
|
252
291
|
version: "0"
|
253
|
-
version:
|
254
292
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
293
|
+
none: false
|
255
294
|
requirements:
|
256
|
-
- - "
|
295
|
+
- - ">"
|
257
296
|
- !ruby/object:Gem::Version
|
258
|
-
|
259
|
-
|
297
|
+
hash: 25
|
298
|
+
segments:
|
299
|
+
- 1
|
300
|
+
- 3
|
301
|
+
- 1
|
302
|
+
version: 1.3.1
|
260
303
|
requirements: []
|
261
304
|
|
262
305
|
rubyforge_project: mechanize
|
263
|
-
rubygems_version: 1.3.
|
306
|
+
rubygems_version: 1.3.7
|
264
307
|
signing_key:
|
265
308
|
specification_version: 3
|
266
309
|
summary: The Mechanize library is used for automating interaction with websites
|
@@ -293,11 +336,11 @@ test_files:
|
|
293
336
|
- test/test_get_headers.rb
|
294
337
|
- test/test_gzipping.rb
|
295
338
|
- test/test_hash_api.rb
|
339
|
+
- test/test_headers.rb
|
296
340
|
- test/test_history.rb
|
297
341
|
- test/test_history_added.rb
|
298
342
|
- test/test_html_unscape_forms.rb
|
299
343
|
- test/test_if_modified_since.rb
|
300
|
-
- test/test_keep_alive.rb
|
301
344
|
- test/test_links.rb
|
302
345
|
- test/test_mech.rb
|
303
346
|
- test/test_mech_proxy.rb
|
data/test/test_keep_alive.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestKeepAlive < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@agent = Mechanize.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_keep_alive
|
9
|
-
page = @agent.get('http://localhost/http_headers')
|
10
|
-
headers = {}
|
11
|
-
page.body.split(/[\r\n]+/).each do |header|
|
12
|
-
headers.[]=(*header.chomp.split(/\|/))
|
13
|
-
end
|
14
|
-
assert(headers.has_key?('connection'))
|
15
|
-
assert_equal('keep-alive', headers['connection'])
|
16
|
-
assert(headers.has_key?('keep-alive'))
|
17
|
-
assert_equal('300', headers['keep-alive'])
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_close_connection
|
21
|
-
@agent.keep_alive = false
|
22
|
-
page = @agent.get('http://localhost/http_headers')
|
23
|
-
headers = {}
|
24
|
-
page.body.split(/[\r\n]+/).each do |header|
|
25
|
-
headers.[]=(*header.chomp.split(/\|/))
|
26
|
-
end
|
27
|
-
assert(headers.has_key?('connection'))
|
28
|
-
assert_equal('close', headers['connection'])
|
29
|
-
assert(!headers.has_key?('keep-alive'))
|
30
|
-
end
|
31
|
-
end
|