mechanize 0.6.2 → 0.6.3
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 +15 -0
- data/NOTES +13 -0
- data/lib/mechanize.rb +11 -13
- data/lib/mechanize/form.rb +30 -4
- data/lib/mechanize/hpricot.rb +1 -8
- data/lib/mechanize/mech_version.rb +1 -1
- data/test/htdocs/empty_form.html +6 -0
- data/test/htdocs/tc_encoded_links.html +5 -0
- data/test/htdocs/tc_form_action.html +48 -0
- data/test/tc_encoded_links.rb +27 -0
- data/test/tc_form_action.rb +52 -0
- data/test/tc_form_as_hash.rb +71 -0
- data/test/tc_forms.rb +17 -14
- data/test/tc_upload.rb +28 -33
- data/test/ts_mech.rb +1 -0
- metadata +8 -2
data/CHANGELOG
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
= Mechanize CHANGELOG
|
2
2
|
|
3
|
+
== 0.6.3
|
4
|
+
|
5
|
+
* Added keys and values methods to Form
|
6
|
+
* Added has_value? to Form
|
7
|
+
* Added a has_field? method to Form
|
8
|
+
* The add_field! method on Form now creates a field for you on the form.
|
9
|
+
Thanks to Mat Schaffer for the patch.
|
10
|
+
http://rubyforge.org/pipermail/mechanize-users/2006-November/000025.html
|
11
|
+
* Fixed a bug when form actions have html ecoded entities in them.
|
12
|
+
http://rubyforge.org/pipermail/mechanize-users/2006-October/000019.html
|
13
|
+
* Fixed a bug when links or frame sources have html encoded entities in the
|
14
|
+
href or src.
|
15
|
+
* Fixed a bug where '#' symbols are encoded
|
16
|
+
http://rubyforge.org/forum/message.php?msg_id=14747
|
17
|
+
|
3
18
|
== 0.6.2
|
4
19
|
|
5
20
|
* Added a yield to Page#form so that dealing with forms can be more DSL like.
|
data/NOTES
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
= Mechanize Release Notes
|
2
2
|
|
3
|
+
== 0.6.3 (Big Man)
|
4
|
+
|
5
|
+
Mechanize 0.6.3 (Big Man) has a few bug fixes and some new features added to
|
6
|
+
the Form class. The Form class is now more hash like. I've added an
|
7
|
+
Form#add_field! method that will add a field to your form. Form#[]= will now
|
8
|
+
add a field if the key doesn't exist. For example, your form doesn't have
|
9
|
+
an input field named 'foo', the following 2 lines of code are equivalent, and
|
10
|
+
will create a field named 'foo':
|
11
|
+
form['foo'] = 'bar'
|
12
|
+
or
|
13
|
+
form.add_field!('foo', 'bar')
|
14
|
+
To make forms more hashlike, has_value?, and has_key? methods.
|
15
|
+
|
3
16
|
== 0.6.2 (Bridget)
|
4
17
|
|
5
18
|
Mechanize 0.6.2 (Bridget) is a fairly small bug fix release. You can now
|
data/lib/mechanize.rb
CHANGED
@@ -200,12 +200,7 @@ class Mechanize
|
|
200
200
|
when 'POST'
|
201
201
|
post_form(uri, form)
|
202
202
|
when 'GET'
|
203
|
-
|
204
|
-
uri.query = WWW::Mechanize.build_query_string(form.build_query)
|
205
|
-
else
|
206
|
-
uri.query = uri.query + "&" +
|
207
|
-
WWW::Mechanize.build_query_string(form.build_query)
|
208
|
-
end
|
203
|
+
uri.query = WWW::Mechanize.build_query_string(form.build_query)
|
209
204
|
get(uri)
|
210
205
|
else
|
211
206
|
raise "unsupported method: #{form.method.upcase}"
|
@@ -241,9 +236,8 @@ class Mechanize
|
|
241
236
|
|
242
237
|
def to_absolute_uri(url, cur_page=current_page())
|
243
238
|
url = URI.parse(
|
244
|
-
URI.
|
245
|
-
|
246
|
-
)) unless url.is_a? URI
|
239
|
+
URI.unescape(Util.html_unescape(url.to_s.strip)).gsub(/ /, '%20')
|
240
|
+
) unless url.is_a? URI
|
247
241
|
|
248
242
|
# construct an absolute uri
|
249
243
|
if url.relative?
|
@@ -287,7 +281,7 @@ class Mechanize
|
|
287
281
|
def fetch_page(uri, request, cur_page=current_page(), request_data=[])
|
288
282
|
raise "unsupported scheme" unless ['http', 'https'].include?(uri.scheme)
|
289
283
|
|
290
|
-
log.info("#{ request.class }: #{
|
284
|
+
log.info("#{ request.class }: #{ request.path }") if log
|
291
285
|
|
292
286
|
page = nil
|
293
287
|
|
@@ -404,9 +398,7 @@ class Mechanize
|
|
404
398
|
return page
|
405
399
|
when "301", "302"
|
406
400
|
log.info("follow redirect to: #{ response['Location'] }") if log
|
407
|
-
abs_uri = to_absolute_uri(
|
408
|
-
URI.parse(
|
409
|
-
URI.escape(URI.unescape(response['Location'].to_s))), page)
|
401
|
+
abs_uri = to_absolute_uri(response['Location'].to_s, page)
|
410
402
|
request = fetch_request(abs_uri)
|
411
403
|
return fetch_page(abs_uri, request, page)
|
412
404
|
else
|
@@ -435,6 +427,12 @@ class Mechanize
|
|
435
427
|
@history = @history[@history.size - @max_history, @max_history]
|
436
428
|
end
|
437
429
|
end
|
430
|
+
|
431
|
+
class Util
|
432
|
+
def self.html_unescape(s)
|
433
|
+
s.to_s.gsub(/&/, "&").gsub(/"/, '"').gsub(/>/, ">").gsub(/</, "<")
|
434
|
+
end
|
435
|
+
end
|
438
436
|
end
|
439
437
|
|
440
438
|
end # module WWW
|
data/lib/mechanize/form.rb
CHANGED
@@ -32,7 +32,7 @@ module WWW
|
|
32
32
|
|
33
33
|
@form_node.attributes ||= {}
|
34
34
|
@method = (@form_node.attributes['method'] || 'GET').upcase
|
35
|
-
@action = @form_node.attributes['action']
|
35
|
+
@action = Util::html_unescape(@form_node.attributes['action'])
|
36
36
|
@name = @form_node.attributes['name']
|
37
37
|
@enctype = @form_node.attributes['enctype'] || 'application/x-www-form-urlencoded'
|
38
38
|
@clicked_buttons = []
|
@@ -220,11 +220,31 @@ module WWW
|
|
220
220
|
@mech = mech
|
221
221
|
end
|
222
222
|
|
223
|
-
#
|
223
|
+
# Returns whether or not the form contains a field with +field_name+
|
224
|
+
def has_field?(field_name)
|
225
|
+
! fields.find { |f| f.name.eql? field_name }.nil?
|
226
|
+
end
|
227
|
+
|
228
|
+
alias :has_key? :has_field?
|
229
|
+
|
230
|
+
def has_value?(value)
|
231
|
+
! fields.find { |f| f.value.eql? value }.nil?
|
232
|
+
end
|
233
|
+
|
234
|
+
def keys; fields.map { |f| f.name }; end
|
235
|
+
|
236
|
+
def values; fields.map { |f| f.value }; end
|
237
|
+
|
238
|
+
# Fetch the first field whose name is equal to +field_name+
|
224
239
|
def field(field_name)
|
225
240
|
fields.find { |f| f.name.eql? field_name }
|
226
241
|
end
|
227
242
|
|
243
|
+
# Add a field with +field_name+ and +value+
|
244
|
+
def add_field!(field_name, value = nil)
|
245
|
+
fields << WWW::Mechanize::Field.new(field_name, value)
|
246
|
+
end
|
247
|
+
|
228
248
|
# This method sets multiple fields on the form. It takes a list of field
|
229
249
|
# name, value pairs. If there is more than one field found with the
|
230
250
|
# same name, this method will set the first one found. If you want to
|
@@ -250,7 +270,8 @@ module WWW
|
|
250
270
|
# Fetch the value set in the input field 'name'
|
251
271
|
# puts form['name']
|
252
272
|
def [](field_name)
|
253
|
-
field(field_name)
|
273
|
+
f = field(field_name)
|
274
|
+
f && f.value
|
254
275
|
end
|
255
276
|
|
256
277
|
# Set the value of the first input field with the name passed in
|
@@ -258,7 +279,12 @@ module WWW
|
|
258
279
|
# Set the value in the input field 'name' to "Aaron"
|
259
280
|
# form['name'] = 'Aaron'
|
260
281
|
def []=(field_name, value)
|
261
|
-
field(field_name)
|
282
|
+
f = field(field_name)
|
283
|
+
if f.nil?
|
284
|
+
add_field!(field_name, value)
|
285
|
+
else
|
286
|
+
f.value = value
|
287
|
+
end
|
262
288
|
end
|
263
289
|
|
264
290
|
# Treat form fields like accessors.
|
data/lib/mechanize/hpricot.rb
CHANGED
@@ -2,14 +2,7 @@ require 'hpricot'
|
|
2
2
|
class Hpricot::Elem
|
3
3
|
def all_text
|
4
4
|
text = ''
|
5
|
-
|
6
|
-
if child.respond_to? :content
|
7
|
-
text << child.content
|
8
|
-
end
|
9
|
-
if child.respond_to? :all_text
|
10
|
-
text << child.all_text
|
11
|
-
end
|
12
|
-
end
|
5
|
+
traverse_text { |t| text << t.content }
|
13
6
|
text
|
14
7
|
end
|
15
8
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<html>
|
2
|
+
<head><title>Page Title</title></head>
|
3
|
+
<body>
|
4
|
+
<h1>Post Form 1</h1>
|
5
|
+
<form name="post_form1" method="post" action="/form_post?a=b&b=c">
|
6
|
+
<table>
|
7
|
+
<tr>
|
8
|
+
<td>First Name</td>
|
9
|
+
<td><input type="text" name="first_name" /></td>
|
10
|
+
</tr>
|
11
|
+
</table><br />
|
12
|
+
<input type="submit" value="Submit" />
|
13
|
+
</form>
|
14
|
+
|
15
|
+
<h1>Post Form 2</h1>
|
16
|
+
<form name="post_form2" method="get" action="/form_post?a=b&b=c">
|
17
|
+
<table>
|
18
|
+
<tr>
|
19
|
+
<td>First Name</td>
|
20
|
+
<td><input type="text" name="first_name" /></td>
|
21
|
+
</tr>
|
22
|
+
</table><br />
|
23
|
+
<input type="submit" value="Submit" />
|
24
|
+
</form>
|
25
|
+
|
26
|
+
<h1>Post Form 3</h1>
|
27
|
+
<form name="post_form3" method="post" action="/form_post?a=b&b=c">
|
28
|
+
<table>
|
29
|
+
<tr>
|
30
|
+
<td>First Name</td>
|
31
|
+
<td><input type="text" name="first_name" /></td>
|
32
|
+
</tr>
|
33
|
+
</table><br />
|
34
|
+
<input type="submit" value="Submit" />
|
35
|
+
</form>
|
36
|
+
|
37
|
+
<h1>Post Form 4</h1>
|
38
|
+
<form name="post_form4" method="post" action="/form_post#1">
|
39
|
+
<table>
|
40
|
+
<tr>
|
41
|
+
<td>First Name</td>
|
42
|
+
<td><input type="text" name="first_name" /></td>
|
43
|
+
</tr>
|
44
|
+
</table><br />
|
45
|
+
<input type="submit" value="Submit" />
|
46
|
+
</form>
|
47
|
+
</body>
|
48
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mechanize'
|
6
|
+
require 'test_includes'
|
7
|
+
|
8
|
+
class TestEncodedLinks < Test::Unit::TestCase
|
9
|
+
include TestMethods
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@agent = WWW::Mechanize.new
|
13
|
+
@page = @agent.get("http://localhost:#{PORT}/tc_encoded_links.html")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_click_link
|
17
|
+
link = @page.links.first
|
18
|
+
assert_equal('/form_post?a=b&b=c', link.href)
|
19
|
+
page = @agent.click(link)
|
20
|
+
assert_equal("http://localhost:#{PORT}/form_post?a=b&b=c", page.uri.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_hpricot_link
|
24
|
+
page = @agent.click(@page.search('a').first)
|
25
|
+
assert_equal("http://localhost:#{PORT}/form_post?a=b&b=c", page.uri.to_s)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mechanize'
|
6
|
+
require 'test_includes'
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
class TestFormAction < Test::Unit::TestCase
|
10
|
+
include TestMethods
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@agent = WWW::Mechanize.new
|
14
|
+
@page = @agent.get("http://localhost:#{PORT}/tc_form_action.html")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_post_encoded_action
|
18
|
+
form = @page.form('post_form1') { |f|
|
19
|
+
f.first_name = "Aaron"
|
20
|
+
}
|
21
|
+
assert_equal('/form_post?a=b&b=c', form.action)
|
22
|
+
page = form.submit
|
23
|
+
assert_equal("http://localhost:#{PORT}/form_post?a=b&b=c", page.uri.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_encoded_action
|
27
|
+
form = @page.form('post_form2') { |f|
|
28
|
+
f.first_name = "Aaron"
|
29
|
+
}
|
30
|
+
assert_equal('/form_post?a=b&b=c', form.action)
|
31
|
+
page = form.submit
|
32
|
+
assert_equal("http://localhost:#{PORT}/form_post?first_name=Aaron", page.uri.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_post_nonencoded_action
|
36
|
+
form = @page.form('post_form3') { |f|
|
37
|
+
f.first_name = "Aaron"
|
38
|
+
}
|
39
|
+
assert_equal('/form_post?a=b&b=c', form.action)
|
40
|
+
page = form.submit
|
41
|
+
assert_equal("http://localhost:#{PORT}/form_post?a=b&b=c", page.uri.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_post_pound_sign
|
45
|
+
form = @page.form('post_form4') { |f|
|
46
|
+
f.first_name = "Aaron"
|
47
|
+
}
|
48
|
+
assert_equal('/form_post#1', form.action)
|
49
|
+
page = form.submit
|
50
|
+
assert_equal("http://localhost:#{PORT}/form_post#1", page.uri.to_s)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require 'webrick'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mechanize'
|
7
|
+
require 'test_includes'
|
8
|
+
|
9
|
+
class TestFormHash < Test::Unit::TestCase
|
10
|
+
include TestMethods
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@agent = WWW::Mechanize.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_form_hash
|
17
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
18
|
+
form = page.forms.name('post_form').first
|
19
|
+
|
20
|
+
assert_not_nil(form)
|
21
|
+
field_length = form.fields.length
|
22
|
+
assert_nil(form['intarweb'])
|
23
|
+
form['intarweb'] = 'Aaron'
|
24
|
+
|
25
|
+
assert_not_nil(form['intarweb'])
|
26
|
+
assert_equal(field_length + 1, form.fields.length)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_add_field_via_hash
|
30
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
31
|
+
form = page.forms.name('post_form').first
|
32
|
+
|
33
|
+
assert_not_nil(form)
|
34
|
+
field_length = form.fields.length
|
35
|
+
assert_nil(form['intarweb'])
|
36
|
+
form['intarweb'] = 'Aaron'
|
37
|
+
|
38
|
+
assert_not_nil(form['intarweb'])
|
39
|
+
assert_equal(field_length + 1, form.fields.length)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_fields_as_hash
|
43
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
44
|
+
form = page.forms.name('post_form').first
|
45
|
+
|
46
|
+
assert_not_nil(form)
|
47
|
+
assert_equal(2, form.fields.name('first').length)
|
48
|
+
|
49
|
+
form['first'] = 'Aaron'
|
50
|
+
assert_equal('Aaron', form['first'])
|
51
|
+
assert_equal('Aaron', form.fields.name('first').first.value)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_keys
|
55
|
+
page = @agent.get("http://localhost:#{PORT}/empty_form.html")
|
56
|
+
form = page.forms.first
|
57
|
+
|
58
|
+
assert_not_nil(form)
|
59
|
+
assert_equal(false, form.has_field?('name'))
|
60
|
+
assert_equal(false, form.has_value?('Aaron'))
|
61
|
+
assert_equal(0, form.keys.length)
|
62
|
+
assert_equal(0, form.values.length)
|
63
|
+
form['name'] = 'Aaron'
|
64
|
+
assert_equal(true, form.has_field?('name'))
|
65
|
+
assert_equal(true, form.has_value?('Aaron'))
|
66
|
+
assert_equal(1, form.keys.length)
|
67
|
+
assert_equal(['name'], form.keys)
|
68
|
+
assert_equal(1, form.values.length)
|
69
|
+
assert_equal(['Aaron'], form.values)
|
70
|
+
end
|
71
|
+
end
|
data/test/tc_forms.rb
CHANGED
@@ -456,7 +456,7 @@ class FormsMechTest < Test::Unit::TestCase
|
|
456
456
|
page = @agent.submit(get_form, get_form.buttons.first)
|
457
457
|
|
458
458
|
# Check that the submitted fields exist
|
459
|
-
assert_equal(
|
459
|
+
assert_equal(3, page.links.size, "Not enough links")
|
460
460
|
assert_not_nil(
|
461
461
|
page.links.find { |l| l.text == "likes ham:on" },
|
462
462
|
"likes ham check box missing"
|
@@ -469,14 +469,6 @@ class FormsMechTest < Test::Unit::TestCase
|
|
469
469
|
page.links.find { |l| l.text == "gender:male" },
|
470
470
|
"gender field missing"
|
471
471
|
)
|
472
|
-
assert_not_nil(
|
473
|
-
page.links.find { |l| l.text == "great day:yes" },
|
474
|
-
"great day field missing"
|
475
|
-
)
|
476
|
-
assert_not_nil(
|
477
|
-
page.links.find { |l| l.text == "one:two" },
|
478
|
-
"one field missing"
|
479
|
-
)
|
480
472
|
end
|
481
473
|
|
482
474
|
def test_field_addition
|
@@ -497,15 +489,26 @@ class FormsMechTest < Test::Unit::TestCase
|
|
497
489
|
assert_equal('Aaron', form.first)
|
498
490
|
end
|
499
491
|
|
500
|
-
def
|
492
|
+
def test_add_field
|
501
493
|
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
502
494
|
form = page.forms.name('post_form').first
|
503
495
|
|
504
496
|
assert_not_nil(form)
|
505
|
-
|
497
|
+
number_of_fields = form.fields.length
|
506
498
|
|
507
|
-
|
508
|
-
|
509
|
-
assert_equal(
|
499
|
+
f = form.add_field!('intarweb')
|
500
|
+
assert_not_nil(f)
|
501
|
+
assert_equal(number_of_fields + 1, form.fields.length)
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_has_field
|
505
|
+
page = @agent.get("http://localhost:#{PORT}/form_multival.html")
|
506
|
+
form = page.forms.name('post_form').first
|
507
|
+
|
508
|
+
assert_not_nil(form)
|
509
|
+
assert_equal(false, form.has_field?('intarweb'))
|
510
|
+
f = form.add_field!('intarweb')
|
511
|
+
assert_not_nil(f)
|
512
|
+
assert_equal(true, form.has_field?('intarweb'))
|
510
513
|
end
|
511
514
|
end
|
data/test/tc_upload.rb
CHANGED
@@ -10,99 +10,94 @@ class UploadMechTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
def setup
|
12
12
|
@agent = WWW::Mechanize.new
|
13
|
+
@page = @agent.get("http://localhost:#{PORT}/file_upload.html")
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_form_enctype
|
16
|
-
|
17
|
-
assert_equal('multipart/form-data', page.forms[0].enctype)
|
17
|
+
assert_equal('multipart/form-data', @page.forms[0].enctype)
|
18
18
|
|
19
|
-
form = page.forms.first
|
19
|
+
form = @page.forms.first
|
20
20
|
form.file_uploads.first.file_name = "README"
|
21
21
|
form.file_uploads.first.mime_type = "text/plain"
|
22
22
|
form.file_uploads.first.file_data = "Hello World\n\n"
|
23
23
|
|
24
|
-
page = @agent.submit(form)
|
24
|
+
@page = @agent.submit(form)
|
25
25
|
|
26
26
|
assert_match(
|
27
27
|
"Content-Disposition: form-data; name=\"userfile1\"; filename=\"README\"",
|
28
|
-
page.body
|
28
|
+
@page.body
|
29
29
|
)
|
30
30
|
assert_match(
|
31
31
|
"Content-Disposition: form-data; name=\"name\"",
|
32
|
-
page.body
|
32
|
+
@page.body
|
33
33
|
)
|
34
|
-
assert_match('Content-Type: text/plain', page.body)
|
35
|
-
assert_match('Hello World', page.body)
|
36
|
-
assert_match('foo[aaron]', page.body)
|
34
|
+
assert_match('Content-Type: text/plain', @page.body)
|
35
|
+
assert_match('Hello World', @page.body)
|
36
|
+
assert_match('foo[aaron]', @page.body)
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_form_multipart
|
40
|
-
|
41
|
-
assert_equal('multipart/form-data', page.forms[1].enctype)
|
40
|
+
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
42
41
|
|
43
|
-
form = page.forms[1]
|
42
|
+
form = @page.forms[1]
|
44
43
|
form.file_uploads.first.file_name = "README"
|
45
44
|
form.file_uploads.first.mime_type = "text/plain"
|
46
45
|
form.file_uploads.first.file_data = "Hello World\n\n"
|
47
46
|
|
48
|
-
page = @agent.submit(form)
|
47
|
+
@page = @agent.submit(form)
|
49
48
|
|
50
49
|
assert_match(
|
51
50
|
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"README\"",
|
52
|
-
page.body
|
51
|
+
@page.body
|
53
52
|
)
|
54
53
|
end
|
55
54
|
|
56
55
|
def test_form_read_file
|
57
|
-
|
58
|
-
assert_equal('multipart/form-data', page.forms[1].enctype)
|
56
|
+
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
59
57
|
|
60
|
-
form = page.forms[1]
|
58
|
+
form = @page.forms[1]
|
61
59
|
form.file_uploads.first.file_name = "README"
|
62
60
|
|
63
|
-
page = @agent.submit(form)
|
61
|
+
@page = @agent.submit(form)
|
64
62
|
|
65
63
|
contents = File.open("README", 'rb') { |f| f.read }
|
66
64
|
assert_match(
|
67
65
|
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"README\"",
|
68
|
-
page.body
|
66
|
+
@page.body
|
69
67
|
)
|
70
|
-
assert_match(contents, page.body)
|
68
|
+
assert_match(contents, @page.body)
|
71
69
|
end
|
72
70
|
|
73
71
|
def test_form_io_obj
|
74
|
-
|
75
|
-
assert_equal('multipart/form-data', page.forms[1].enctype)
|
72
|
+
assert_equal('multipart/form-data', @page.forms[1].enctype)
|
76
73
|
|
77
|
-
form = page.forms[1]
|
74
|
+
form = @page.forms[1]
|
78
75
|
form.file_uploads.first.file_name = "README"
|
79
76
|
form.file_uploads.first.file_data = File.open("README", 'rb')
|
80
77
|
|
81
|
-
page = @agent.submit(form)
|
78
|
+
@page = @agent.submit(form)
|
82
79
|
|
83
80
|
contents = File.open("README", 'rb') { |f| f.read }
|
84
81
|
assert_match(
|
85
82
|
"Content-Disposition: form-data; name=\"green[eggs]\"; filename=\"README\"",
|
86
|
-
page.body
|
83
|
+
@page.body
|
87
84
|
)
|
88
|
-
assert_match(contents, page.body)
|
85
|
+
assert_match(contents, @page.body)
|
89
86
|
end
|
90
87
|
|
91
88
|
def test_submit_no_file
|
92
|
-
|
93
|
-
form = page.forms.first
|
89
|
+
form = @page.forms.first
|
94
90
|
form.fields.name('name').value = 'Aaron'
|
95
|
-
page = @agent.submit(form)
|
96
|
-
assert_match('Aaron', page.body)
|
91
|
+
@page = @agent.submit(form)
|
92
|
+
assert_match('Aaron', @page.body)
|
97
93
|
assert_match(
|
98
94
|
"Content-Disposition: form-data; name=\"userfile1\"; filename=\"\"",
|
99
|
-
page.body
|
95
|
+
@page.body
|
100
96
|
)
|
101
97
|
end
|
102
98
|
|
103
99
|
def test_no_value
|
104
|
-
|
105
|
-
form = page.form('value_test')
|
100
|
+
form = @page.form('value_test')
|
106
101
|
assert_nil(form.file_uploads.first.value)
|
107
102
|
assert_nil(form.file_uploads.first.file_name)
|
108
103
|
end
|
data/test/ts_mech.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mechanize
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.6.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.6.3
|
7
|
+
date: 2006-11-05 00:00:00 -08:00
|
8
8
|
summary: Mechanize provides automated web-browsing
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -43,7 +43,10 @@ files:
|
|
43
43
|
- test/tc_cookie_class.rb
|
44
44
|
- test/tc_cookie_jar.rb
|
45
45
|
- test/tc_cookies.rb
|
46
|
+
- test/tc_encoded_links.rb
|
46
47
|
- test/tc_errors.rb
|
48
|
+
- test/tc_form_action.rb
|
49
|
+
- test/tc_form_as_hash.rb
|
47
50
|
- test/tc_form_no_inputname.rb
|
48
51
|
- test/tc_forms.rb
|
49
52
|
- test/tc_frames.rb
|
@@ -80,6 +83,7 @@ files:
|
|
80
83
|
- test/htdocs/alt_text.html
|
81
84
|
- test/htdocs/bad_form_test.html
|
82
85
|
- test/htdocs/button.jpg
|
86
|
+
- test/htdocs/empty_form.html
|
83
87
|
- test/htdocs/file_upload.html
|
84
88
|
- test/htdocs/find_link.html
|
85
89
|
- test/htdocs/form_multi_select.html
|
@@ -100,6 +104,8 @@ files:
|
|
100
104
|
- test/htdocs/no_title_test.html
|
101
105
|
- test/htdocs/tc_bad_links.html
|
102
106
|
- test/htdocs/tc_checkboxes.html
|
107
|
+
- test/htdocs/tc_encoded_links.html
|
108
|
+
- test/htdocs/tc_form_action.html
|
103
109
|
- test/htdocs/tc_links.html
|
104
110
|
- test/htdocs/tc_no_attributes.html
|
105
111
|
- test/htdocs/tc_pretty_print.html
|