mechanize 0.7.8 → 0.8.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/History.txt +14 -0
- data/Manifest.txt +30 -5
- data/README.txt +5 -5
- data/Rakefile +6 -0
- data/{eg → examples}/flickr_upload.rb +0 -0
- data/{eg → examples}/mech-dump.rb +0 -0
- data/{eg → examples}/proxy_req.rb +0 -0
- data/{eg → examples}/rubyforge.rb +0 -0
- data/{eg → examples}/spider.rb +0 -0
- data/lib/www/mechanize.rb +183 -404
- data/lib/www/mechanize/chain.rb +34 -0
- data/lib/www/mechanize/chain/auth_headers.rb +79 -0
- data/lib/www/mechanize/chain/body_decoding_handler.rb +43 -0
- data/lib/www/mechanize/chain/connection_resolver.rb +78 -0
- data/lib/www/mechanize/chain/custom_headers.rb +23 -0
- data/lib/www/mechanize/chain/handler.rb +9 -0
- data/lib/www/mechanize/chain/header_resolver.rb +47 -0
- data/lib/www/mechanize/chain/parameter_resolver.rb +23 -0
- data/lib/www/mechanize/chain/post_connect_hook.rb +0 -0
- data/lib/www/mechanize/chain/pre_connect_hook.rb +22 -0
- data/lib/www/mechanize/chain/request_resolver.rb +28 -0
- data/lib/www/mechanize/chain/response_body_parser.rb +40 -0
- data/lib/www/mechanize/chain/response_header_handler.rb +50 -0
- data/lib/www/mechanize/chain/response_reader.rb +41 -0
- data/lib/www/mechanize/chain/ssl_resolver.rb +36 -0
- data/lib/www/mechanize/chain/uri_resolver.rb +56 -0
- data/lib/www/mechanize/cookie.rb +1 -1
- data/lib/www/mechanize/file_response.rb +60 -0
- data/lib/www/mechanize/form.rb +12 -4
- data/lib/www/mechanize/form/field.rb +2 -2
- data/lib/www/mechanize/form/file_upload.rb +1 -1
- data/lib/www/mechanize/form/option.rb +1 -1
- data/lib/www/mechanize/list.rb +4 -0
- data/lib/www/mechanize/page.rb +20 -10
- data/lib/www/mechanize/util.rb +29 -0
- data/mechanize.gemspec +4 -4
- data/test/chain/test_argument_validator.rb +14 -0
- data/test/chain/test_custom_headers.rb +18 -0
- data/test/chain/test_parameter_resolver.rb +35 -0
- data/test/chain/test_request_resolver.rb +29 -0
- data/test/chain/test_response_reader.rb +24 -0
- data/test/helper.rb +3 -1
- data/test/servlets.rb +43 -0
- data/test/test_authenticate.rb +13 -12
- data/test/test_bad_links.rb +1 -1
- data/test/test_blank_form.rb +1 -1
- data/test/test_checkboxes.rb +1 -1
- data/test/test_content_type.rb +1 -1
- data/test/test_cookie_class.rb +1 -1
- data/test/test_cookie_jar.rb +1 -1
- data/test/test_cookies.rb +1 -1
- data/test/test_encoded_links.rb +1 -1
- data/test/test_errors.rb +1 -1
- data/test/test_follow_meta.rb +1 -1
- data/test/test_form_action.rb +1 -1
- data/test/test_form_as_hash.rb +1 -1
- data/test/test_form_button.rb +22 -17
- data/test/test_form_no_inputname.rb +1 -1
- data/test/test_forms.rb +2 -1
- data/test/test_frames.rb +1 -1
- data/test/test_get_headers.rb +1 -1
- data/test/test_gzipping.rb +1 -1
- data/test/test_hash_api.rb +17 -14
- data/test/test_history.rb +1 -1
- data/test/test_history_added.rb +1 -1
- data/test/test_html_unscape_forms.rb +1 -1
- data/test/test_if_modified_since.rb +1 -1
- data/test/test_keep_alive.rb +1 -1
- data/test/test_links.rb +1 -1
- data/test/test_mech.rb +18 -11
- data/test/test_mechanize_file.rb +1 -1
- data/test/test_multi_select.rb +1 -1
- data/test/test_no_attributes.rb +1 -1
- data/test/test_option.rb +2 -1
- data/test/test_page.rb +1 -1
- data/test/test_pluggable_parser.rb +1 -1
- data/test/test_post_form.rb +1 -1
- data/test/test_pretty_print.rb +1 -1
- data/test/test_radiobutton.rb +1 -1
- data/test/test_redirect_limit_reached.rb +1 -1
- data/test/test_referer.rb +1 -1
- data/test/test_relative_links.rb +1 -1
- data/test/test_response_code.rb +7 -1
- data/test/test_save_file.rb +1 -1
- data/test/test_scheme.rb +44 -0
- data/test/test_select.rb +1 -1
- data/test/test_select_all.rb +1 -1
- data/test/test_select_none.rb +1 -1
- data/test/test_select_noopts.rb +1 -1
- data/test/test_set_fields.rb +1 -1
- data/test/test_ssl_server.rb +1 -1
- data/test/test_subclass.rb +4 -11
- data/test/test_textarea.rb +1 -1
- data/test/test_upload.rb +1 -1
- data/test/test_verbs.rb +22 -0
- metadata +39 -7
data/test/test_history.rb
CHANGED
data/test/test_history_added.rb
CHANGED
data/test/test_keep_alive.rb
CHANGED
data/test/test_links.rb
CHANGED
data/test/test_mech.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
2
|
|
3
3
|
class TestMechMethods < Test::Unit::TestCase
|
4
4
|
def setup
|
@@ -20,20 +20,27 @@ class TestMechMethods < Test::Unit::TestCase
|
|
20
20
|
assert_equal('HTTP://localhost/?q=hello', page.uri.to_s)
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_post_connect_hook_gets_called
|
24
|
+
response = nil
|
25
|
+
@agent.post_connect_hooks << lambda { |params|
|
26
|
+
response = params[:response]
|
27
|
+
}
|
28
|
+
|
29
|
+
@agent.get('http://localhost/')
|
30
|
+
assert(response)
|
31
|
+
end
|
32
|
+
|
23
33
|
def test_get_with_referer
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@request = request
|
30
|
-
end
|
31
|
-
end
|
34
|
+
request = nil
|
35
|
+
@agent.pre_connect_hooks << lambda { |params|
|
36
|
+
request = params[:request]
|
37
|
+
}
|
38
|
+
|
32
39
|
@agent.get('http://localhost/', URI.parse('http://google.com/'))
|
33
|
-
assert_equal 'http://google.com/',
|
40
|
+
assert_equal 'http://google.com/', request['Referer']
|
34
41
|
|
35
42
|
@agent.get('http://localhost/', [], 'http://tenderlovemaking.com/')
|
36
|
-
assert_equal 'http://tenderlovemaking.com/',
|
43
|
+
assert_equal 'http://tenderlovemaking.com/', request['Referer']
|
37
44
|
end
|
38
45
|
|
39
46
|
def test_get_with_file_referer
|
data/test/test_mechanize_file.rb
CHANGED
data/test/test_multi_select.rb
CHANGED
data/test/test_no_attributes.rb
CHANGED
data/test/test_option.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
2
|
|
3
3
|
class OptionTest < Test::Unit::TestCase
|
4
4
|
class FakeAttribute < Hash
|
@@ -7,6 +7,7 @@ class OptionTest < Test::Unit::TestCase
|
|
7
7
|
@inner_text = inner_text
|
8
8
|
end
|
9
9
|
alias :has_attribute? :has_key?
|
10
|
+
alias :attributes :keys
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_option_missing_value
|
data/test/test_page.rb
CHANGED
data/test/test_post_form.rb
CHANGED
data/test/test_pretty_print.rb
CHANGED
data/test/test_radiobutton.rb
CHANGED
data/test/test_referer.rb
CHANGED
data/test/test_relative_links.rb
CHANGED
data/test/test_response_code.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
2
|
|
3
3
|
class ResponseCodeMechTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@agent = WWW::Mechanize.new
|
6
6
|
end
|
7
7
|
|
8
|
+
def test_eof_error_loop
|
9
|
+
assert_raises(EOFError) {
|
10
|
+
@agent.get("http://localhost/http_headers?Content-Length=300")
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
8
14
|
def test_redirect
|
9
15
|
@agent.get("http://localhost/response_code?code=300")
|
10
16
|
assert_equal("http://localhost/index.html",
|
data/test/test_save_file.rb
CHANGED
data/test/test_scheme.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class SchemeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@agent = WWW::Mechanize.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_file_scheme
|
9
|
+
f = File.expand_path(__FILE__)
|
10
|
+
page = @agent.get("file://#{f}")
|
11
|
+
assert_equal(File.read(f), page.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_file_scheme_parses_html
|
15
|
+
f = File.expand_path(
|
16
|
+
File.join(File.dirname(__FILE__), "htdocs", 'google.html'))
|
17
|
+
page = @agent.get("file://#{f}")
|
18
|
+
assert_equal(File.read(f), page.body)
|
19
|
+
assert_kind_of(WWW::Mechanize::Page, page)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_file_scheme_supports_directories
|
23
|
+
f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs"))
|
24
|
+
page = @agent.get("file://#{f}")
|
25
|
+
assert_equal(Dir[File.join(f, '*')].length, page.links.length)
|
26
|
+
assert_kind_of(WWW::Mechanize::Page, page)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_click_file_link
|
30
|
+
f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs"))
|
31
|
+
page = @agent.get("file://#{f}")
|
32
|
+
link = page.links.find { |l| l.text =~ /tc_follow_meta/ }
|
33
|
+
assert_not_nil(link)
|
34
|
+
path = URI.parse(link.href).path
|
35
|
+
|
36
|
+
page = link.click
|
37
|
+
assert_equal(File.read(path), page.body)
|
38
|
+
|
39
|
+
link = page.meta.first
|
40
|
+
assert_not_nil(link)
|
41
|
+
page = @agent.click(link)
|
42
|
+
assert_equal("http://localhost/index.html", @agent.history.last.uri.to_s)
|
43
|
+
end
|
44
|
+
end
|
data/test/test_select.rb
CHANGED
data/test/test_select_all.rb
CHANGED
data/test/test_select_none.rb
CHANGED
data/test/test_select_noopts.rb
CHANGED
data/test/test_set_fields.rb
CHANGED
data/test/test_ssl_server.rb
CHANGED
data/test/test_subclass.rb
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
class MechSubclass < WWW::Mechanize
|
4
|
-
def set_headers(uri, request, cur_page)
|
5
|
-
super(uri, request, cur_page)
|
6
|
-
request.add_field('Cookie', 'name=Aaron')
|
7
|
-
request
|
8
|
-
end
|
9
|
-
end
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
10
2
|
|
11
3
|
class TestSubclass < Test::Unit::TestCase
|
12
4
|
def setup
|
13
|
-
@agent =
|
5
|
+
@agent = WWW::Mechanize.new
|
14
6
|
end
|
15
7
|
|
16
8
|
def test_send_cookie
|
17
|
-
page = @agent.get("http://localhost/send_cookies"
|
9
|
+
page = @agent.get( :url => "http://localhost/send_cookies",
|
10
|
+
:headers => {'Cookie' => 'name=Aaron'} )
|
18
11
|
assert_equal(1, page.links.length)
|
19
12
|
assert_not_nil(page.links.find { |l| l.text == "name:Aaron" })
|
20
13
|
end
|
data/test/test_textarea.rb
CHANGED
data/test/test_upload.rb
CHANGED
data/test/test_verbs.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class VerbsTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@agent = WWW::Mechanize.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_put
|
9
|
+
page = @agent.put('http://localhost/verb', { 'q' => 'foo' })
|
10
|
+
assert_equal('method: PUT', page.body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_delete
|
14
|
+
page = @agent.delete('http://localhost/verb', { 'q' => 'foo' })
|
15
|
+
assert_equal('method: DELETE', page.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_head
|
19
|
+
page = @agent.head('http://localhost/verb', { 'q' => 'foo' })
|
20
|
+
assert_equal('method: HEAD', page.body)
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mechanize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,17 +57,34 @@ files:
|
|
57
57
|
- NOTES.txt
|
58
58
|
- README.txt
|
59
59
|
- Rakefile
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
60
|
+
- examples/flickr_upload.rb
|
61
|
+
- examples/mech-dump.rb
|
62
|
+
- examples/proxy_req.rb
|
63
|
+
- examples/rubyforge.rb
|
64
|
+
- examples/spider.rb
|
65
65
|
- lib/mechanize.rb
|
66
66
|
- lib/www/mechanize.rb
|
67
|
+
- lib/www/mechanize/chain.rb
|
68
|
+
- lib/www/mechanize/chain/auth_headers.rb
|
69
|
+
- lib/www/mechanize/chain/body_decoding_handler.rb
|
70
|
+
- lib/www/mechanize/chain/connection_resolver.rb
|
71
|
+
- lib/www/mechanize/chain/custom_headers.rb
|
72
|
+
- lib/www/mechanize/chain/handler.rb
|
73
|
+
- lib/www/mechanize/chain/header_resolver.rb
|
74
|
+
- lib/www/mechanize/chain/parameter_resolver.rb
|
75
|
+
- lib/www/mechanize/chain/post_connect_hook.rb
|
76
|
+
- lib/www/mechanize/chain/pre_connect_hook.rb
|
77
|
+
- lib/www/mechanize/chain/request_resolver.rb
|
78
|
+
- lib/www/mechanize/chain/response_body_parser.rb
|
79
|
+
- lib/www/mechanize/chain/response_header_handler.rb
|
80
|
+
- lib/www/mechanize/chain/response_reader.rb
|
81
|
+
- lib/www/mechanize/chain/ssl_resolver.rb
|
82
|
+
- lib/www/mechanize/chain/uri_resolver.rb
|
67
83
|
- lib/www/mechanize/content_type_error.rb
|
68
84
|
- lib/www/mechanize/cookie.rb
|
69
85
|
- lib/www/mechanize/cookie_jar.rb
|
70
86
|
- lib/www/mechanize/file.rb
|
87
|
+
- lib/www/mechanize/file_response.rb
|
71
88
|
- lib/www/mechanize/file_saver.rb
|
72
89
|
- lib/www/mechanize/form.rb
|
73
90
|
- lib/www/mechanize/form/button.rb
|
@@ -93,7 +110,13 @@ files:
|
|
93
110
|
- lib/www/mechanize/redirect_limit_reached_error.rb
|
94
111
|
- lib/www/mechanize/response_code_error.rb
|
95
112
|
- lib/www/mechanize/unsupported_scheme_error.rb
|
113
|
+
- lib/www/mechanize/util.rb
|
96
114
|
- mechanize.gemspec
|
115
|
+
- test/chain/test_argument_validator.rb
|
116
|
+
- test/chain/test_custom_headers.rb
|
117
|
+
- test/chain/test_parameter_resolver.rb
|
118
|
+
- test/chain/test_request_resolver.rb
|
119
|
+
- test/chain/test_response_reader.rb
|
97
120
|
- test/data/htpasswd
|
98
121
|
- test/data/server.crt
|
99
122
|
- test/data/server.csr
|
@@ -182,6 +205,7 @@ files:
|
|
182
205
|
- test/test_relative_links.rb
|
183
206
|
- test/test_response_code.rb
|
184
207
|
- test/test_save_file.rb
|
208
|
+
- test/test_scheme.rb
|
185
209
|
- test/test_select.rb
|
186
210
|
- test/test_select_all.rb
|
187
211
|
- test/test_select_none.rb
|
@@ -191,6 +215,7 @@ files:
|
|
191
215
|
- test/test_subclass.rb
|
192
216
|
- test/test_textarea.rb
|
193
217
|
- test/test_upload.rb
|
218
|
+
- test/test_verbs.rb
|
194
219
|
has_rdoc: true
|
195
220
|
homepage: " http://mechanize.rubyforge.org/"
|
196
221
|
post_install_message:
|
@@ -219,6 +244,11 @@ signing_key:
|
|
219
244
|
specification_version: 2
|
220
245
|
summary: Mechanize provides automated web-browsing
|
221
246
|
test_files:
|
247
|
+
- test/chain/test_argument_validator.rb
|
248
|
+
- test/chain/test_custom_headers.rb
|
249
|
+
- test/chain/test_parameter_resolver.rb
|
250
|
+
- test/chain/test_request_resolver.rb
|
251
|
+
- test/chain/test_response_reader.rb
|
222
252
|
- test/test_authenticate.rb
|
223
253
|
- test/test_bad_links.rb
|
224
254
|
- test/test_blank_form.rb
|
@@ -260,6 +290,7 @@ test_files:
|
|
260
290
|
- test/test_relative_links.rb
|
261
291
|
- test/test_response_code.rb
|
262
292
|
- test/test_save_file.rb
|
293
|
+
- test/test_scheme.rb
|
263
294
|
- test/test_select.rb
|
264
295
|
- test/test_select_all.rb
|
265
296
|
- test/test_select_none.rb
|
@@ -269,3 +300,4 @@ test_files:
|
|
269
300
|
- test/test_subclass.rb
|
270
301
|
- test/test_textarea.rb
|
271
302
|
- test/test_upload.rb
|
303
|
+
- test/test_verbs.rb
|