mechanize 2.0.pre.2 → 2.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.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.rdoc +22 -0
- data/Manifest.txt +11 -8
- data/Rakefile +2 -2
- data/examples/flickr_upload.rb +6 -7
- data/examples/mech-dump.rb +0 -2
- data/examples/proxy_req.rb +0 -2
- data/examples/rubyforge.rb +1 -3
- data/examples/spider.rb +2 -3
- data/lib/mechanize.rb +228 -680
- data/lib/mechanize/form/field.rb +1 -1
- data/lib/mechanize/history.rb +23 -5
- data/lib/mechanize/http.rb +3 -0
- data/lib/mechanize/http/agent.rb +738 -0
- data/lib/mechanize/inspect.rb +2 -2
- data/lib/mechanize/page.rb +101 -42
- data/lib/mechanize/page/frame.rb +24 -17
- data/lib/mechanize/page/link.rb +72 -54
- data/lib/mechanize/page/meta_refresh.rb +56 -0
- data/lib/mechanize/response_read_error.rb +27 -0
- data/test/htdocs/frame_referer_test.html +10 -0
- data/test/htdocs/tc_referer.html +4 -0
- data/test/test_frames.rb +9 -0
- data/test/test_history.rb +74 -98
- data/test/test_mechanize.rb +334 -812
- data/test/test_mechanize_form.rb +32 -3
- data/test/{test_textarea.rb → test_mechanize_form_textarea.rb} +1 -1
- data/test/test_mechanize_http_agent.rb +697 -0
- data/test/test_mechanize_link.rb +83 -0
- data/test/test_mechanize_page_encoding.rb +147 -0
- data/test/test_mechanize_page_link.rb +379 -0
- data/test/test_mechanize_page_meta_refresh.rb +115 -0
- data/test/test_pretty_print.rb +1 -1
- data/test/test_referer.rb +29 -5
- data/test/test_response_code.rb +21 -20
- data/test/test_robots.rb +13 -17
- data/test/test_scheme.rb +1 -1
- metadata +30 -31
- metadata.gz.sig +0 -0
- data/lib/mechanize/page/meta.rb +0 -48
- data/test/test_form_no_inputname.rb +0 -15
- data/test/test_links.rb +0 -146
- data/test/test_mechanize_page.rb +0 -224
- data/test/test_meta.rb +0 -67
- data/test/test_upload.rb +0 -109
- data/test/test_verbs.rb +0 -25
data/test/test_upload.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class UploadMechTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@agent = Mechanize.new
|
6
|
-
@page = @agent.get("http://localhost/file_upload.html")
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_upload_with_post_param
|
10
|
-
page = @agent.post('http://localhost/file_upload', {
|
11
|
-
:name => 'Some file',
|
12
|
-
:userfile1 => File.open(__FILE__)
|
13
|
-
})
|
14
|
-
assert_match(
|
15
|
-
"Content-Disposition: form-data; name=\"userfile1\"; filename=\"#{File.basename(__FILE__)}\"",
|
16
|
-
page.body
|
17
|
-
)
|
18
|
-
assert page.body.length > File.read(__FILE__).length
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_form_enctype
|
22
|
-
assert_equal('multipart/form-data', @page.forms[0].enctype)
|
23
|
-
|
24
|
-
form = @page.forms.first
|
25
|
-
form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
|
26
|
-
form.file_uploads.first.mime_type = "text/plain"
|
27
|
-
form.file_uploads.first.file_data = "Hello World\n\n"
|
28
|
-
|
29
|
-
@page = @agent.submit(form)
|
30
|
-
|
31
|
-
assert_match(
|
32
|
-
"Content-Disposition: form-data; name=\"userfile1\"; filename=\"helper.rb\"",
|
33
|
-
@page.body
|
34
|
-
)
|
35
|
-
assert_match(
|
36
|
-
"Content-Disposition: form-data; name=\"name\"",
|
37
|
-
@page.body
|
38
|
-
)
|
39
|
-
assert_match('Content-Type: text/plain', @page.body)
|
40
|
-
assert_match('Hello World', @page.body)
|
41
|
-
assert_match('foo[aaron]', @page.body)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_form_multipart
|
45
|
-
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
46
|
-
|
47
|
-
form = @page.forms[1]
|
48
|
-
form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
|
49
|
-
form.file_uploads.first.mime_type = "text/plain"
|
50
|
-
form.file_uploads.first.file_data = "Hello World\n\n"
|
51
|
-
|
52
|
-
@page = @agent.submit(form)
|
53
|
-
|
54
|
-
assert_match(
|
55
|
-
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
|
56
|
-
@page.body
|
57
|
-
)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_form_read_file
|
61
|
-
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
62
|
-
|
63
|
-
form = @page.forms[1]
|
64
|
-
form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
|
65
|
-
|
66
|
-
@page = @agent.submit(form)
|
67
|
-
|
68
|
-
contents = File.open("#{BASE_DIR}/helper.rb", 'rb') { |f| f.read }
|
69
|
-
assert_match(
|
70
|
-
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
|
71
|
-
@page.body
|
72
|
-
)
|
73
|
-
assert_match(contents, @page.body)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_form_io_obj
|
77
|
-
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
78
|
-
|
79
|
-
form = @page.forms[1]
|
80
|
-
form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
|
81
|
-
form.file_uploads.first.file_data = File.open("#{BASE_DIR}/helper.rb", 'rb')
|
82
|
-
|
83
|
-
@page = @agent.submit(form)
|
84
|
-
|
85
|
-
contents = File.open("#{BASE_DIR}/helper.rb", 'rb') { |f| f.read }
|
86
|
-
assert_match(
|
87
|
-
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
|
88
|
-
@page.body
|
89
|
-
)
|
90
|
-
assert_match(contents, @page.body)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_submit_no_file
|
94
|
-
form = @page.forms.first
|
95
|
-
form.field_with(:name => 'name').value = 'Aaron'
|
96
|
-
@page = @agent.submit(form)
|
97
|
-
assert_match('Aaron', @page.body)
|
98
|
-
assert_match(
|
99
|
-
"Content-Disposition: form-data; name=\"userfile1\"; filename=\"\"",
|
100
|
-
@page.body
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_no_value
|
105
|
-
form = @page.form('value_test')
|
106
|
-
assert_nil(form.file_uploads.first.value)
|
107
|
-
assert_nil(form.file_uploads.first.file_name)
|
108
|
-
end
|
109
|
-
end
|
data/test/test_verbs.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class VerbsTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@agent = Mechanize.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_put
|
9
|
-
page = @agent.put('http://localhost/verb', 'foo')
|
10
|
-
assert_equal 1, @agent.history.length
|
11
|
-
assert_equal 'PUT', page.header['X-Request-Method']
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_delete
|
15
|
-
page = @agent.delete('http://localhost/verb', { 'q' => 'foo' })
|
16
|
-
assert_equal 1, @agent.history.length
|
17
|
-
assert_equal 'DELETE', page.header['X-Request-Method']
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_head
|
21
|
-
page = @agent.head('http://localhost/verb', { 'q' => 'foo' })
|
22
|
-
assert_equal 0, @agent.history.length
|
23
|
-
assert_equal 'HEAD', page.header['X-Request-Method']
|
24
|
-
end
|
25
|
-
end
|