eric-mechanize 0.9.3.20090623142847

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/CHANGELOG.rdoc +504 -0
  2. data/EXAMPLES.rdoc +171 -0
  3. data/FAQ.rdoc +11 -0
  4. data/GUIDE.rdoc +122 -0
  5. data/LICENSE.rdoc +340 -0
  6. data/Manifest.txt +169 -0
  7. data/README.rdoc +60 -0
  8. data/Rakefile +43 -0
  9. data/examples/flickr_upload.rb +23 -0
  10. data/examples/mech-dump.rb +7 -0
  11. data/examples/proxy_req.rb +9 -0
  12. data/examples/rubyforge.rb +21 -0
  13. data/examples/spider.rb +11 -0
  14. data/lib/mechanize.rb +7 -0
  15. data/lib/www/mechanize.rb +619 -0
  16. data/lib/www/mechanize/chain.rb +34 -0
  17. data/lib/www/mechanize/chain/auth_headers.rb +80 -0
  18. data/lib/www/mechanize/chain/body_decoding_handler.rb +48 -0
  19. data/lib/www/mechanize/chain/connection_resolver.rb +78 -0
  20. data/lib/www/mechanize/chain/custom_headers.rb +23 -0
  21. data/lib/www/mechanize/chain/handler.rb +9 -0
  22. data/lib/www/mechanize/chain/header_resolver.rb +53 -0
  23. data/lib/www/mechanize/chain/parameter_resolver.rb +24 -0
  24. data/lib/www/mechanize/chain/post_connect_hook.rb +0 -0
  25. data/lib/www/mechanize/chain/pre_connect_hook.rb +22 -0
  26. data/lib/www/mechanize/chain/request_resolver.rb +32 -0
  27. data/lib/www/mechanize/chain/response_body_parser.rb +40 -0
  28. data/lib/www/mechanize/chain/response_header_handler.rb +50 -0
  29. data/lib/www/mechanize/chain/response_reader.rb +41 -0
  30. data/lib/www/mechanize/chain/ssl_resolver.rb +42 -0
  31. data/lib/www/mechanize/chain/uri_resolver.rb +77 -0
  32. data/lib/www/mechanize/content_type_error.rb +16 -0
  33. data/lib/www/mechanize/cookie.rb +72 -0
  34. data/lib/www/mechanize/cookie_jar.rb +191 -0
  35. data/lib/www/mechanize/file.rb +73 -0
  36. data/lib/www/mechanize/file_response.rb +62 -0
  37. data/lib/www/mechanize/file_saver.rb +39 -0
  38. data/lib/www/mechanize/form.rb +360 -0
  39. data/lib/www/mechanize/form/button.rb +8 -0
  40. data/lib/www/mechanize/form/check_box.rb +13 -0
  41. data/lib/www/mechanize/form/field.rb +28 -0
  42. data/lib/www/mechanize/form/file_upload.rb +24 -0
  43. data/lib/www/mechanize/form/image_button.rb +23 -0
  44. data/lib/www/mechanize/form/multi_select_list.rb +69 -0
  45. data/lib/www/mechanize/form/option.rb +51 -0
  46. data/lib/www/mechanize/form/radio_button.rb +38 -0
  47. data/lib/www/mechanize/form/select_list.rb +45 -0
  48. data/lib/www/mechanize/headers.rb +12 -0
  49. data/lib/www/mechanize/history.rb +67 -0
  50. data/lib/www/mechanize/inspect.rb +90 -0
  51. data/lib/www/mechanize/monkey_patch.rb +37 -0
  52. data/lib/www/mechanize/page.rb +181 -0
  53. data/lib/www/mechanize/page/base.rb +10 -0
  54. data/lib/www/mechanize/page/frame.rb +22 -0
  55. data/lib/www/mechanize/page/link.rb +50 -0
  56. data/lib/www/mechanize/page/meta.rb +51 -0
  57. data/lib/www/mechanize/pluggable_parsers.rb +103 -0
  58. data/lib/www/mechanize/redirect_limit_reached_error.rb +18 -0
  59. data/lib/www/mechanize/redirect_not_get_or_head_error.rb +20 -0
  60. data/lib/www/mechanize/response_code_error.rb +25 -0
  61. data/lib/www/mechanize/unsupported_scheme_error.rb +10 -0
  62. data/lib/www/mechanize/util.rb +76 -0
  63. data/mechanize.gemspec +41 -0
  64. data/test/chain/test_argument_validator.rb +14 -0
  65. data/test/chain/test_auth_headers.rb +25 -0
  66. data/test/chain/test_custom_headers.rb +18 -0
  67. data/test/chain/test_header_resolver.rb +28 -0
  68. data/test/chain/test_parameter_resolver.rb +35 -0
  69. data/test/chain/test_request_resolver.rb +29 -0
  70. data/test/chain/test_response_reader.rb +24 -0
  71. data/test/data/htpasswd +1 -0
  72. data/test/data/server.crt +16 -0
  73. data/test/data/server.csr +12 -0
  74. data/test/data/server.key +15 -0
  75. data/test/data/server.pem +15 -0
  76. data/test/helper.rb +129 -0
  77. data/test/htdocs/alt_text.html +10 -0
  78. data/test/htdocs/bad_form_test.html +9 -0
  79. data/test/htdocs/button.jpg +0 -0
  80. data/test/htdocs/empty_form.html +6 -0
  81. data/test/htdocs/file_upload.html +26 -0
  82. data/test/htdocs/find_link.html +41 -0
  83. data/test/htdocs/form_multi_select.html +16 -0
  84. data/test/htdocs/form_multival.html +37 -0
  85. data/test/htdocs/form_no_action.html +18 -0
  86. data/test/htdocs/form_no_input_name.html +16 -0
  87. data/test/htdocs/form_select.html +16 -0
  88. data/test/htdocs/form_select_all.html +16 -0
  89. data/test/htdocs/form_select_none.html +17 -0
  90. data/test/htdocs/form_select_noopts.html +10 -0
  91. data/test/htdocs/form_set_fields.html +14 -0
  92. data/test/htdocs/form_test.html +188 -0
  93. data/test/htdocs/frame_test.html +30 -0
  94. data/test/htdocs/google.html +13 -0
  95. data/test/htdocs/iframe_test.html +16 -0
  96. data/test/htdocs/index.html +6 -0
  97. data/test/htdocs/link with space.html +5 -0
  98. data/test/htdocs/meta_cookie.html +11 -0
  99. data/test/htdocs/no_title_test.html +6 -0
  100. data/test/htdocs/relative/tc_relative_links.html +21 -0
  101. data/test/htdocs/tc_bad_links.html +5 -0
  102. data/test/htdocs/tc_base_link.html +8 -0
  103. data/test/htdocs/tc_blank_form.html +11 -0
  104. data/test/htdocs/tc_checkboxes.html +19 -0
  105. data/test/htdocs/tc_encoded_links.html +5 -0
  106. data/test/htdocs/tc_follow_meta.html +8 -0
  107. data/test/htdocs/tc_form_action.html +48 -0
  108. data/test/htdocs/tc_links.html +18 -0
  109. data/test/htdocs/tc_no_attributes.html +16 -0
  110. data/test/htdocs/tc_pretty_print.html +17 -0
  111. data/test/htdocs/tc_radiobuttons.html +17 -0
  112. data/test/htdocs/tc_referer.html +10 -0
  113. data/test/htdocs/tc_relative_links.html +19 -0
  114. data/test/htdocs/tc_textarea.html +23 -0
  115. data/test/htdocs/unusual______.html +5 -0
  116. data/test/servlets.rb +365 -0
  117. data/test/ssl_server.rb +48 -0
  118. data/test/test_authenticate.rb +71 -0
  119. data/test/test_bad_links.rb +25 -0
  120. data/test/test_blank_form.rb +16 -0
  121. data/test/test_checkboxes.rb +61 -0
  122. data/test/test_content_type.rb +13 -0
  123. data/test/test_cookie_class.rb +338 -0
  124. data/test/test_cookie_jar.rb +362 -0
  125. data/test/test_cookies.rb +123 -0
  126. data/test/test_encoded_links.rb +20 -0
  127. data/test/test_errors.rb +49 -0
  128. data/test/test_follow_meta.rb +108 -0
  129. data/test/test_form_action.rb +52 -0
  130. data/test/test_form_as_hash.rb +61 -0
  131. data/test/test_form_button.rb +38 -0
  132. data/test/test_form_no_inputname.rb +15 -0
  133. data/test/test_forms.rb +564 -0
  134. data/test/test_frames.rb +25 -0
  135. data/test/test_get_headers.rb +52 -0
  136. data/test/test_gzipping.rb +22 -0
  137. data/test/test_hash_api.rb +45 -0
  138. data/test/test_history.rb +142 -0
  139. data/test/test_history_added.rb +16 -0
  140. data/test/test_html_unscape_forms.rb +39 -0
  141. data/test/test_if_modified_since.rb +20 -0
  142. data/test/test_keep_alive.rb +31 -0
  143. data/test/test_links.rb +120 -0
  144. data/test/test_mech.rb +268 -0
  145. data/test/test_mechanize_file.rb +47 -0
  146. data/test/test_meta.rb +65 -0
  147. data/test/test_multi_select.rb +106 -0
  148. data/test/test_no_attributes.rb +13 -0
  149. data/test/test_option.rb +18 -0
  150. data/test/test_page.rb +124 -0
  151. data/test/test_pluggable_parser.rb +145 -0
  152. data/test/test_post_form.rb +34 -0
  153. data/test/test_pretty_print.rb +22 -0
  154. data/test/test_radiobutton.rb +75 -0
  155. data/test/test_redirect_limit_reached.rb +41 -0
  156. data/test/test_redirect_verb_handling.rb +45 -0
  157. data/test/test_referer.rb +39 -0
  158. data/test/test_relative_links.rb +40 -0
  159. data/test/test_request.rb +13 -0
  160. data/test/test_response_code.rb +52 -0
  161. data/test/test_save_file.rb +48 -0
  162. data/test/test_scheme.rb +48 -0
  163. data/test/test_select.rb +106 -0
  164. data/test/test_select_all.rb +15 -0
  165. data/test/test_select_none.rb +15 -0
  166. data/test/test_select_noopts.rb +16 -0
  167. data/test/test_set_fields.rb +44 -0
  168. data/test/test_ssl_server.rb +20 -0
  169. data/test/test_subclass.rb +14 -0
  170. data/test/test_textarea.rb +45 -0
  171. data/test/test_upload.rb +109 -0
  172. data/test/test_verbs.rb +25 -0
  173. metadata +314 -0
@@ -0,0 +1,18 @@
1
+ module WWW
2
+ class Mechanize
3
+ # Thrown when too many redirects are sent
4
+ class RedirectLimitReachedError < RuntimeError
5
+ attr_reader :page, :response_code, :redirects
6
+ def initialize(page, redirects)
7
+ @page = page
8
+ @redirects = redirects
9
+ @response_code = page.code
10
+ end
11
+
12
+ def to_s
13
+ "Maximum redirect limit (#{redirects}) reached"
14
+ end
15
+ alias :inspect :to_s
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module WWW
2
+ class Mechanize
3
+ # Thrown when a POST, PUT, or DELETE request results in a redirect
4
+ # see RFC 2616 10.3.2, 10.3.3 http://www.ietf.org/rfc/rfc2616.txt
5
+ class RedirectNotGetOrHeadError < RuntimeError
6
+ attr_reader :page, :response_code, :verb, :uri
7
+ def initialize(page, verb)
8
+ @page = page
9
+ @verb = verb
10
+ @uri = page.uri
11
+ @response_code = page.code
12
+ end
13
+
14
+ def to_s
15
+ "#{@response_code} redirect received after a #{@verb} request"
16
+ end
17
+ alias :inspect :to_s
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module WWW
2
+ class Mechanize
3
+ # =Synopsis
4
+ # This error is thrown when Mechanize encounters a response code it does
5
+ # not know how to handle. Currently, this exception will be thrown
6
+ # if Mechanize encounters response codes other than 200, 301, or 302.
7
+ # Any other response code is up to the user to handle.
8
+ class ResponseCodeError < RuntimeError
9
+ attr_reader :response_code
10
+ attr_reader :page
11
+
12
+ def initialize(page)
13
+ @page = page
14
+ @response_code = page.code
15
+ end
16
+
17
+ def to_s
18
+ "#{response_code} => #{Net::HTTPResponse::CODE_TO_OBJ[response_code]}"
19
+ end
20
+
21
+ def inspect; to_s; end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,10 @@
1
+ module WWW
2
+ class Mechanize
3
+ class UnsupportedSchemeError < RuntimeError
4
+ attr_accessor :scheme
5
+ def initialize(scheme)
6
+ @scheme = scheme
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,76 @@
1
+ require 'cgi'
2
+
3
+ module WWW
4
+ class Mechanize
5
+ class Util
6
+ CODE_DIC = {
7
+ :JIS => "ISO-2022-JP",
8
+ :EUC => "EUC-JP",
9
+ :SJIS => "SHIFT_JIS",
10
+ :UTF8 => "UTF-8", :UTF16 => "UTF-16", :UTF32 => "UTF-32"}
11
+
12
+ class << self
13
+ def build_query_string(parameters, enc=nil)
14
+ parameters.map { |k,v|
15
+ if k
16
+ # WEBrick::HTTP.escape* has some problems about m17n on ruby-1.9.*.
17
+ [CGI.escape(k.to_s), CGI.escape(v.to_s)].join("=")
18
+ =begin
19
+ [WEBrick::HTTPUtils.escape_form(k.to_s),
20
+ WEBrick::HTTPUtils.escape_form(v.to_s)].join("=")
21
+ =end
22
+
23
+ end
24
+ }.compact.join('&')
25
+ end
26
+
27
+ def to_native_charset(s, code=nil)
28
+ if Mechanize.html_parser == Nokogiri::HTML
29
+ return unless s
30
+ code ||= detect_charset(s)
31
+ Iconv.iconv("UTF-8", code, s).join("")
32
+ else
33
+ s
34
+ end
35
+ end
36
+
37
+ def from_native_charset(s, code)
38
+ if Mechanize.html_parser == Nokogiri::HTML
39
+ return unless s
40
+ Iconv.iconv(code, "UTF-8", s).join("")
41
+ else
42
+ return s
43
+ end
44
+ end
45
+
46
+ def html_unescape(s)
47
+ return s unless s
48
+ s.gsub(/&(\w+|#[0-9]+);/) { |match|
49
+ number = case match
50
+ when /&(\w+);/
51
+ Mechanize.html_parser::NamedCharacters[$1]
52
+ when /&#([0-9]+);/
53
+ $1.to_i
54
+ end
55
+
56
+ number ? ([number].pack('U') rescue match) : match
57
+ }
58
+ end
59
+
60
+ def detect_charset(src)
61
+ tmp = NKF.guess(src || "<html></html>")
62
+ if RUBY_VERSION >= "1.9.0"
63
+ enc = tmp.to_s.upcase
64
+ else
65
+ enc = NKF.constants.find{|c|
66
+ NKF.const_get(c) == tmp
67
+ }
68
+ enc = CODE_DIC[enc.intern]
69
+ end
70
+ enc || "ISO-8859-1"
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
data/mechanize.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{mechanize}
5
+ s.version = "0.9.3.20090623142847"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Aaron Patterson", "Mike Dalessio"]
9
+ s.date = %q{2009-06-23}
10
+ s.description = %q{The Mechanize library is used for automating interaction with websites.
11
+ Mechanize automatically stores and sends cookies, follows redirects,
12
+ can follow links, and submit forms. Form fields can be populated and
13
+ submitted. Mechanize also keeps track of the sites that you have visited as
14
+ a history.}
15
+ s.email = ["aaronp@rubyforge.org", "mike.dalessio@gmail.com"]
16
+ s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "README.rdoc"]
17
+ s.files = ["CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "examples/flickr_upload.rb", "examples/mech-dump.rb", "examples/proxy_req.rb", "examples/rubyforge.rb", "examples/spider.rb", "lib/mechanize.rb", "lib/www/mechanize.rb", "lib/www/mechanize/chain.rb", "lib/www/mechanize/chain/auth_headers.rb", "lib/www/mechanize/chain/body_decoding_handler.rb", "lib/www/mechanize/chain/connection_resolver.rb", "lib/www/mechanize/chain/custom_headers.rb", "lib/www/mechanize/chain/handler.rb", "lib/www/mechanize/chain/header_resolver.rb", "lib/www/mechanize/chain/parameter_resolver.rb", "lib/www/mechanize/chain/post_connect_hook.rb", "lib/www/mechanize/chain/pre_connect_hook.rb", "lib/www/mechanize/chain/request_resolver.rb", "lib/www/mechanize/chain/response_body_parser.rb", "lib/www/mechanize/chain/response_header_handler.rb", "lib/www/mechanize/chain/response_reader.rb", "lib/www/mechanize/chain/ssl_resolver.rb", "lib/www/mechanize/chain/uri_resolver.rb", "lib/www/mechanize/content_type_error.rb", "lib/www/mechanize/cookie.rb", "lib/www/mechanize/cookie_jar.rb", "lib/www/mechanize/file.rb", "lib/www/mechanize/file_response.rb", "lib/www/mechanize/file_saver.rb", "lib/www/mechanize/form.rb", "lib/www/mechanize/form/button.rb", "lib/www/mechanize/form/check_box.rb", "lib/www/mechanize/form/field.rb", "lib/www/mechanize/form/file_upload.rb", "lib/www/mechanize/form/image_button.rb", "lib/www/mechanize/form/multi_select_list.rb", "lib/www/mechanize/form/option.rb", "lib/www/mechanize/form/radio_button.rb", "lib/www/mechanize/form/select_list.rb", "lib/www/mechanize/headers.rb", "lib/www/mechanize/history.rb", "lib/www/mechanize/inspect.rb", "lib/www/mechanize/monkey_patch.rb", "lib/www/mechanize/page.rb", "lib/www/mechanize/page/base.rb", "lib/www/mechanize/page/frame.rb", "lib/www/mechanize/page/link.rb", "lib/www/mechanize/page/meta.rb", "lib/www/mechanize/pluggable_parsers.rb", "lib/www/mechanize/redirect_limit_reached_error.rb", "lib/www/mechanize/redirect_not_get_or_head_error.rb", "lib/www/mechanize/response_code_error.rb", "lib/www/mechanize/unsupported_scheme_error.rb", "lib/www/mechanize/util.rb", "mechanize.gemspec", "test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/data/htpasswd", "test/data/server.crt", "test/data/server.csr", "test/data/server.key", "test/data/server.pem", "test/helper.rb", "test/htdocs/alt_text.html", "test/htdocs/bad_form_test.html", "test/htdocs/button.jpg", "test/htdocs/empty_form.html", "test/htdocs/file_upload.html", "test/htdocs/find_link.html", "test/htdocs/form_multi_select.html", "test/htdocs/form_multival.html", "test/htdocs/form_no_action.html", "test/htdocs/form_no_input_name.html", "test/htdocs/form_select.html", "test/htdocs/form_select_all.html", "test/htdocs/form_select_none.html", "test/htdocs/form_select_noopts.html", "test/htdocs/form_set_fields.html", "test/htdocs/form_test.html", "test/htdocs/frame_test.html", "test/htdocs/google.html", "test/htdocs/iframe_test.html", "test/htdocs/index.html", "test/htdocs/link with space.html", "test/htdocs/meta_cookie.html", "test/htdocs/no_title_test.html", "test/htdocs/relative/tc_relative_links.html", "test/htdocs/tc_bad_links.html", "test/htdocs/tc_base_link.html", "test/htdocs/tc_blank_form.html", "test/htdocs/tc_checkboxes.html", "test/htdocs/tc_encoded_links.html", "test/htdocs/tc_follow_meta.html", "test/htdocs/tc_form_action.html", "test/htdocs/tc_links.html", "test/htdocs/tc_no_attributes.html", "test/htdocs/tc_pretty_print.html", "test/htdocs/tc_radiobuttons.html", "test/htdocs/tc_referer.html", "test/htdocs/tc_relative_links.html", "test/htdocs/tc_textarea.html", "test/htdocs/unusual______.html", "test/servlets.rb", "test/ssl_server.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb", "test/chain/test_auth_headers.rb", "test/chain/test_header_resolver.rb", "test/test_meta.rb"]
18
+ s.homepage = %q{http://mechanize.rubyforge.org/}
19
+ s.rdoc_options = ["--main", "README.rdoc"]
20
+ s.require_paths = ["lib"]
21
+ s.rubyforge_project = %q{mechanize}
22
+ s.rubygems_version = %q{1.3.4}
23
+ s.summary = %q{Mechanize provides automated web-browsing}
24
+ s.test_files = ["test/chain/test_argument_validator.rb", "test/chain/test_auth_headers.rb", "test/chain/test_custom_headers.rb", "test/chain/test_header_resolver.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_meta.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
25
+
26
+ if s.respond_to? :specification_version then
27
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
28
+ s.specification_version = 3
29
+
30
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
31
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.2.1"])
32
+ s.add_development_dependency(%q<hoe>, [">= 2.2.0"])
33
+ else
34
+ s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
35
+ s.add_dependency(%q<hoe>, [">= 2.2.0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
39
+ s.add_dependency(%q<hoe>, [">= 2.2.0"])
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestURIResolver < Test::Unit::TestCase
4
+ def test_handle
5
+ v = WWW::Mechanize::Chain.new([
6
+ WWW::Mechanize::Chain::URIResolver.new(Hash.new { |h,k|
7
+ h[k] = lambda { |u,r| u }
8
+ })
9
+ ])
10
+ assert_raises(ArgumentError) { v.handle({}) }
11
+ assert_nothing_raised { v.handle({:uri => 'http://google.com/'}) }
12
+ assert_raises(RuntimeError) { v.handle({:uri => 'google'}) }
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestAuthHeaders < Test::Unit::TestCase
4
+ def test_auth
5
+ url = URI.parse('http://www.anthonychaves.net/tests.xml')
6
+ digest = %Q!Digest realm="www.anthonychaves.net", qop="auth", algorithm=MD5, nonce="MTI0NTEyMTYyNjo0ZTY2MjhlZWMyZmM1ZjA0M2Y1Njc1MGU0YTA2MWY5OQ==", opaque="9f455d4e71e8d46a6d3aaef8bf8b0d9e"!
7
+ v = WWW::Mechanize::Chain.new([
8
+ WWW::Mechanize::Chain::AuthHeaders.new({(url.host) => :digest}, "anthony", "password", digest)
9
+ ])
10
+
11
+ hash = {
12
+ :request => Net::HTTP::Get.new(url.request_uri),
13
+ :uri => url
14
+ }
15
+ v.handle(hash)
16
+ actual_authorization = hash[:request]['Authorization']
17
+ # The chain gave our request an Authorization header with client-generated values and derivatives.
18
+ # They should be scrubbed before comparing to the expected result because they change
19
+ # on each invokation
20
+ actual_authorization.gsub!(/cnonce=\"\w+?\"/, "cnonce=\"scrubbed_cnonce\"").gsub!(/response=\"\w+?\"/, "response=\"scrubbed_response\"")
21
+
22
+ expected_authorization = %Q!Digest username="anthony", qop=auth, uri="/tests.xml", algorithm="MD5", opaque="9f455d4e71e8d46a6d3aaef8bf8b0d9e", nonce="MTI0NTEyMTYyNjo0ZTY2MjhlZWMyZmM1ZjA0M2Y1Njc1MGU0YTA2MWY5OQ==", realm="www.anthonychaves.net", nc=00000001, cnonce="scrubbed_cnonce", response="scrubbed_response"!
23
+ assert_equal(expected_authorization, actual_authorization)
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestCustomHeaders < Test::Unit::TestCase
4
+ def test_handle
5
+ v = WWW::Mechanize::Chain.new([
6
+ WWW::Mechanize::Chain::CustomHeaders.new
7
+ ])
8
+ url = URI.parse('http://tenderlovemaking.com/')
9
+ hash = {
10
+ :request => Net::HTTP::Get.new(url.request_uri),
11
+ :headers => { 'Content-Length' => 300 }
12
+ }
13
+ v.handle(hash)
14
+ headers = hash[:request].to_hash
15
+ assert(headers.key?('content-length'))
16
+ assert_equal([300], headers['content-length'])
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestHeaderResolver < Test::Unit::TestCase
4
+ def setup
5
+ @chain = WWW::Mechanize::Chain.new([
6
+ WWW::Mechanize::Chain::HeaderResolver.new(
7
+ true,
8
+ 300,
9
+ WWW::Mechanize::CookieJar.new,
10
+ 'foobar',
11
+ {
12
+ 'hello' => 'world',
13
+ 'Content-Type' => 'utf-8'
14
+ }
15
+ )
16
+ ])
17
+ end
18
+
19
+ def test_handle
20
+ hash = {
21
+ :request => {},
22
+ :uri => URI.parse('http://google.com/')
23
+ }
24
+ @chain.handle(hash)
25
+ assert_equal 'world', hash[:request]['hello']
26
+ assert_equal 'utf-8', hash[:request]['Content-Type']
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestParameterResolver < Test::Unit::TestCase
4
+ def test_handle_get
5
+ v = WWW::Mechanize::Chain.new([
6
+ WWW::Mechanize::Chain::ParameterResolver.new
7
+ ])
8
+ hash = {
9
+ :uri => URI.parse('http://google.com/'),
10
+ :params => { :q => 'hello' },
11
+ :verb => :get
12
+ }
13
+ assert_nothing_raised {
14
+ v.handle(hash)
15
+ }
16
+ assert_equal('q=hello', hash[:uri].query)
17
+ assert_equal([], hash[:params])
18
+ end
19
+
20
+ def test_handle_post
21
+ v = WWW::Mechanize::Chain.new([
22
+ WWW::Mechanize::Chain::ParameterResolver.new
23
+ ])
24
+ hash = {
25
+ :uri => URI.parse('http://google.com/'),
26
+ :params => { :q => 'hello' },
27
+ :verb => :post
28
+ }
29
+ assert_nothing_raised {
30
+ v.handle(hash)
31
+ }
32
+ assert_equal('', hash[:uri].query.to_s)
33
+ assert_equal({ :q => 'hello' }, hash[:params])
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestRequestResolver < Test::Unit::TestCase
4
+ def test_handle_get
5
+ v = WWW::Mechanize::Chain.new([
6
+ WWW::Mechanize::Chain::RequestResolver.new
7
+ ])
8
+ hash = {
9
+ :uri => URI.parse('http://google.com'),
10
+ :verb => :get
11
+ }
12
+ assert_nothing_raised { v.handle(hash) }
13
+ assert_kind_of(Net::HTTP::Get, hash[:request])
14
+ assert_equal('/', hash[:request].path)
15
+ end
16
+
17
+ def test_handle_post
18
+ v = WWW::Mechanize::Chain.new([
19
+ WWW::Mechanize::Chain::RequestResolver.new
20
+ ])
21
+ hash = {
22
+ :uri => URI.parse('http://google.com'),
23
+ :verb => :post
24
+ }
25
+ assert_nothing_raised { v.handle(hash) }
26
+ assert_kind_of(Net::HTTP::Post, hash[:request])
27
+ assert_equal('/', hash[:request].path)
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ class TestResponseReader < Test::Unit::TestCase
4
+ def test_handle_bad_response_code
5
+ response = Object.new
6
+ class << response
7
+ def read_body
8
+ end
9
+ def code; 999; end
10
+ end
11
+
12
+ v = WWW::Mechanize::Chain.new([
13
+ WWW::Mechanize::Chain::ResponseReader.new(response)
14
+ ])
15
+ assert_raises(WWW::Mechanize::ResponseCodeError) {
16
+ begin
17
+ v.handle({})
18
+ rescue Exception => x
19
+ assert_equal(999, x.response_code)
20
+ raise x
21
+ end
22
+ }
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ mech:44E/qORekFV0E
@@ -0,0 +1,16 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICmzCCAgQCCQDq2kM3TCIM0DANBgkqhkiG9w0BAQQFADCBkTELMAkGA1UEBhMC
3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