mechanize 0.8.4 → 0.8.5

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 (51) hide show
  1. data/EXAMPLES.txt +1 -1
  2. data/GUIDE.txt +11 -12
  3. data/History.txt +24 -0
  4. data/Manifest.txt +2 -1
  5. data/README.txt +1 -1
  6. data/Rakefile +2 -2
  7. data/lib/www/mechanize.rb +43 -11
  8. data/lib/www/mechanize/chain/header_resolver.rb +1 -1
  9. data/lib/www/mechanize/chain/request_resolver.rb +4 -0
  10. data/lib/www/mechanize/chain/response_body_parser.rb +1 -1
  11. data/lib/www/mechanize/chain/response_reader.rb +1 -1
  12. data/lib/www/mechanize/chain/ssl_resolver.rb +1 -1
  13. data/lib/www/mechanize/chain/uri_resolver.rb +21 -9
  14. data/lib/www/mechanize/cookie_jar.rb +11 -6
  15. data/lib/www/mechanize/file_response.rb +2 -0
  16. data/lib/www/mechanize/form.rb +33 -13
  17. data/lib/www/mechanize/form/multi_select_list.rb +2 -2
  18. data/lib/www/mechanize/form/radio_button.rb +1 -1
  19. data/lib/www/mechanize/list.rb +15 -38
  20. data/lib/www/mechanize/page.rb +17 -10
  21. data/lib/www/mechanize/page/link.rb +2 -2
  22. data/lib/www/mechanize/redirect_not_get_or_head_error.rb +20 -0
  23. data/test/helper.rb +4 -0
  24. data/test/htdocs/relative/tc_relative_links.html +1 -0
  25. data/test/servlets.rb +38 -8
  26. data/test/test_checkboxes.rb +14 -15
  27. data/test/test_cookie_class.rb +5 -4
  28. data/test/test_cookie_jar.rb +29 -0
  29. data/test/test_encoded_links.rb +1 -1
  30. data/test/test_errors.rb +1 -1
  31. data/test/test_follow_meta.rb +50 -6
  32. data/test/test_form_as_hash.rb +5 -5
  33. data/test/test_forms.rb +28 -27
  34. data/test/test_links.rb +22 -16
  35. data/test/test_mech.rb +24 -7
  36. data/test/test_multi_select.rb +27 -27
  37. data/test/test_pluggable_parser.rb +4 -4
  38. data/test/test_radiobutton.rb +35 -42
  39. data/test/test_redirect_verb_handling.rb +45 -0
  40. data/test/test_referer.rb +1 -1
  41. data/test/test_relative_links.rb +4 -4
  42. data/test/test_scheme.rb +4 -0
  43. data/test/test_select.rb +15 -15
  44. data/test/test_select_all.rb +1 -1
  45. data/test/test_select_none.rb +1 -1
  46. data/test/test_select_noopts.rb +1 -1
  47. data/test/test_set_fields.rb +4 -4
  48. data/test/test_textarea.rb +13 -13
  49. data/test/test_upload.rb +1 -1
  50. metadata +10 -6
  51. data/NOTES.txt +0 -318
@@ -1,25 +1,69 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
2
 
3
3
  class FollowMetaTest < Test::Unit::TestCase
4
4
  def setup
5
5
  @agent = WWW::Mechanize.new
6
6
  end
7
7
 
8
- def test_follow_meta
8
+ def test_dont_follow_meta_by_default
9
9
  page = @agent.get('http://localhost/tc_follow_meta.html')
10
10
  assert_equal('http://localhost/tc_follow_meta.html', page.uri.to_s)
11
11
  assert_equal(1, page.meta.length)
12
+ end
12
13
 
14
+ def test_follow_meta_if_set
13
15
  @agent.follow_meta_refresh = true
16
+
14
17
  page = @agent.get('http://localhost/tc_follow_meta.html')
18
+
19
+ assert_equal(2, @agent.history.length)
20
+ assert_equal('http://localhost/tc_follow_meta.html',
21
+ @agent.history[0].uri.to_s)
22
+ assert_equal('http://localhost/index.html', page.uri.to_s)
23
+ assert_equal('http://localhost/index.html', @agent.history.last.uri.to_s)
24
+ end
25
+
26
+ def test_always_follow_302
27
+ @agent.follow_meta_refresh = false
28
+ page = @agent.get('http://localhost/response_code?code=302&ct=test/xml')
15
29
  assert_equal('http://localhost/index.html', page.uri.to_s)
16
- assert_equal(3, @agent.history.length)
30
+ assert_equal(2, @agent.history.length)
17
31
  end
18
32
 
19
- def test_follow_meta_on_302
33
+ def test_infinite_refresh_throws_exception
20
34
  @agent.follow_meta_refresh = true
21
- assert_nothing_raised {
22
- @agent.get("http://localhost/response_code?code=302&ct=test/xml")
35
+ assert_raises(WWW::Mechanize::RedirectLimitReachedError) {
36
+ begin
37
+ @agent.get('http://localhost/infinite_refresh')
38
+ rescue WWW::Mechanize::RedirectLimitReachedError => ex
39
+ raise ex
40
+ end
23
41
  }
24
42
  end
43
+
44
+ def test_dont_honor_http_refresh_by_default
45
+ page = @agent.get('http://localhost/http_refresh?refresh_time=0')
46
+ assert_equal('http://localhost/http_refresh?refresh_time=0', page.uri.to_s)
47
+ end
48
+
49
+ def test_honor_http_refresh_if_set
50
+ @agent.follow_meta_refresh = true
51
+ page = @agent.get('http://localhost/http_refresh?refresh_time=0')
52
+ assert_equal('http://localhost/index.html', page.uri.to_s)
53
+ assert_equal(2, @agent.history.length)
54
+ end
55
+
56
+ def test_honor_http_refresh_delay_if_set
57
+ @agent.follow_meta_refresh = true
58
+ class << @agent
59
+ attr_accessor :slept
60
+ def sleep *args
61
+ @slept = args
62
+ end
63
+ end
64
+
65
+ page = @agent.get('http://localhost/http_refresh?refresh_time=1')
66
+ assert_equal [1], @agent.slept
67
+ end
68
+
25
69
  end
@@ -7,7 +7,7 @@ class TestFormHash < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_form_hash
10
- form = @page.forms.name('post_form').first
10
+ form = @page.form_with(:name => 'post_form')
11
11
 
12
12
  assert_not_nil(form)
13
13
  field_length = form.fields.length
@@ -19,7 +19,7 @@ class TestFormHash < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_add_field_via_hash
22
- form = @page.forms.name('post_form').first
22
+ form = @page.form_with(:name => 'post_form')
23
23
 
24
24
  assert_not_nil(form)
25
25
  field_length = form.fields.length
@@ -31,14 +31,14 @@ class TestFormHash < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_fields_as_hash
34
- form = @page.forms.name('post_form').first
34
+ form = @page.form_with(:name => 'post_form')
35
35
 
36
36
  assert_not_nil(form)
37
- assert_equal(2, form.fields.name('first').length)
37
+ assert_equal(2, form.fields_with(:name => 'first').length)
38
38
 
39
39
  form['first'] = 'Aaron'
40
40
  assert_equal('Aaron', form['first'])
41
- assert_equal('Aaron', form.fields.name('first').first.value)
41
+ assert_equal('Aaron', form.field_with(:name => 'first').value)
42
42
  end
43
43
 
44
44
  def test_keys
data/test/test_forms.rb CHANGED
@@ -11,64 +11,65 @@ class FormsMechTest < Test::Unit::TestCase
11
11
  page = @agent.submit(page.forms.first)
12
12
  assert_match('/form_no_action.html?first=Aaron', page.uri.to_s)
13
13
  end
14
+
14
15
  # Test submitting form with two fields of the same name
15
16
  def test_post_multival
16
17
  page = @agent.get("http://localhost/form_multival.html")
17
- form = page.forms.name('post_form').first
18
+ form = page.form_with(:name => 'post_form')
18
19
 
19
20
  assert_not_nil(form)
20
- assert_equal(2, form.fields.name('first').length)
21
+ assert_equal(2, form.fields_with(:name => 'first').length)
21
22
 
22
- form.fields.name('first')[0].value = 'Aaron'
23
- form.fields.name('first')[1].value = 'Patterson'
23
+ form.fields_with(:name => 'first')[0].value = 'Aaron'
24
+ form.fields_with(:name => 'first')[1].value = 'Patterson'
24
25
 
25
26
  page = @agent.submit(form)
26
27
 
27
28
  assert_not_nil(page)
28
29
 
29
30
  assert_equal(2, page.links.length)
30
- assert_not_nil(page.links.text('first:Aaron').first)
31
- assert_not_nil(page.links.text('first:Patterson').first)
31
+ assert_not_nil(page.link_with(:text => 'first:Aaron'))
32
+ assert_not_nil(page.link_with(:text => 'first:Patterson'))
32
33
  end
33
34
 
34
35
  # Test calling submit on the form object
35
36
  def test_submit_on_form
36
37
  page = @agent.get("http://localhost/form_multival.html")
37
- form = page.forms.name('post_form').first
38
+ form = page.form_with(:name => 'post_form')
38
39
 
39
40
  assert_not_nil(form)
40
- assert_equal(2, form.fields.name('first').length)
41
+ assert_equal(2, form.fields_with(:name => 'first').length)
41
42
 
42
- form.fields.name('first')[0].value = 'Aaron'
43
- form.fields.name('first')[1].value = 'Patterson'
43
+ form.fields_with(:name => 'first')[0].value = 'Aaron'
44
+ form.fields_with(:name => 'first')[1].value = 'Patterson'
44
45
 
45
46
  page = form.submit
46
47
 
47
48
  assert_not_nil(page)
48
49
 
49
50
  assert_equal(2, page.links.length)
50
- assert_not_nil(page.links.text('first:Aaron').first)
51
- assert_not_nil(page.links.text('first:Patterson').first)
51
+ assert_not_nil(page.link_with(:text => 'first:Aaron'))
52
+ assert_not_nil(page.link_with(:text => 'first:Patterson'))
52
53
  end
53
54
 
54
55
  # Test submitting form with two fields of the same name
55
56
  def test_get_multival
56
57
  page = @agent.get("http://localhost/form_multival.html")
57
- form = page.forms.name('get_form').first
58
+ form = page.form_with(:name => 'get_form')
58
59
 
59
60
  assert_not_nil(form)
60
- assert_equal(2, form.fields.name('first').length)
61
+ assert_equal(2, form.fields_with(:name => 'first').length)
61
62
 
62
- form.fields.name('first')[0].value = 'Aaron'
63
- form.fields.name('first')[1].value = 'Patterson'
63
+ form.fields_with(:name => 'first')[0].value = 'Aaron'
64
+ form.fields_with(:name => 'first')[1].value = 'Patterson'
64
65
 
65
66
  page = @agent.submit(form)
66
67
 
67
68
  assert_not_nil(page)
68
69
 
69
70
  assert_equal(2, page.links.length)
70
- assert_not_nil(page.links.text('first:Aaron').first)
71
- assert_not_nil(page.links.text('first:Patterson').first)
71
+ assert_not_nil(page.link_with(:text => 'first:Aaron'))
72
+ assert_not_nil(page.link_with(:text => 'first:Patterson'))
72
73
  end
73
74
 
74
75
  def test_post
@@ -159,7 +160,7 @@ class FormsMechTest < Test::Unit::TestCase
159
160
  assert_equal("/form_post", post_form.action)
160
161
 
161
162
  # Find the select list
162
- s = post_form.fields.name(/country/).first
163
+ s = post_form.field_with(:name => /country/)
163
164
  assert_not_nil(s, "Couldn't find country select list")
164
165
  assert_equal(2, s.options.length)
165
166
  assert_equal("USA", s.value)
@@ -169,7 +170,7 @@ class FormsMechTest < Test::Unit::TestCase
169
170
  assert_equal("CANADA", s.options[1].text)
170
171
 
171
172
  # Now set all the fields
172
- post_form.fields.name(/country/).value = s.options[1]
173
+ post_form.field_with(:name => /country/).value = s.options[1]
173
174
  assert_equal('CANADA', post_form.country)
174
175
  page = @agent.submit(post_form, post_form.buttons.first)
175
176
 
@@ -382,13 +383,13 @@ class FormsMechTest < Test::Unit::TestCase
382
383
  "Gender female button was nil"
383
384
  )
384
385
 
385
- assert_not_nil(post_form.checkboxes.name("cool person").first,
386
+ assert_not_nil(post_form.checkbox_with(:name => "cool person"),
386
387
  "couldn't find cool person checkbox")
387
388
  assert_not_nil(post_form.checkboxes.find { |f| f.name == "likes ham" },
388
389
  "couldn't find likes ham checkbox")
389
390
 
390
391
  # Now set all the fields
391
- post_form.fields.name('first_name').value = "Aaron"
392
+ post_form.field_with(:name => 'first_name').value = "Aaron"
392
393
  post_form.radiobuttons.find { |f|
393
394
  f.name == "gender" && f.value == "male"
394
395
  }.checked = true
@@ -472,10 +473,10 @@ class FormsMechTest < Test::Unit::TestCase
472
473
 
473
474
  def test_fields_as_accessors
474
475
  page = @agent.get("http://localhost/form_multival.html")
475
- form = page.forms.name('post_form').first
476
+ form = page.form_with(:name => 'post_form')
476
477
 
477
478
  assert_not_nil(form)
478
- assert_equal(2, form.fields.name('first').length)
479
+ assert_equal(2, form.fields_with(:name => 'first').length)
479
480
 
480
481
  form.first = 'Aaron'
481
482
  assert_equal('Aaron', form.first)
@@ -483,7 +484,7 @@ class FormsMechTest < Test::Unit::TestCase
483
484
 
484
485
  def test_add_field
485
486
  page = @agent.get("http://localhost/form_multival.html")
486
- form = page.forms.name('post_form').first
487
+ form = page.form_with(:name => 'post_form')
487
488
 
488
489
  assert_not_nil(form)
489
490
  number_of_fields = form.fields.length
@@ -495,7 +496,7 @@ class FormsMechTest < Test::Unit::TestCase
495
496
 
496
497
  def test_delete_field
497
498
  page = @agent.get("http://localhost/form_multival.html")
498
- form = page.forms.name('post_form').first
499
+ form = page.form_with(:name => 'post_form')
499
500
 
500
501
  assert_not_nil(form)
501
502
  number_of_fields = form.fields.length
@@ -508,7 +509,7 @@ class FormsMechTest < Test::Unit::TestCase
508
509
 
509
510
  def test_has_field
510
511
  page = @agent.get("http://localhost/form_multival.html")
511
- form = page.forms.name('post_form').first
512
+ form = page.form_with(:name => 'post_form')
512
513
 
513
514
  assert_not_nil(form)
514
515
  assert_equal(false, form.has_field?('intarweb'))
data/test/test_links.rb CHANGED
@@ -7,12 +7,12 @@ class LinksMechTest < Test::Unit::TestCase
7
7
 
8
8
  def test_unsupported_link_types
9
9
  page = @agent.get("http://google.com/tc_links.html")
10
- link = page.links.text('javascript link').first
10
+ link = page.link_with(:text => 'javascript link')
11
11
  assert_raise(WWW::Mechanize::UnsupportedSchemeError) {
12
12
  link.click
13
13
  }
14
14
 
15
- @agent.scheme_handlers['javascript'] = lambda { |link, page|
15
+ @agent.scheme_handlers['javascript'] = lambda { |my_link, my_page|
16
16
  URI.parse('http://localhost/tc_links.html')
17
17
  }
18
18
  assert_nothing_raised {
@@ -20,6 +20,12 @@ class LinksMechTest < Test::Unit::TestCase
20
20
  }
21
21
  end
22
22
 
23
+ def test_link_with_no_path
24
+ page = @agent.get("http://localhost/relative/tc_relative_links.html")
25
+ page = page.link_with(:text => 'just the query string').click
26
+ assert_equal('http://localhost/relative/tc_relative_links.html?a=b', page.uri.to_s)
27
+ end
28
+
23
29
  def test_base
24
30
  page = @agent.get("http://google.com/tc_base_link.html")
25
31
  page = page.links.first.click
@@ -47,17 +53,17 @@ class LinksMechTest < Test::Unit::TestCase
47
53
  assert_equal(1, page.meta.length)
48
54
 
49
55
  assert_equal('', page.meta.first.text)
50
- assert_equal('alt text', page.links.href('alt_text.html').first.text)
51
- assert_equal('', page.links.href('no_alt_text.html').first.text)
52
- assert_equal('no image', page.links.href('no_image.html').first.text)
53
- assert_equal('', page.links.href('no_text.html').first.text)
54
- assert_equal('', page.links.href('nil_alt_text.html').first.text)
56
+ assert_equal('alt text', page.link_with(:href => 'alt_text.html').text)
57
+ assert_equal('', page.link_with(:href => 'no_alt_text.html').text)
58
+ assert_equal('no image', page.link_with(:href => 'no_image.html').text)
59
+ assert_equal('', page.link_with(:href => 'no_text.html').text)
60
+ assert_equal('', page.link_with(:href => 'nil_alt_text.html').text)
55
61
  end
56
62
 
57
63
  def test_click_link
58
64
  @agent.user_agent_alias = 'Mac Safari'
59
65
  page = @agent.get("http://localhost/frame_test.html")
60
- link = page.links.text("Form Test")
66
+ link = page.link_with(:text => "Form Test")
61
67
  assert_not_nil(link)
62
68
  assert_equal('Form Test', link.text)
63
69
  page = @agent.click(link)
@@ -67,7 +73,7 @@ class LinksMechTest < Test::Unit::TestCase
67
73
 
68
74
  def test_click_method
69
75
  page = @agent.get("http://localhost/frame_test.html")
70
- link = page.links.text("Form Test")
76
+ link = page.link_with(:text => "Form Test")
71
77
  assert_not_nil(link)
72
78
  assert_equal('Form Test', link.text)
73
79
  page = link.click
@@ -77,38 +83,38 @@ class LinksMechTest < Test::Unit::TestCase
77
83
 
78
84
  def test_find_bold_link
79
85
  page = @agent.get("http://localhost/tc_links.html")
80
- link = page.links.text(/Bold Dude/)
86
+ link = page.links_with(:text => /Bold Dude/)
81
87
  assert_equal(1, link.length)
82
88
  assert_equal('Bold Dude', link.first.text)
83
89
 
84
- link = page.links.text('Aaron James Patterson')
90
+ link = page.links_with(:text => 'Aaron James Patterson')
85
91
  assert_equal(1, link.length)
86
92
  assert_equal('Aaron James Patterson', link.first.text)
87
93
 
88
- link = page.links.text('Aaron Patterson')
94
+ link = page.links_with(:text => 'Aaron Patterson')
89
95
  assert_equal(1, link.length)
90
96
  assert_equal('Aaron Patterson', link.first.text)
91
97
 
92
- link = page.links.text('Ruby Rocks!')
98
+ link = page.links_with(:text => 'Ruby Rocks!')
93
99
  assert_equal(1, link.length)
94
100
  assert_equal('Ruby Rocks!', link.first.text)
95
101
  end
96
102
 
97
103
  def test_link_with_encoded_space
98
104
  page = @agent.get("http://localhost/tc_links.html")
99
- link = page.links.text('encoded space').first
105
+ link = page.link_with(:text => 'encoded space')
100
106
  page = @agent.click link
101
107
  end
102
108
 
103
109
  def test_link_with_space
104
110
  page = @agent.get("http://localhost/tc_links.html")
105
- link = page.links.text('not encoded space').first
111
+ link = page.link_with(:text => 'not encoded space')
106
112
  page = @agent.click link
107
113
  end
108
114
 
109
115
  def test_link_with_unusual_characters
110
116
  page = @agent.get("http://localhost/tc_links.html")
111
- link = page.links.text('unusual characters').first
117
+ link = page.link_with(:text => 'unusual characters')
112
118
  assert_nothing_raised { @agent.click link }
113
119
  end
114
120
  end
data/test/test_mech.rb CHANGED
@@ -20,6 +20,25 @@ 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_get_no_referer
24
+ requests = []
25
+ @agent.pre_connect_hooks << lambda { |params|
26
+ requests << params[:request]
27
+ }
28
+
29
+ @agent.get('http://localhost/')
30
+ @agent.get('http://localhost/')
31
+ assert_equal(2, requests.length)
32
+ requests.each do |request|
33
+ assert_nil request['referer']
34
+ end
35
+ end
36
+
37
+ def test_with_anchor
38
+ page = @agent.get('http://localhost/?foo=bar&#34;')
39
+ assert_equal('http://localhost/?foo=bar%22', page.uri.to_s)
40
+ end
41
+
23
42
  def test_post_connect_hook_gets_called
24
43
  response = nil
25
44
  @agent.post_connect_hooks << lambda { |params|
@@ -161,15 +180,15 @@ class TestMechMethods < Test::Unit::TestCase
161
180
  page = @agent.get("http://localhost/google.html")
162
181
  search = page.forms.find { |f| f.name == "f" }
163
182
  assert_not_nil(search)
164
- assert_not_nil(search.fields.name('q').first)
165
- assert_not_nil(search.fields.name('hl').first)
183
+ assert_not_nil(search.field_with(:name => 'q'))
184
+ assert_not_nil(search.field_with(:name => 'hl'))
166
185
  assert_not_nil(search.fields.find { |f| f.name == 'ie' })
167
186
  end
168
187
 
169
188
  def test_click
170
189
  @agent.user_agent_alias = 'Mac Safari'
171
190
  page = @agent.get("http://localhost/frame_test.html")
172
- link = page.links.text("Form Test").first
191
+ link = page.link_with(:text => "Form Test")
173
192
  assert_not_nil(link)
174
193
  page = @agent.click(link)
175
194
  assert_equal("http://localhost/form_test.html",
@@ -201,12 +220,10 @@ class TestMechMethods < Test::Unit::TestCase
201
220
  assert_equal(3, page.frames.size)
202
221
 
203
222
  find_orig = page.frames.find_all { |f| f.name == 'frame1' }
204
- find1 = page.frames.with.name('frame1')
205
- find2 = page.frames.name('frame1')
223
+ find1 = page.frames_with(:name => 'frame1')
206
224
 
207
- find_orig.zip(find1, find2).each { |a,b,c|
225
+ find_orig.zip(find1).each { |a,b|
208
226
  assert_equal(a, b)
209
- assert_equal(a, c)
210
227
  }
211
228
  end
212
229
 
@@ -8,7 +8,7 @@ class MultiSelectTest < Test::Unit::TestCase
8
8
  def test_select_none
9
9
  page = @agent.get("http://localhost/form_multi_select.html")
10
10
  form = page.forms.first
11
- form.fields.name('list').first.select_none
11
+ form.field_with(:name => 'list').select_none
12
12
  page = @agent.submit(form)
13
13
  assert_equal(0, page.links.length)
14
14
  end
@@ -16,28 +16,28 @@ class MultiSelectTest < Test::Unit::TestCase
16
16
  def test_select_all
17
17
  page = @agent.get("http://localhost/form_multi_select.html")
18
18
  form = page.forms.first
19
- form.fields.name('list').first.select_all
19
+ form.field_with(:name => 'list').select_all
20
20
  page = @agent.submit(form)
21
21
  assert_equal(6, page.links.length)
22
- assert_equal(1, page.links.text('list:1').length)
23
- assert_equal(1, page.links.text('list:2').length)
24
- assert_equal(1, page.links.text('list:3').length)
25
- assert_equal(1, page.links.text('list:4').length)
26
- assert_equal(1, page.links.text('list:5').length)
27
- assert_equal(1, page.links.text('list:6').length)
22
+ assert_equal(1, page.links_with(:text => 'list:1').length)
23
+ assert_equal(1, page.links_with(:text => 'list:2').length)
24
+ assert_equal(1, page.links_with(:text => 'list:3').length)
25
+ assert_equal(1, page.links_with(:text => 'list:4').length)
26
+ assert_equal(1, page.links_with(:text => 'list:5').length)
27
+ assert_equal(1, page.links_with(:text => 'list:6').length)
28
28
  end
29
29
 
30
30
  def test_click_all
31
31
  page = @agent.get("http://localhost/form_multi_select.html")
32
32
  form = page.forms.first
33
- form.fields.name('list').first.options.each { |o| o.click }
33
+ form.field_with(:name => 'list').options.each { |o| o.click }
34
34
  page = @agent.submit(form)
35
35
  assert_equal(5, page.links.length)
36
- assert_equal(1, page.links.text('list:1').length)
37
- assert_equal(1, page.links.text('list:3').length)
38
- assert_equal(1, page.links.text('list:4').length)
39
- assert_equal(1, page.links.text('list:5').length)
40
- assert_equal(1, page.links.text('list:6').length)
36
+ assert_equal(1, page.links_with(:text => 'list:1').length)
37
+ assert_equal(1, page.links_with(:text => 'list:3').length)
38
+ assert_equal(1, page.links_with(:text => 'list:4').length)
39
+ assert_equal(1, page.links_with(:text => 'list:5').length)
40
+ assert_equal(1, page.links_with(:text => 'list:6').length)
41
41
  end
42
42
 
43
43
  def test_select_default
@@ -45,7 +45,7 @@ class MultiSelectTest < Test::Unit::TestCase
45
45
  form = page.forms.first
46
46
  page = @agent.submit(form)
47
47
  assert_equal(1, page.links.length)
48
- assert_equal(1, page.links.text('list:2').length)
48
+ assert_equal(1, page.links_with(:text => 'list:2').length)
49
49
  end
50
50
 
51
51
  def test_select_one
@@ -64,8 +64,8 @@ class MultiSelectTest < Test::Unit::TestCase
64
64
  form.list = ['1', 'Aaron']
65
65
  page = @agent.submit(form)
66
66
  assert_equal(2, page.links.length)
67
- assert_equal(1, page.links.text('list:1').length)
68
- assert_equal(1, page.links.text('list:Aaron').length)
67
+ assert_equal(1, page.links_with(:text => 'list:1').length)
68
+ assert_equal(1, page.links_with(:text => 'list:Aaron').length)
69
69
  end
70
70
 
71
71
  def test_select_three
@@ -74,9 +74,9 @@ class MultiSelectTest < Test::Unit::TestCase
74
74
  form.list = ['1', '2', '3']
75
75
  page = @agent.submit(form)
76
76
  assert_equal(3, page.links.length)
77
- assert_equal(1, page.links.text('list:1').length)
78
- assert_equal(1, page.links.text('list:2').length)
79
- assert_equal(1, page.links.text('list:3').length)
77
+ assert_equal(1, page.links_with(:text => 'list:1').length)
78
+ assert_equal(1, page.links_with(:text => 'list:2').length)
79
+ assert_equal(1, page.links_with(:text => 'list:3').length)
80
80
  end
81
81
 
82
82
  def test_select_three_twice
@@ -86,21 +86,21 @@ class MultiSelectTest < Test::Unit::TestCase
86
86
  form.list = ['1', '2', '3']
87
87
  page = @agent.submit(form)
88
88
  assert_equal(3, page.links.length)
89
- assert_equal(1, page.links.text('list:1').length)
90
- assert_equal(1, page.links.text('list:2').length)
91
- assert_equal(1, page.links.text('list:3').length)
89
+ assert_equal(1, page.links_with(:text => 'list:1').length)
90
+ assert_equal(1, page.links_with(:text => 'list:2').length)
91
+ assert_equal(1, page.links_with(:text => 'list:3').length)
92
92
  end
93
93
 
94
94
  def test_select_with_click
95
95
  page = @agent.get("http://localhost/form_multi_select.html")
96
96
  form = page.forms.first
97
97
  form.list = ['1', 'Aaron']
98
- form.fields.name('list').first.options[3].tick
98
+ form.field_with(:name => 'list').options[3].tick
99
99
  assert_equal(['1', 'Aaron', '4'].sort, form.list.sort)
100
100
  page = @agent.submit(form)
101
101
  assert_equal(3, page.links.length)
102
- assert_equal(1, page.links.text('list:1').length)
103
- assert_equal(1, page.links.text('list:Aaron').length)
104
- assert_equal(1, page.links.text('list:4').length)
102
+ assert_equal(1, page.links_with(:text => 'list:1').length)
103
+ assert_equal(1, page.links_with(:text => 'list:Aaron').length)
104
+ assert_equal(1, page.links_with(:text => 'list:4').length)
105
105
  end
106
106
  end