mechanize 2.0 → 2.0.1

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 (62) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -0
  3. data/CHANGELOG.rdoc +12 -1
  4. data/Manifest.txt +1 -0
  5. data/Rakefile +4 -2
  6. data/lib/mechanize.rb +23 -13
  7. data/lib/mechanize/cookie_jar.rb +13 -7
  8. data/test/helper.rb +1 -1
  9. data/test/test_cookies.rb +12 -12
  10. data/test/test_form_action.rb +1 -1
  11. data/test/test_form_as_hash.rb +5 -7
  12. data/test/test_form_button.rb +1 -1
  13. data/test/test_frames.rb +1 -1
  14. data/test/test_headers.rb +1 -1
  15. data/test/test_history.rb +1 -1
  16. data/test/test_history_added.rb +1 -1
  17. data/test/test_html_unscape_forms.rb +1 -1
  18. data/test/test_if_modified_since.rb +1 -1
  19. data/test/test_images.rb +1 -1
  20. data/test/test_mechanize.rb +45 -27
  21. data/test/test_mechanize_cookie.rb +6 -6
  22. data/test/test_mechanize_cookie_jar.rb +5 -4
  23. data/test/test_mechanize_file.rb +1 -1
  24. data/test/test_mechanize_file_request.rb +1 -1
  25. data/test/test_mechanize_file_response.rb +1 -1
  26. data/test/test_mechanize_form.rb +148 -233
  27. data/test/test_mechanize_form_check_box.rb +1 -1
  28. data/test/test_mechanize_form_encoding.rb +8 -6
  29. data/test/test_mechanize_form_field.rb +1 -1
  30. data/test/test_mechanize_form_image_button.rb +1 -1
  31. data/test/test_mechanize_form_textarea.rb +9 -3
  32. data/test/test_mechanize_http_agent.rb +2 -2
  33. data/test/test_mechanize_link.rb +8 -7
  34. data/test/test_mechanize_page_encoding.rb +1 -1
  35. data/test/test_mechanize_page_link.rb +5 -2
  36. data/test/test_mechanize_page_meta_refresh.rb +1 -1
  37. data/test/test_mechanize_redirect_not_get_or_head_error.rb +1 -1
  38. data/test/test_mechanize_subclass.rb +1 -1
  39. data/test/test_mechanize_util.rb +18 -18
  40. data/test/test_multi_select.rb +1 -1
  41. data/test/test_no_attributes.rb +4 -4
  42. data/test/test_option.rb +1 -1
  43. data/test/test_pluggable_parser.rb +11 -20
  44. data/test/test_post_form.rb +9 -13
  45. data/test/test_pretty_print.rb +1 -1
  46. data/test/test_radiobutton.rb +1 -1
  47. data/test/test_redirect_limit_reached.rb +1 -1
  48. data/test/test_referer.rb +1 -1
  49. data/test/test_relative_links.rb +2 -2
  50. data/test/test_request.rb +1 -1
  51. data/test/test_response_code.rb +1 -1
  52. data/test/test_robots.rb +18 -29
  53. data/test/test_save_file.rb +1 -1
  54. data/test/test_scheme.rb +3 -3
  55. data/test/test_select.rb +5 -2
  56. data/test/test_select_all.rb +1 -1
  57. data/test/test_select_none.rb +1 -1
  58. data/test/test_select_noopts.rb +5 -3
  59. data/test/test_set_fields.rb +1 -1
  60. data/test/test_ssl_server.rb +1 -1
  61. metadata +23 -5
  62. metadata.gz.sig +1 -2
@@ -17,7 +17,7 @@ module Enumerable
17
17
  end
18
18
  end
19
19
 
20
- class TestMechanizeCookie < Test::Unit::TestCase
20
+ class TestMechanizeCookie < MiniTest::Unit::TestCase
21
21
  def silently
22
22
  warn_level = $VERBOSE
23
23
  $VERBOSE = false
@@ -183,7 +183,7 @@ class TestMechanizeCookie < Test::Unit::TestCase
183
183
  end
184
184
  cookie = nil
185
185
  Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
186
- assert_not_nil(cookie)
186
+
187
187
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
188
188
  assert_equal('/', cookie.path)
189
189
 
@@ -218,7 +218,7 @@ class TestMechanizeCookie < Test::Unit::TestCase
218
218
  end
219
219
  cookie = nil
220
220
  Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
221
- assert_not_nil(cookie)
221
+
222
222
  assert_equal('12345%7D=', cookie.to_s)
223
223
  assert_equal('', cookie.value)
224
224
  assert_equal('/', cookie.path)
@@ -256,7 +256,7 @@ class TestMechanizeCookie < Test::Unit::TestCase
256
256
  end
257
257
  cookie = nil
258
258
  Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
259
- assert_not_nil(cookie)
259
+
260
260
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
261
261
  assert_equal('/', cookie.path)
262
262
 
@@ -293,7 +293,7 @@ class TestMechanizeCookie < Test::Unit::TestCase
293
293
  end
294
294
  cookie = nil
295
295
  Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
296
- assert_not_nil(cookie)
296
+
297
297
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
298
298
  assert_equal('/', cookie.path)
299
299
  assert_equal(true, cookie.secure)
@@ -329,7 +329,7 @@ class TestMechanizeCookie < Test::Unit::TestCase
329
329
  end
330
330
  cookie = nil
331
331
  Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
332
- assert_not_nil(cookie)
332
+
333
333
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
334
334
  assert_equal('/', cookie.path)
335
335
 
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
  require 'tmpdir'
3
3
 
4
- class TestMechanizeCookieJar < Test::Unit::TestCase
4
+ class TestMechanizeCookieJar < MiniTest::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  @jar = Mechanize::CookieJar.new
@@ -378,9 +378,10 @@ class TestMechanizeCookieJar < Test::Unit::TestCase
378
378
 
379
379
  @jar.jar['rubyforge.org'] = {}
380
380
 
381
- assert_nothing_raised do
382
- @jar.add(url, cookie_from_hash(cookie_values))
383
- end
381
+
382
+ @jar.add url, cookie_from_hash(cookie_values)
383
+
384
+ # HACK no asertion
384
385
  end
385
386
 
386
387
  def test_ssl_cookies
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class TestMechanizeFile < Test::Unit::TestCase
3
+ class TestMechanizeFile < MiniTest::Unit::TestCase
4
4
  def test_content_disposition
5
5
  file = Mechanize::File.new(
6
6
  URI.parse('http://localhost/foo'),
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeFileRequest < Test::Unit::TestCase
3
+ class TestMechanizeFileRequest < MiniTest::Unit::TestCase
4
4
 
5
5
  def test_initialize
6
6
  uri = URI.parse 'http://example/'
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeFileConnection < Test::Unit::TestCase
3
+ class TestMechanizeFileConnection < MiniTest::Unit::TestCase
4
4
 
5
5
  def test_request
6
6
  uri = URI.parse "file://#{File.expand_path __FILE__}"
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class TestMechanizeForm < Test::Unit::TestCase
3
+ class TestMechanizeForm < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @agent = Mechanize.new
@@ -24,10 +24,10 @@ class TestMechanizeForm < Test::Unit::TestCase
24
24
  def test_field_with
25
25
  page = @agent.get("http://localhost/google.html")
26
26
  search = page.forms.find { |f| f.name == "f" }
27
- assert_not_nil(search)
28
- assert_not_nil(search.field_with(:name => 'q'))
29
- assert_not_nil(search.field_with(:name => 'hl'))
30
- assert_not_nil(search.fields.find { |f| f.name == 'ie' })
27
+
28
+ assert(search.field_with(:name => 'q'))
29
+ assert(search.field_with(:name => 'hl'))
30
+ assert(search.fields.find { |f| f.name == 'ie' })
31
31
  end
32
32
 
33
33
  def test_fields_no_input_name
@@ -114,7 +114,6 @@ class TestMechanizeForm < Test::Unit::TestCase
114
114
  page = @agent.get("http://localhost/form_multival.html")
115
115
  form = page.form_with(:name => 'post_form')
116
116
 
117
- assert_not_nil(form)
118
117
  assert_equal(2, form.fields_with(:name => 'first').length)
119
118
 
120
119
  form.fields_with(:name => 'first')[0].value = 'Aaron'
@@ -122,11 +121,9 @@ class TestMechanizeForm < Test::Unit::TestCase
122
121
 
123
122
  page = @agent.submit(form)
124
123
 
125
- assert_not_nil(page)
126
-
127
124
  assert_equal(2, page.links.length)
128
- assert_not_nil(page.link_with(:text => 'first:Aaron'))
129
- assert_not_nil(page.link_with(:text => 'first:Patterson'))
125
+ assert(page.link_with(:text => 'first:Aaron'))
126
+ assert(page.link_with(:text => 'first:Patterson'))
130
127
  end
131
128
 
132
129
  # Test calling submit on the form object
@@ -134,7 +131,6 @@ class TestMechanizeForm < Test::Unit::TestCase
134
131
  page = @agent.get("http://localhost/form_multival.html")
135
132
  form = page.form_with(:name => 'post_form')
136
133
 
137
- assert_not_nil(form)
138
134
  assert_equal(2, form.fields_with(:name => 'first').length)
139
135
 
140
136
  form.fields_with(:name => 'first')[0].value = 'Aaron'
@@ -142,11 +138,9 @@ class TestMechanizeForm < Test::Unit::TestCase
142
138
 
143
139
  page = form.submit
144
140
 
145
- assert_not_nil(page)
146
-
147
141
  assert_equal(2, page.links.length)
148
- assert_not_nil(page.link_with(:text => 'first:Aaron'))
149
- assert_not_nil(page.link_with(:text => 'first:Patterson'))
142
+ assert(page.link_with(:text => 'first:Aaron'))
143
+ assert(page.link_with(:text => 'first:Patterson'))
150
144
  end
151
145
 
152
146
  # Test submitting form with two fields of the same name
@@ -154,7 +148,6 @@ class TestMechanizeForm < Test::Unit::TestCase
154
148
  page = @agent.get("http://localhost/form_multival.html")
155
149
  form = page.form_with(:name => 'get_form')
156
150
 
157
- assert_not_nil(form)
158
151
  assert_equal(2, form.fields_with(:name => 'first').length)
159
152
 
160
153
  form.fields_with(:name => 'first')[0].value = 'Aaron'
@@ -162,11 +155,9 @@ class TestMechanizeForm < Test::Unit::TestCase
162
155
 
163
156
  page = @agent.submit(form)
164
157
 
165
- assert_not_nil(page)
166
-
167
158
  assert_equal(2, page.links.length)
168
- assert_not_nil(page.link_with(:text => 'first:Aaron'))
169
- assert_not_nil(page.link_with(:text => 'first:Patterson'))
159
+ assert(page.link_with(:text => 'first:Aaron'))
160
+ assert(page.link_with(:text => 'first:Patterson'))
170
161
  end
171
162
 
172
163
  def test_post_with_non_strings
@@ -179,7 +170,7 @@ class TestMechanizeForm < Test::Unit::TestCase
179
170
  def test_post
180
171
  page = @agent.get("http://localhost/form_test.html")
181
172
  post_form = page.forms.find { |f| f.name == "post_form1" }
182
- assert_not_nil(post_form, "Post form is null")
173
+
183
174
  assert_equal("post", post_form.method.downcase)
184
175
  assert_equal("/form_post", post_form.action)
185
176
 
@@ -188,28 +179,22 @@ class TestMechanizeForm < Test::Unit::TestCase
188
179
  assert_equal(1, post_form.buttons.size)
189
180
  assert_equal(2, post_form.radiobuttons.size)
190
181
  assert_equal(3, post_form.checkboxes.size)
191
- assert_not_nil(post_form.fields.find { |f| f.name == "first_name" },
192
- "First name field was nil"
193
- )
194
- assert_not_nil(post_form.fields.find { |f| f.name == "country" },
195
- "Country field was nil"
196
- )
197
- assert_not_nil(
198
- post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
199
- "Gender male button was nil"
200
- )
201
-
202
- assert_not_nil(
203
- post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
204
- "Gender female button was nil"
205
- )
206
-
207
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "cool person" },
208
- "couldn't find cool person checkbox")
209
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "likes ham" },
210
- "couldn't find likes ham checkbox")
211
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "green[eggs]" },
212
- "couldn't find green[eggs] checkbox")
182
+ assert(post_form.fields.find { |f| f.name == "first_name" },
183
+ "First name field was nil")
184
+ assert(post_form.fields.find { |f| f.name == "country" },
185
+ "Country field was nil")
186
+ assert(post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
187
+ "Gender male button was nil")
188
+
189
+ assert(post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
190
+ "Gender female button was nil")
191
+
192
+ assert(post_form.checkboxes.find { |f| f.name == "cool person" },
193
+ "couldn't find cool person checkbox")
194
+ assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
195
+ "couldn't find likes ham checkbox")
196
+ assert(post_form.checkboxes.find { |f| f.name == "green[eggs]" },
197
+ "couldn't find green[eggs] checkbox")
213
198
 
214
199
  # Find the select list
215
200
  s = post_form.fields.find { |f| f.name == "country" }
@@ -231,32 +216,22 @@ class TestMechanizeForm < Test::Unit::TestCase
231
216
 
232
217
  # Check that the submitted fields exist
233
218
  assert_equal(5, page.links.size, "Not enough links")
234
- assert_not_nil(
235
- page.links.find { |l| l.text == "likes ham:on" },
236
- "likes ham check box missing"
237
- )
238
- assert_not_nil(
239
- page.links.find { |l| l.text == "green[eggs]:on" },
240
- "green[eggs] check box missing"
241
- )
242
- assert_not_nil(
243
- page.links.find { |l| l.text == "first_name:Aaron" },
244
- "first_name field missing"
245
- )
246
- assert_not_nil(
247
- page.links.find { |l| l.text == "gender:male" },
248
- "gender field missing"
249
- )
250
- assert_not_nil(
251
- page.links.find { |l| l.text == "country:USA" },
252
- "select box not submitted"
253
- )
219
+ assert(page.links.find { |l| l.text == "likes ham:on" },
220
+ "likes ham check box missing")
221
+ assert(page.links.find { |l| l.text == "green[eggs]:on" },
222
+ "green[eggs] check box missing")
223
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
224
+ "first_name field missing")
225
+ assert(page.links.find { |l| l.text == "gender:male" },
226
+ "gender field missing")
227
+ assert(page.links.find { |l| l.text == "country:USA" },
228
+ "select box not submitted")
254
229
  end
255
230
 
256
231
  def test_post_multipart
257
232
  page = @agent.get("http://localhost/form_test.html")
258
233
  post_form = page.forms.find { |f| f.name == "post_form4_multipart" }
259
- assert_not_nil(post_form, "Post form is null")
234
+ assert(post_form, "Post form is null")
260
235
  assert_equal("post", post_form.method.downcase)
261
236
  assert_equal("/form_post", post_form.action)
262
237
 
@@ -265,22 +240,22 @@ class TestMechanizeForm < Test::Unit::TestCase
265
240
 
266
241
  page = @agent.submit(post_form, post_form.buttons.first)
267
242
 
268
- assert_not_nil(page)
243
+ assert page
269
244
  end
270
245
 
271
246
  def test_select_box
272
247
  page = @agent.get("http://localhost/form_test.html")
273
248
  post_form = page.forms.find { |f| f.name == "post_form1" }
274
- assert_not_nil(post_form, "Post form is null")
275
- assert_not_nil(page.header)
276
- assert_not_nil(page.root)
249
+
250
+ assert(page.header)
251
+ assert(page.root)
277
252
  assert_equal(0, page.iframes.length)
278
253
  assert_equal("post", post_form.method.downcase)
279
254
  assert_equal("/form_post", post_form.action)
280
255
 
281
256
  # Find the select list
282
257
  s = post_form.field_with(:name => /country/)
283
- assert_not_nil(s, "Couldn't find country select list")
258
+
284
259
  assert_equal(2, s.options.length)
285
260
  assert_equal("USA", s.value)
286
261
  assert_equal("USA", s.options.first.value)
@@ -294,41 +269,34 @@ class TestMechanizeForm < Test::Unit::TestCase
294
269
  page = @agent.submit(post_form, post_form.buttons.first)
295
270
 
296
271
  # Check that the submitted fields exist
297
- assert_not_nil(
298
- page.links.find { |l| l.text == "country:CANADA" },
299
- "select box not submitted"
300
- )
272
+ assert(page.links.find { |l| l.text == "country:CANADA" },
273
+ "select box not submitted")
301
274
  end
302
275
 
303
276
  def test_get
304
277
  page = @agent.get("http://localhost/form_test.html")
305
278
  get_form = page.forms.find { |f| f.name == "get_form1" }
306
- assert_not_nil(get_form, "Get form is null")
279
+
307
280
  assert_equal("get", get_form.method.downcase)
308
281
  assert_equal("/form_post", get_form.action)
309
282
  assert_equal(1, get_form.fields.size)
310
283
  assert_equal(2, get_form.buttons.size)
311
284
  assert_equal(2, get_form.radiobuttons.size)
312
285
  assert_equal(3, get_form.checkboxes.size)
313
- assert_not_nil(get_form.fields.find { |f| f.name == "first_name" },
314
- "First name field was nil"
315
- )
316
- assert_not_nil(
317
- get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
318
- "Gender male button was nil"
319
- )
320
-
321
- assert_not_nil(
322
- get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
323
- "Gender female button was nil"
324
- )
325
-
326
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "cool person" },
327
- "couldn't find cool person checkbox")
328
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "likes ham" },
329
- "couldn't find likes ham checkbox")
330
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "green[eggs]" },
331
- "couldn't find green[eggs] checkbox")
286
+ assert(get_form.fields.find { |f| f.name == "first_name" },
287
+ "First name field was nil")
288
+ assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
289
+ "Gender male button was nil")
290
+
291
+ assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
292
+ "Gender female button was nil")
293
+
294
+ assert(get_form.checkboxes.find { |f| f.name == "cool person" },
295
+ "couldn't find cool person checkbox")
296
+ assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
297
+ "couldn't find likes ham checkbox")
298
+ assert(get_form.checkboxes.find { |f| f.name == "green[eggs]" },
299
+ "couldn't find green[eggs] checkbox")
332
300
 
333
301
  # Set up the image button
334
302
  img = get_form.buttons.find { |f| f.name == "button" }
@@ -345,59 +313,42 @@ class TestMechanizeForm < Test::Unit::TestCase
345
313
 
346
314
  # Check that the submitted fields exist
347
315
  assert_equal(6, page.links.size, "Not enough links")
348
- assert_not_nil(
349
- page.links.find { |l| l.text == "likes ham:on" },
350
- "likes ham check box missing"
351
- )
352
- assert_not_nil(
353
- page.links.find { |l| l.text == "green[eggs]:on" },
354
- "green[eggs] check box missing"
355
- )
356
- assert_not_nil(
357
- page.links.find { |l| l.text == "first_name:Aaron" },
358
- "first_name field missing"
359
- )
360
- assert_not_nil(
361
- page.links.find { |l| l.text == "gender:male" },
362
- "gender field missing"
363
- )
364
- assert_not_nil(
365
- page.links.find { |l| l.text == "button.y:10" },
366
- "Image button missing"
367
- )
368
- assert_not_nil(
369
- page.links.find { |l| l.text == "button.x:9" },
370
- "Image button missing"
371
- )
316
+ assert(page.links.find { |l| l.text == "likes ham:on" },
317
+ "likes ham check box missing")
318
+ assert(page.links.find { |l| l.text == "green[eggs]:on" },
319
+ "green[eggs] check box missing")
320
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
321
+ "first_name field missing")
322
+ assert(page.links.find { |l| l.text == "gender:male" },
323
+ "gender field missing")
324
+ assert(page.links.find { |l| l.text == "button.y:10" },
325
+ "Image button missing")
326
+ assert(page.links.find { |l| l.text == "button.x:9" },
327
+ "Image button missing")
372
328
  end
373
329
 
374
330
  def test_post_with_space_in_action
375
331
  page = @agent.get("http://localhost/form_test.html")
376
332
  post_form = page.forms.find { |f| f.name == "post_form2" }
377
- assert_not_nil(post_form, "Post form is null")
333
+
378
334
  assert_equal("post", post_form.method.downcase)
379
335
  assert_equal("/form post", post_form.action)
380
336
  assert_equal(1, post_form.fields.size)
381
337
  assert_equal(1, post_form.buttons.size)
382
338
  assert_equal(2, post_form.radiobuttons.size)
383
339
  assert_equal(2, post_form.checkboxes.size)
384
- assert_not_nil(post_form.fields.find { |f| f.name == "first_name" },
385
- "First name field was nil"
386
- )
387
- assert_not_nil(
388
- post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
389
- "Gender male button was nil"
390
- )
391
-
392
- assert_not_nil(
393
- post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
394
- "Gender female button was nil"
395
- )
396
-
397
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "cool person" },
398
- "couldn't find cool person checkbox")
399
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "likes ham" },
400
- "couldn't find likes ham checkbox")
340
+ assert(post_form.fields.find { |f| f.name == "first_name" },
341
+ "First name field was nil")
342
+ assert(post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
343
+ "Gender male button was nil")
344
+
345
+ assert(post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
346
+ "Gender female button was nil")
347
+
348
+ assert(post_form.checkboxes.find { |f| f.name == "cool person" },
349
+ "couldn't find cool person checkbox")
350
+ assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
351
+ "couldn't find likes ham checkbox")
401
352
 
402
353
  # Now set all the fields
403
354
  post_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
@@ -409,47 +360,36 @@ class TestMechanizeForm < Test::Unit::TestCase
409
360
 
410
361
  # Check that the submitted fields exist
411
362
  assert_equal(3, page.links.size, "Not enough links")
412
- assert_not_nil(
413
- page.links.find { |l| l.text == "likes ham:on" },
414
- "likes ham check box missing"
415
- )
416
- assert_not_nil(
417
- page.links.find { |l| l.text == "first_name:Aaron" },
418
- "first_name field missing"
419
- )
420
- assert_not_nil(
421
- page.links.find { |l| l.text == "gender:male" },
422
- "gender field missing"
423
- )
363
+ assert(page.links.find { |l| l.text == "likes ham:on" },
364
+ "likes ham check box missing")
365
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
366
+ "first_name field missing")
367
+ assert(page.links.find { |l| l.text == "gender:male" },
368
+ "gender field missing")
424
369
  end
425
370
 
426
371
  def test_get_with_space_in_action
427
372
  page = @agent.get("http://localhost/form_test.html")
428
373
  get_form = page.forms.find { |f| f.name == "get_form2" }
429
- assert_not_nil(get_form, "Get form is null")
374
+
430
375
  assert_equal("get", get_form.method.downcase)
431
376
  assert_equal("/form post", get_form.action)
432
377
  assert_equal(1, get_form.fields.size)
433
378
  assert_equal(1, get_form.buttons.size)
434
379
  assert_equal(2, get_form.radiobuttons.size)
435
380
  assert_equal(2, get_form.checkboxes.size)
436
- assert_not_nil(get_form.fields.find { |f| f.name == "first_name" },
437
- "First name field was nil"
438
- )
439
- assert_not_nil(
440
- get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
441
- "Gender male button was nil"
442
- )
443
-
444
- assert_not_nil(
445
- get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
446
- "Gender female button was nil"
447
- )
448
-
449
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "cool person" },
450
- "couldn't find cool person checkbox")
451
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "likes ham" },
452
- "couldn't find likes ham checkbox")
381
+ assert(get_form.fields.find { |f| f.name == "first_name" },
382
+ "First name field was nil")
383
+ assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
384
+ "Gender male button was nil")
385
+
386
+ assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
387
+ "Gender female button was nil")
388
+
389
+ assert(get_form.checkboxes.find { |f| f.name == "cool person" },
390
+ "couldn't find cool person checkbox")
391
+ assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
392
+ "couldn't find likes ham checkbox")
453
393
 
454
394
  # Now set all the fields
455
395
  get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
@@ -461,24 +401,18 @@ class TestMechanizeForm < Test::Unit::TestCase
461
401
 
462
402
  # Check that the submitted fields exist
463
403
  assert_equal(3, page.links.size, "Not enough links")
464
- assert_not_nil(
465
- page.links.find { |l| l.text == "likes ham:on" },
466
- "likes ham check box missing"
467
- )
468
- assert_not_nil(
469
- page.links.find { |l| l.text == "first_name:Aaron" },
470
- "first_name field missing"
471
- )
472
- assert_not_nil(
473
- page.links.find { |l| l.text == "gender:male" },
474
- "gender field missing"
475
- )
404
+ assert(page.links.find { |l| l.text == "likes ham:on" },
405
+ "likes ham check box missing")
406
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
407
+ "first_name field missing")
408
+ assert(page.links.find { |l| l.text == "gender:male" },
409
+ "gender field missing")
476
410
  end
477
411
 
478
412
  def test_post_with_param_in_action
479
413
  page = @agent.get("http://localhost/form_test.html")
480
414
  post_form = page.forms.find { |f| f.name == "post_form3" }
481
- assert_not_nil(post_form, "Post form is null")
415
+
482
416
  assert_equal("post", post_form.method.downcase)
483
417
  assert_equal("/form_post?great day=yes&one=two", post_form.action)
484
418
  assert_equal(1, post_form.fields.size)
@@ -486,24 +420,24 @@ class TestMechanizeForm < Test::Unit::TestCase
486
420
  assert_equal(2, post_form.radiobuttons.size)
487
421
  assert_equal(2, post_form.checkboxes.size)
488
422
 
489
- assert_not_nil(post_form.fields.find { |f| f.name == "first_name" },
490
- "First name field was nil")
423
+ assert(post_form.fields.find { |f| f.name == "first_name" },
424
+ "First name field was nil")
491
425
 
492
426
  male_button = post_form.radiobuttons.find { |f|
493
427
  f.name == "gender" && f.value == "male"
494
428
  }
495
- assert_not_nil(male_button, "Gender male button was nil")
429
+ assert(male_button, "Gender male button was nil")
496
430
 
497
431
  female_button = post_form.radiobuttons.find { |f|
498
432
  f.name == "gender" && f.value == "female"
499
433
  }
500
434
 
501
- assert_not_nil(female_button, "Gender female button was nil")
435
+ assert(female_button, "Gender female button was nil")
502
436
 
503
- assert_not_nil(post_form.checkbox_with(:name => "cool person"),
504
- "couldn't find cool person checkbox")
437
+ assert(post_form.checkbox_with(:name => "cool person"),
438
+ "couldn't find cool person checkbox")
505
439
 
506
- assert_not_nil(post_form.checkboxes.find { |f| f.name == "likes ham" },
440
+ assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
507
441
  "couldn't find likes ham checkbox")
508
442
 
509
443
  # Now set all the fields
@@ -518,41 +452,36 @@ class TestMechanizeForm < Test::Unit::TestCase
518
452
  # Check that the submitted fields exist
519
453
  assert_equal(3, page.links.size, "Not enough links")
520
454
 
521
- assert_not_nil(page.links.find { |l| l.text == "likes ham:on" },
522
- "likes ham check box missing")
523
- assert_not_nil(page.links.find { |l| l.text == "first_name:Aaron" },
524
- "first_name field missing")
525
- assert_not_nil(page.links.find { |l| l.text == "gender:male" },
526
- "gender field missing")
455
+ assert(page.links.find { |l| l.text == "likes ham:on" },
456
+ "likes ham check box missing")
457
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
458
+ "first_name field missing")
459
+ assert(page.links.find { |l| l.text == "gender:male" },
460
+ "gender field missing")
527
461
  end
528
462
 
529
463
  def test_get_with_param_in_action
530
464
  page = @agent.get("http://localhost/form_test.html")
531
465
  get_form = page.forms.find { |f| f.name == "get_form3" }
532
- assert_not_nil(get_form, "Get form is null")
466
+
533
467
  assert_equal("get", get_form.method.downcase)
534
468
  assert_equal("/form_post?great day=yes&one=two", get_form.action)
535
469
  assert_equal(1, get_form.fields.size)
536
470
  assert_equal(1, get_form.buttons.size)
537
471
  assert_equal(2, get_form.radiobuttons.size)
538
472
  assert_equal(2, get_form.checkboxes.size)
539
- assert_not_nil(get_form.fields.find { |f| f.name == "first_name" },
540
- "First name field was nil"
541
- )
542
- assert_not_nil(
543
- get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
544
- "Gender male button was nil"
545
- )
546
-
547
- assert_not_nil(
548
- get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
549
- "Gender female button was nil"
550
- )
551
-
552
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "cool person" },
553
- "couldn't find cool person checkbox")
554
- assert_not_nil(get_form.checkboxes.find { |f| f.name == "likes ham" },
555
- "couldn't find likes ham checkbox")
473
+ assert(get_form.fields.find { |f| f.name == "first_name" },
474
+ "First name field was nil")
475
+ assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
476
+ "Gender male button was nil")
477
+
478
+ assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
479
+ "Gender female button was nil")
480
+
481
+ assert(get_form.checkboxes.find { |f| f.name == "cool person" },
482
+ "couldn't find cool person checkbox")
483
+ assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
484
+ "couldn't find likes ham checkbox")
556
485
 
557
486
  # Now set all the fields
558
487
  get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
@@ -563,18 +492,12 @@ class TestMechanizeForm < Test::Unit::TestCase
563
492
  page = @agent.submit(get_form, get_form.buttons.first)
564
493
  # Check that the submitted fields exist
565
494
  assert_equal(3, page.links.size, "Not enough links")
566
- assert_not_nil(
567
- page.links.find { |l| l.text == "likes ham:on" },
568
- "likes ham check box missing"
569
- )
570
- assert_not_nil(
571
- page.links.find { |l| l.text == "first_name:Aaron" },
572
- "first_name field missing"
573
- )
574
- assert_not_nil(
575
- page.links.find { |l| l.text == "gender:male" },
576
- "gender field missing"
577
- )
495
+ assert(page.links.find { |l| l.text == "likes ham:on" },
496
+ "likes ham check box missing")
497
+ assert(page.links.find { |l| l.text == "first_name:Aaron" },
498
+ "first_name field missing")
499
+ assert(page.links.find { |l| l.text == "gender:male" },
500
+ "gender field missing")
578
501
  end
579
502
 
580
503
  def test_field_addition
@@ -588,7 +511,6 @@ class TestMechanizeForm < Test::Unit::TestCase
588
511
  page = @agent.get("http://localhost/form_multival.html")
589
512
  form = page.form_with(:name => 'post_form')
590
513
 
591
- assert_not_nil(form)
592
514
  assert_equal(2, form.fields_with(:name => 'first').length)
593
515
 
594
516
  form.first = 'Aaron'
@@ -601,8 +523,6 @@ class TestMechanizeForm < Test::Unit::TestCase
601
523
  form = page.form_with(:dom_id => 'generic_form')
602
524
  form_by_id = page.form_with(:id => 'generic_form')
603
525
 
604
-
605
- assert_not_nil(form)
606
526
  assert_equal(1, form.fields_with(:dom_id => 'name_first').length)
607
527
  assert_equal('first_name', form.field_with(:dom_id => 'name_first').name)
608
528
 
@@ -615,11 +535,9 @@ class TestMechanizeForm < Test::Unit::TestCase
615
535
  page = @agent.get("http://localhost/form_multival.html")
616
536
  form = page.form_with(:name => 'post_form')
617
537
 
618
- assert_not_nil(form)
619
538
  number_of_fields = form.fields.length
620
539
 
621
- f = form.add_field!('intarweb')
622
- assert_not_nil(f)
540
+ assert form.add_field!('intarweb')
623
541
  assert_equal(number_of_fields + 1, form.fields.length)
624
542
  end
625
543
 
@@ -627,7 +545,6 @@ class TestMechanizeForm < Test::Unit::TestCase
627
545
  page = @agent.get("http://localhost/form_multival.html")
628
546
  form = page.form_with(:name => 'post_form')
629
547
 
630
- assert_not_nil(form)
631
548
  number_of_fields = form.fields.length
632
549
  assert_equal 2, number_of_fields
633
550
 
@@ -640,21 +557,19 @@ class TestMechanizeForm < Test::Unit::TestCase
640
557
  page = @agent.get("http://localhost/form_multival.html")
641
558
  form = page.form_with(:name => 'post_form')
642
559
 
643
- assert_not_nil(form)
644
560
  assert(!form.has_field?('intarweb'))
645
- f = form.add_field!('intarweb')
646
- assert_not_nil(f)
561
+ assert form.add_field!('intarweb')
647
562
  assert(form.has_field?('intarweb'))
648
563
  end
649
564
 
650
565
  def test_field_error
651
566
  @page = @agent.get('http://localhost/empty_form.html')
652
567
  form = @page.forms.first
653
- assert_raise(NoMethodError) {
568
+ assert_raises(NoMethodError) {
654
569
  form.foo = 'asdfasdf'
655
570
  }
656
571
 
657
- assert_raise(NoMethodError) {
572
+ assert_raises(NoMethodError) {
658
573
  form.foo
659
574
  }
660
575
  end