mechanize 0.7.6 → 0.7.7

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 (65) hide show
  1. data/EXAMPLES.txt +87 -40
  2. data/History.txt +21 -0
  3. data/Manifest.txt +51 -47
  4. data/lib/www/mechanize.rb +88 -22
  5. data/lib/www/mechanize/cookie.rb +1 -1
  6. data/lib/www/mechanize/form.rb +27 -14
  7. data/lib/www/mechanize/form/multi_select_list.rb +1 -1
  8. data/lib/www/mechanize/monkey_patch.rb +3 -0
  9. data/lib/www/mechanize/page.rb +20 -16
  10. data/lib/www/mechanize/page/link.rb +2 -2
  11. data/lib/www/mechanize/redirect_limit_reached_error.rb +18 -0
  12. data/test/helper.rb +14 -0
  13. data/test/htdocs/meta_cookie.html +11 -0
  14. data/test/servlets.rb +10 -0
  15. data/test/{tc_authenticate.rb → test_authenticate.rb} +0 -0
  16. data/test/{tc_bad_links.rb → test_bad_links.rb} +0 -0
  17. data/test/{tc_blank_form.rb → test_blank_form.rb} +0 -0
  18. data/test/{tc_checkboxes.rb → test_checkboxes.rb} +0 -0
  19. data/test/{tc_cookie_class.rb → test_cookie_class.rb} +9 -0
  20. data/test/{tc_cookie_jar.rb → test_cookie_jar.rb} +0 -0
  21. data/test/{tc_cookies.rb → test_cookies.rb} +6 -0
  22. data/test/{tc_encoded_links.rb → test_encoded_links.rb} +1 -1
  23. data/test/{tc_errors.rb → test_errors.rb} +0 -0
  24. data/test/{tc_follow_meta.rb → test_follow_meta.rb} +0 -0
  25. data/test/{tc_form_action.rb → test_form_action.rb} +1 -1
  26. data/test/{tc_form_as_hash.rb → test_form_as_hash.rb} +0 -0
  27. data/test/{tc_form_button.rb → test_form_button.rb} +0 -0
  28. data/test/{tc_form_no_inputname.rb → test_form_no_inputname.rb} +0 -0
  29. data/test/{tc_forms.rb → test_forms.rb} +0 -0
  30. data/test/{tc_frames.rb → test_frames.rb} +0 -0
  31. data/test/test_get_headers.rb +45 -0
  32. data/test/{tc_gzipping.rb → test_gzipping.rb} +0 -0
  33. data/test/test_hash_api.rb +42 -0
  34. data/test/{tc_history.rb → test_history.rb} +0 -0
  35. data/test/{tc_history_added.rb → test_history_added.rb} +0 -0
  36. data/test/{tc_html_unscape_forms.rb → test_html_unscape_forms.rb} +0 -0
  37. data/test/{tc_if_modified_since.rb → test_if_modified_since.rb} +0 -0
  38. data/test/{tc_keep_alive.rb → test_keep_alive.rb} +0 -0
  39. data/test/{tc_links.rb → test_links.rb} +0 -0
  40. data/test/{tc_mech.rb → test_mech.rb} +2 -2
  41. data/test/{tc_mechanize_file.rb → test_mechanize_file.rb} +0 -0
  42. data/test/{tc_multi_select.rb → test_multi_select.rb} +0 -0
  43. data/test/{tc_no_attributes.rb → test_no_attributes.rb} +0 -0
  44. data/test/{tc_option.rb → test_option.rb} +0 -0
  45. data/test/{tc_page.rb → test_page.rb} +17 -0
  46. data/test/{tc_pluggable_parser.rb → test_pluggable_parser.rb} +0 -0
  47. data/test/{tc_post_form.rb → test_post_form.rb} +0 -0
  48. data/test/{tc_pretty_print.rb → test_pretty_print.rb} +0 -0
  49. data/test/{tc_radiobutton.rb → test_radiobutton.rb} +0 -0
  50. data/test/test_redirect_limit_reached.rb +41 -0
  51. data/test/{tc_referer.rb → test_referer.rb} +0 -0
  52. data/test/{tc_relative_links.rb → test_relative_links.rb} +0 -0
  53. data/test/{tc_response_code.rb → test_response_code.rb} +0 -0
  54. data/test/{tc_save_file.rb → test_save_file.rb} +0 -0
  55. data/test/{tc_select.rb → test_select.rb} +0 -0
  56. data/test/{tc_select_all.rb → test_select_all.rb} +0 -0
  57. data/test/{tc_select_none.rb → test_select_none.rb} +0 -0
  58. data/test/{tc_select_noopts.rb → test_select_noopts.rb} +0 -0
  59. data/test/{tc_set_fields.rb → test_set_fields.rb} +8 -0
  60. data/test/{tc_ssl_server.rb → test_ssl_server.rb} +0 -0
  61. data/test/{tc_subclass.rb → test_subclass.rb} +0 -0
  62. data/test/{tc_textarea.rb → test_textarea.rb} +0 -0
  63. data/test/{tc_upload.rb → test_upload.rb} +11 -11
  64. metadata +106 -52
  65. data/test/test_all.rb +0 -5
File without changes
File without changes
File without changes
File without changes
@@ -172,7 +172,7 @@ class TestMechMethods < Test::Unit::TestCase
172
172
  def test_click_hpricot
173
173
  page = @agent.get("http://localhost/frame_test.html")
174
174
 
175
- link = (page/"a[@class=bar]").first
175
+ link = (page/"//a[@class='bar']").first
176
176
  assert_not_nil(link)
177
177
  page = @agent.click(link)
178
178
  assert_equal("http://localhost/form_test.html",
@@ -182,7 +182,7 @@ class TestMechMethods < Test::Unit::TestCase
182
182
  def test_click_hpricot_frame
183
183
  page = @agent.get("http://localhost/frame_test.html")
184
184
 
185
- link = (page/"frame[@name=frame2]").first
185
+ link = (page/"//frame[@name='frame2']").first
186
186
  assert_not_nil(link)
187
187
  page = @agent.click(link)
188
188
  assert_equal("http://localhost/form_test.html",
File without changes
File without changes
File without changes
@@ -23,4 +23,21 @@ class TestPage < Test::Unit::TestCase
23
23
  page = @agent.get("http://localhost/no_title_test.html")
24
24
  assert_equal(nil, page.title)
25
25
  end
26
+
27
+ def test_find_form_with_hash
28
+ page = @agent.get("http://localhost/tc_form_action.html")
29
+ form = page.form(:name => 'post_form1')
30
+ assert form
31
+ yielded = false
32
+ form = page.form(:name => 'post_form1') { |f|
33
+ yielded = true
34
+ assert f
35
+ assert_equal(form, f)
36
+ }
37
+ assert yielded
38
+
39
+ form_by_action = page.form(:action => '/form_post?a=b&b=c')
40
+ assert form_by_action
41
+ assert_equal(form, form_by_action)
42
+ end
26
43
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestRedirectLimitReached < Test::Unit::TestCase
4
+ include WWW
5
+
6
+ def setup
7
+ @agent = WWW::Mechanize.new
8
+ end
9
+
10
+ def test_to_s
11
+ page = MechTestHelper.fake_page(@agent)
12
+ error = Mechanize::RedirectLimitReachedError.new(page, 10)
13
+ assert_match(/10/, error.to_s)
14
+ end
15
+
16
+ def test_get_default_redirects
17
+ assert_raises(Mechanize::RedirectLimitReachedError) {
18
+ begin
19
+ @agent.get('http://localhost/infinite_redirect')
20
+ rescue Mechanize::RedirectLimitReachedError => ex
21
+ assert_equal(@agent.redirection_limit, ex.redirects)
22
+ assert_equal("q=#{@agent.redirection_limit}", ex.page.uri.query)
23
+ raise ex
24
+ end
25
+ }
26
+ end
27
+
28
+ def test_get_2_redirects
29
+ @agent.redirection_limit = 2
30
+ assert_raises(Mechanize::RedirectLimitReachedError) {
31
+ begin
32
+ @agent.get('http://localhost/infinite_redirect')
33
+ rescue Mechanize::RedirectLimitReachedError => ex
34
+ assert_equal(2, ex.redirects)
35
+ assert_equal(@agent.redirection_limit, ex.redirects)
36
+ assert_equal("q=#{@agent.redirection_limit}", ex.page.uri.query)
37
+ raise ex
38
+ end
39
+ }
40
+ end
41
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -29,6 +29,14 @@ class TestSetFields < Test::Unit::TestCase
29
29
  assert_equal('Ham', @form.fields.name('green[eggs]').first.value)
30
30
  end
31
31
 
32
+ def test_set_multiple_duplicate_fields
33
+ page = @agent.get("http://localhost/form_multival.html")
34
+ form = page.form('post_form')
35
+ form.set_fields( :first => { 0 => 'a', 1 => 'b' } )
36
+ assert_equal('a', form.fields.name('first')[0].value)
37
+ assert_equal('b', form.fields.name('first')[1].value)
38
+ end
39
+
32
40
  def test_set_second_field
33
41
  @form.set_fields( :first_name => ['Aaron', 1] )
34
42
  assert_equal('Aaron', @form.fields.name('first_name')[1].value)
File without changes
File without changes
File without changes
@@ -22,14 +22,14 @@ class UploadMechTest < Test::Unit::TestCase
22
22
  assert_equal('multipart/form-data', @page.forms[0].enctype)
23
23
 
24
24
  form = @page.forms.first
25
- form.file_uploads.first.file_name = "#{BASE_DIR}/test_all.rb"
25
+ form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
26
26
  form.file_uploads.first.mime_type = "text/plain"
27
27
  form.file_uploads.first.file_data = "Hello World\n\n"
28
28
 
29
29
  @page = @agent.submit(form)
30
30
 
31
31
  assert_match(
32
- "Content-Disposition: form-data; name=\"userfile1\"; filename=\"test_all.rb\"",
32
+ "Content-Disposition: form-data; name=\"userfile1\"; filename=\"helper.rb\"",
33
33
  @page.body
34
34
  )
35
35
  assert_match(
@@ -45,14 +45,14 @@ class UploadMechTest < Test::Unit::TestCase
45
45
  assert_equal('multipart/form-data', @page.forms[1].enctype)
46
46
 
47
47
  form = @page.forms[1]
48
- form.file_uploads.first.file_name = "#{BASE_DIR}/test_all.rb"
48
+ form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
49
49
  form.file_uploads.first.mime_type = "text/plain"
50
50
  form.file_uploads.first.file_data = "Hello World\n\n"
51
51
 
52
52
  @page = @agent.submit(form)
53
53
 
54
54
  assert_match(
55
- "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"test_all.rb\"",
55
+ "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
56
56
  @page.body
57
57
  )
58
58
  end
@@ -61,13 +61,13 @@ class UploadMechTest < Test::Unit::TestCase
61
61
  assert_equal('multipart/form-data', @page.forms[1].enctype)
62
62
 
63
63
  form = @page.forms[1]
64
- form.file_uploads.first.file_name = "#{BASE_DIR}/test_all.rb"
64
+ form.file_uploads.first.file_name = "#{BASE_DIR}/helper.rb"
65
65
 
66
66
  @page = @agent.submit(form)
67
67
 
68
- contents = File.open("#{BASE_DIR}/test_all.rb", 'rb') { |f| f.read }
68
+ contents = File.open("#{BASE_DIR}/helper.rb", 'rb') { |f| f.read }
69
69
  assert_match(
70
- "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"test_all.rb\"",
70
+ "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
71
71
  @page.body
72
72
  )
73
73
  assert_match(contents, @page.body)
@@ -77,14 +77,14 @@ class UploadMechTest < Test::Unit::TestCase
77
77
  assert_equal('multipart/form-data', @page.forms[1].enctype)
78
78
 
79
79
  form = @page.forms[1]
80
- form.file_uploads.first.file_name = "#{BASE_DIR}/test_all.rb"
81
- form.file_uploads.first.file_data = File.open("#{BASE_DIR}/test_all.rb", 'rb')
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
82
 
83
83
  @page = @agent.submit(form)
84
84
 
85
- contents = File.open("#{BASE_DIR}/test_all.rb", 'rb') { |f| f.read }
85
+ contents = File.open("#{BASE_DIR}/helper.rb", 'rb') { |f| f.read }
86
86
  assert_match(
87
- "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"test_all.rb\"",
87
+ "Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"helper.rb\"",
88
88
  @page.body
89
89
  )
90
90
  assert_match(contents, @page.body)
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.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-11 00:00:00 -07:00
12
+ date: 2008-07-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hpricot
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,12 +24,13 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: hoe
27
+ type: :development
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
29
31
  - - ">="
30
32
  - !ruby/object:Gem::Version
31
- version: 1.5.1
33
+ version: 1.7.0
32
34
  version:
33
35
  description: The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.
34
36
  email: aaronp@rubyforge.org
@@ -88,6 +90,7 @@ files:
88
90
  - lib/www/mechanize/page/link.rb
89
91
  - lib/www/mechanize/page/meta.rb
90
92
  - lib/www/mechanize/pluggable_parsers.rb
93
+ - lib/www/mechanize/redirect_limit_reached_error.rb
91
94
  - lib/www/mechanize/response_code_error.rb
92
95
  - lib/www/mechanize/unsupported_scheme_error.rb
93
96
  - test/data/htpasswd
@@ -117,6 +120,7 @@ files:
117
120
  - test/htdocs/iframe_test.html
118
121
  - test/htdocs/index.html
119
122
  - test/htdocs/link with space.html
123
+ - test/htdocs/meta_cookie.html
120
124
  - test/htdocs/no_title_test.html
121
125
  - test/htdocs/relative/tc_relative_links.html
122
126
  - test/htdocs/tc_bad_links.html
@@ -136,53 +140,55 @@ files:
136
140
  - test/htdocs/unusual______.html
137
141
  - test/servlets.rb
138
142
  - test/ssl_server.rb
139
- - test/tc_authenticate.rb
140
- - test/tc_bad_links.rb
141
- - test/tc_blank_form.rb
142
- - test/tc_checkboxes.rb
143
- - test/tc_cookie_class.rb
144
- - test/tc_cookie_jar.rb
145
- - test/tc_cookies.rb
146
- - test/tc_encoded_links.rb
147
- - test/tc_errors.rb
148
- - test/tc_follow_meta.rb
149
- - test/tc_form_action.rb
150
- - test/tc_form_as_hash.rb
151
- - test/tc_form_button.rb
152
- - test/tc_form_no_inputname.rb
153
- - test/tc_forms.rb
154
- - test/tc_frames.rb
155
- - test/tc_gzipping.rb
156
- - test/tc_history.rb
157
- - test/tc_history_added.rb
158
- - test/tc_html_unscape_forms.rb
159
- - test/tc_if_modified_since.rb
160
- - test/tc_keep_alive.rb
161
- - test/tc_links.rb
162
- - test/tc_mech.rb
163
- - test/tc_mechanize_file.rb
164
- - test/tc_multi_select.rb
165
- - test/tc_no_attributes.rb
166
- - test/tc_option.rb
167
- - test/tc_page.rb
168
- - test/tc_pluggable_parser.rb
169
- - test/tc_post_form.rb
170
- - test/tc_pretty_print.rb
171
- - test/tc_radiobutton.rb
172
- - test/tc_referer.rb
173
- - test/tc_relative_links.rb
174
- - test/tc_response_code.rb
175
- - test/tc_save_file.rb
176
- - test/tc_select.rb
177
- - test/tc_select_all.rb
178
- - test/tc_select_none.rb
179
- - test/tc_select_noopts.rb
180
- - test/tc_set_fields.rb
181
- - test/tc_ssl_server.rb
182
- - test/tc_subclass.rb
183
- - test/tc_textarea.rb
184
- - test/tc_upload.rb
185
- - test/test_all.rb
143
+ - test/test_authenticate.rb
144
+ - test/test_bad_links.rb
145
+ - test/test_blank_form.rb
146
+ - test/test_checkboxes.rb
147
+ - test/test_cookie_class.rb
148
+ - test/test_cookie_jar.rb
149
+ - test/test_cookies.rb
150
+ - test/test_encoded_links.rb
151
+ - test/test_errors.rb
152
+ - test/test_follow_meta.rb
153
+ - test/test_form_action.rb
154
+ - test/test_form_as_hash.rb
155
+ - test/test_form_button.rb
156
+ - test/test_form_no_inputname.rb
157
+ - test/test_forms.rb
158
+ - test/test_frames.rb
159
+ - test/test_get_headers.rb
160
+ - test/test_gzipping.rb
161
+ - test/test_hash_api.rb
162
+ - test/test_history.rb
163
+ - test/test_history_added.rb
164
+ - test/test_html_unscape_forms.rb
165
+ - test/test_if_modified_since.rb
166
+ - test/test_keep_alive.rb
167
+ - test/test_links.rb
168
+ - test/test_mech.rb
169
+ - test/test_mechanize_file.rb
170
+ - test/test_multi_select.rb
171
+ - test/test_no_attributes.rb
172
+ - test/test_option.rb
173
+ - test/test_page.rb
174
+ - test/test_pluggable_parser.rb
175
+ - test/test_post_form.rb
176
+ - test/test_pretty_print.rb
177
+ - test/test_radiobutton.rb
178
+ - test/test_redirect_limit_reached.rb
179
+ - test/test_referer.rb
180
+ - test/test_relative_links.rb
181
+ - test/test_response_code.rb
182
+ - test/test_save_file.rb
183
+ - test/test_select.rb
184
+ - test/test_select_all.rb
185
+ - test/test_select_none.rb
186
+ - test/test_select_noopts.rb
187
+ - test/test_set_fields.rb
188
+ - test/test_ssl_server.rb
189
+ - test/test_subclass.rb
190
+ - test/test_textarea.rb
191
+ - test/test_upload.rb
186
192
  has_rdoc: true
187
193
  homepage: " http://mechanize.rubyforge.org/"
188
194
  post_install_message:
@@ -206,9 +212,57 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
212
  requirements: []
207
213
 
208
214
  rubyforge_project: mechanize
209
- rubygems_version: 1.1.0
215
+ rubygems_version: 1.2.0
210
216
  signing_key:
211
217
  specification_version: 2
212
218
  summary: Mechanize provides automated web-browsing
213
219
  test_files:
214
- - test/test_all.rb
220
+ - test/test_authenticate.rb
221
+ - test/test_bad_links.rb
222
+ - test/test_blank_form.rb
223
+ - test/test_checkboxes.rb
224
+ - test/test_cookie_class.rb
225
+ - test/test_cookie_jar.rb
226
+ - test/test_cookies.rb
227
+ - test/test_encoded_links.rb
228
+ - test/test_errors.rb
229
+ - test/test_follow_meta.rb
230
+ - test/test_form_action.rb
231
+ - test/test_form_as_hash.rb
232
+ - test/test_form_button.rb
233
+ - test/test_form_no_inputname.rb
234
+ - test/test_forms.rb
235
+ - test/test_frames.rb
236
+ - test/test_get_headers.rb
237
+ - test/test_gzipping.rb
238
+ - test/test_hash_api.rb
239
+ - test/test_history.rb
240
+ - test/test_history_added.rb
241
+ - test/test_html_unscape_forms.rb
242
+ - test/test_if_modified_since.rb
243
+ - test/test_keep_alive.rb
244
+ - test/test_links.rb
245
+ - test/test_mech.rb
246
+ - test/test_mechanize_file.rb
247
+ - test/test_multi_select.rb
248
+ - test/test_no_attributes.rb
249
+ - test/test_option.rb
250
+ - test/test_page.rb
251
+ - test/test_pluggable_parser.rb
252
+ - test/test_post_form.rb
253
+ - test/test_pretty_print.rb
254
+ - test/test_radiobutton.rb
255
+ - test/test_redirect_limit_reached.rb
256
+ - test/test_referer.rb
257
+ - test/test_relative_links.rb
258
+ - test/test_response_code.rb
259
+ - test/test_save_file.rb
260
+ - test/test_select.rb
261
+ - test/test_select_all.rb
262
+ - test/test_select_none.rb
263
+ - test/test_select_noopts.rb
264
+ - test/test_set_fields.rb
265
+ - test/test_ssl_server.rb
266
+ - test/test_subclass.rb
267
+ - test/test_textarea.rb
268
+ - test/test_upload.rb
data/test/test_all.rb DELETED
@@ -1,5 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/tc_*.rb"].
2
- reject { |f| f == __FILE__ }.
3
- collect { |f| File.basename(f, ".rb") }.
4
- each { |f| require f }
5
-