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
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeFormCheckBox < Test::Unit::TestCase
3
+ class TestMechanizeFormCheckBox < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @agent = Mechanize.new
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  require "helper"
3
3
 
4
- class TestMechanizeFormEncoding < Test::Unit::TestCase
4
+ class TestMechanizeFormEncoding < MiniTest::Unit::TestCase
5
5
 
6
6
  # See also: tests of Util.from_native_charset
7
7
  # Encoding test should do with non-utf-8 characters
@@ -41,7 +41,7 @@ class TestMechanizeFormEncoding < Test::Unit::TestCase
41
41
 
42
42
  assert accept_charset
43
43
  assert_equal accept_charset, form.encoding
44
- assert_not_equal page.encoding, form.encoding
44
+ refute_equal page.encoding, form.encoding
45
45
  end
46
46
 
47
47
  def test_form_encoding_returns_page_encoding_when_no_accept_charset
@@ -50,7 +50,7 @@ class TestMechanizeFormEncoding < Test::Unit::TestCase
50
50
  accept_charset = form.form_node['accept-charset']
51
51
 
52
52
  assert_nil accept_charset
53
- assert_not_equal accept_charset, form.encoding
53
+ refute_equal accept_charset, form.encoding
54
54
  assert_equal page.encoding, form.encoding
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ class TestMechanizeFormEncoding < Test::Unit::TestCase
58
58
  page = @agent.get("http://localhost/form_set_fields.html")
59
59
  form = page.forms.first
60
60
 
61
- assert_not_equal CONTENT_ENCODING, form.encoding
61
+ refute_equal CONTENT_ENCODING, form.encoding
62
62
 
63
63
  form.encoding = CONTENT_ENCODING
64
64
 
@@ -93,14 +93,16 @@ class TestMechanizeFormEncoding < Test::Unit::TestCase
93
93
  def test_post_form_with_problematic_encoding
94
94
  form = set_form_with_encoding INVALID_ENCODING
95
95
 
96
- assert_raise(*ENCODING_ERRORS){ form.submit }
96
+ assert_raises(*ENCODING_ERRORS){ form.submit }
97
97
  end
98
98
 
99
99
  def test_form_ignore_encoding_error_is_true
100
100
  form = set_form_with_encoding INVALID_ENCODING
101
101
  form.ignore_encoding_error = true
102
102
 
103
- assert_nothing_raised(*ENCODING_ERRORS){ form.submit }
103
+ form.submit
104
+
105
+ # HACK no assertions
104
106
  end
105
107
 
106
108
  def test_post_form_logs_form_encoding
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeFormField < Test::Unit::TestCase
3
+ class TestMechanizeFormField < MiniTest::Unit::TestCase
4
4
 
5
5
  def test_field_spaceship
6
6
  doc = Nokogiri::HTML::Document.new
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeFormImageButton < Test::Unit::TestCase
3
+ class TestMechanizeFormImageButton < MiniTest::Unit::TestCase
4
4
 
5
5
  def test_query_value
6
6
  button = Mechanize::Form::ImageButton.new 'name' => 'image_button'
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class TestMechanizeFormTextarea < Test::Unit::TestCase
3
+ class TestMechanizeFormTextarea < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @agent = Mechanize.new
6
6
  @page = @agent.get("http://localhost/tc_textarea.html")
@@ -26,20 +26,26 @@ class TestMechanizeFormTextarea < Test::Unit::TestCase
26
26
 
27
27
  def test_multi_textfield
28
28
  form = @page.form_with(:name => 'form3')
29
+
29
30
  assert_equal(2, form.fields_with(:name => 'text1').length)
30
31
  assert_equal('', form.fields_with(:name => 'text1')[0].value)
31
32
  assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
33
+
32
34
  form.text1 = 'Hello World'
35
+
33
36
  assert_equal('Hello World', form.fields_with(:name => 'text1')[0].value)
34
37
  assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
38
+
35
39
  page = @agent.submit(form)
40
+
36
41
  assert_equal(2, page.links.length)
42
+
37
43
  link = page.links_with(:text => 'text1:sample text')
38
- assert_not_nil(link)
44
+
39
45
  assert_equal(1, link.length)
40
46
 
41
47
  link = page.links_with(:text => 'text1:Hello World')
42
- assert_not_nil(link)
48
+
43
49
  assert_equal(1, link.length)
44
50
  end
45
51
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestMechanizeHttpAgent < Test::Unit::TestCase
4
+ class TestMechanizeHttpAgent < MiniTest::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  @mech = Mechanize.new
@@ -95,7 +95,7 @@ class TestMechanizeHttpAgent < Test::Unit::TestCase
95
95
 
96
96
  def test_get_robots
97
97
  robotstxt = @agent.get_robots 'http://localhost/robots.txt'
98
- assert_not_equal '', robotstxt
98
+ refute_equal '', robotstxt
99
99
 
100
100
  robotstxt = @agent.get_robots 'http://localhost/response_code?code=404'
101
101
  assert_equal '', robotstxt
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class TestMechanizeLink < Test::Unit::TestCase
3
+ class TestMechanizeLink < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @agent = Mechanize.new
@@ -9,7 +9,7 @@ class TestMechanizeLink < Test::Unit::TestCase
9
9
  def test_click
10
10
  page = @agent.get("http://localhost/frame_test.html")
11
11
  link = page.link_with(:text => "Form Test")
12
- assert_not_nil(link)
12
+
13
13
  assert_equal('Form Test', link.text)
14
14
  page = link.click
15
15
  assert_equal("http://localhost/form_test.html",
@@ -25,16 +25,17 @@ class TestMechanizeLink < Test::Unit::TestCase
25
25
  def test_click_unsupported_scheme
26
26
  page = @agent.get("http://google.com/tc_links.html")
27
27
  link = page.link_with(:text => 'javascript link')
28
- assert_raise(Mechanize::UnsupportedSchemeError) {
28
+ assert_raises Mechanize::UnsupportedSchemeError do
29
29
  link.click
30
- }
30
+ end
31
31
 
32
32
  @agent.scheme_handlers['javascript'] = lambda { |my_link, my_page|
33
33
  URI.parse('http://localhost/tc_links.html')
34
34
  }
35
- assert_nothing_raised {
36
- link.click
37
- }
35
+
36
+ link.click
37
+
38
+ # HACK no assertion
38
39
  end
39
40
 
40
41
  def test_text_alt_text
@@ -4,7 +4,7 @@ require 'cgi'
4
4
 
5
5
  # tests for Page encoding and charset and parsing
6
6
 
7
- class TestMechanizePageEncoding < Test::Unit::TestCase
7
+ class TestMechanizePageEncoding < MiniTest::Unit::TestCase
8
8
 
9
9
  MECH_ASCII_ENCODING = Mechanize::Util::NEW_RUBY_ENCODING ? 'US-ASCII' : 'ISO-8859-1'
10
10
 
@@ -3,7 +3,7 @@
3
3
  require 'helper'
4
4
  require 'cgi'
5
5
 
6
- class TestMechanizePage < Test::Unit::TestCase
6
+ class TestMechanizePage < MiniTest::Unit::TestCase
7
7
 
8
8
  WINDOWS_1255 = <<-HTML
9
9
  <meta http-equiv="content-type" content="text/html; charset=windows-1255">
@@ -290,7 +290,10 @@ class TestMechanizePage < Test::Unit::TestCase
290
290
  def test_link_with_unusual_characters
291
291
  page = @agent.get("http://localhost/tc_links.html")
292
292
  link = page.link_with(:text => 'unusual characters')
293
- assert_nothing_raised { @agent.click link }
293
+
294
+ @agent.click link
295
+
296
+ # HACK no assertion
294
297
  end
295
298
 
296
299
  def test_links
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizePageMetaRefresh < Test::Unit::TestCase
3
+ class TestMechanizePageMetaRefresh < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @MR = Mechanize::Page::MetaRefresh
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TestMechanizeRedirectNotGetOrHead < Test::Unit::TestCase
3
+ class TestMechanizeRedirectNotGetOrHead < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @agent = Mechanize.new
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class TestMechanizeSubclass < Test::Unit::TestCase
3
+ class TestMechanizeSubclass < MiniTest::Unit::TestCase
4
4
 
5
5
  class Parent < Mechanize
6
6
  @html_parser = :parser
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  require 'helper'
3
3
 
4
- class TestMechanizeUtil < Test::Unit::TestCase
4
+ class TestMechanizeUtil < MiniTest::Unit::TestCase
5
5
 
6
6
  INPUTTED_VALUE = "テスト" # "test" in Japanese UTF-8 encoding
7
7
  CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
@@ -19,7 +19,7 @@ class TestMechanizeUtil < Test::Unit::TestCase
19
19
  INVALID_ENCODING = 'UTF-eight'
20
20
 
21
21
  def setup
22
- @result = "non_nil"
22
+ @result = "not set"
23
23
  end
24
24
 
25
25
  def test_from_native_charset
@@ -34,7 +34,7 @@ class TestMechanizeUtil < Test::Unit::TestCase
34
34
 
35
35
  def test_from_native_charset_doesnot_convert_when_no_encoding
36
36
  @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, nil)
37
- assert_not_equal ENCODED_VALUE, @result
37
+ refute_equal ENCODED_VALUE, @result
38
38
  assert_equal INPUTTED_VALUE, @result
39
39
  end
40
40
 
@@ -43,28 +43,28 @@ class TestMechanizeUtil < Test::Unit::TestCase
43
43
  Mechanize.html_parser = 'Another HTML Parser'
44
44
 
45
45
  @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, CONTENT_ENCODING)
46
- assert_not_equal ENCODED_VALUE, @result
46
+ refute_equal ENCODED_VALUE, @result
47
47
  assert_equal INPUTTED_VALUE, @result
48
-
48
+ ensure
49
49
  Mechanize.html_parser = parser
50
50
  end
51
51
 
52
52
  def test_from_native_charset_raises_error_with_bad_encoding
53
- assert_raise(*ENCODING_ERRORS){
54
- @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING)
55
- }
53
+ assert_raises(*ENCODING_ERRORS) do
54
+ Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING)
55
+ end
56
56
  end
57
57
 
58
58
  def test_from_native_charset_suppress_encoding_error_when_3rd_arg_is_true
59
- assert_nothing_raised(*ENCODING_ERRORS){
60
- @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true)
61
- }
59
+ Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true)
60
+
61
+ # HACK no assertion
62
62
  end
63
63
 
64
64
  def test_from_native_charset_doesnot_convert_when_encoding_error_raised_and_ignored
65
65
  @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true)
66
66
 
67
- assert_not_equal ENCODED_VALUE, @result
67
+ refute_equal ENCODED_VALUE, @result
68
68
  assert_equal INPUTTED_VALUE, @result
69
69
  end
70
70
 
@@ -73,9 +73,10 @@ class TestMechanizeUtil < Test::Unit::TestCase
73
73
  log = Logger.new(sio)
74
74
  log.level = Logger::DEBUG
75
75
 
76
- assert_raise(*ENCODING_ERRORS){
77
- @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, nil, log)
78
- }
76
+ assert_raises(*ENCODING_ERRORS) do
77
+ Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, nil, log)
78
+ end
79
+
79
80
  assert_match ERROR_LOG_MESSAGE, sio.string
80
81
  end
81
82
 
@@ -84,9 +85,8 @@ class TestMechanizeUtil < Test::Unit::TestCase
84
85
  log = Logger.new(sio)
85
86
  log.level = Logger::DEBUG
86
87
 
87
- assert_nothing_raised(*ENCODING_ERRORS){
88
- @result = Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true, log)
89
- }
88
+ Mechanize::Util.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true, log)
89
+
90
90
  assert_match ERROR_LOG_MESSAGE, sio.string
91
91
  end
92
92
  end
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class MultiSelectTest < Test::Unit::TestCase
3
+ class MultiSelectTest < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @agent = Mechanize.new
6
6
  @page = @agent.get("http://localhost/form_multi_select.html")
@@ -1,13 +1,13 @@
1
1
  require "helper"
2
2
 
3
- class TestNoAttributes < Test::Unit::TestCase
3
+ class TestNoAttributes < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @agent = Mechanize.new
6
6
  end
7
7
 
8
8
  def test_parse_no_attributes
9
- assert_nothing_raised do
10
- @agent.get('http://localhost/tc_no_attributes.html')
11
- end
9
+ @agent.get('http://localhost/tc_no_attributes.html')
10
+
11
+ # HACK no assertions
12
12
  end
13
13
  end
data/test/test_option.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class OptionTest < Test::Unit::TestCase
3
+ class OptionTest < MiniTest::Unit::TestCase
4
4
  class FakeAttribute < Hash
5
5
  attr_reader :inner_text
6
6
  def initialize(inner_text)
@@ -1,30 +1,21 @@
1
1
  require "helper"
2
2
 
3
- class PluggableParserTest < Test::Unit::TestCase
3
+ class PluggableParserTest < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @agent = Mechanize.new
6
6
  end
7
7
 
8
8
  def test_content_type_error
9
9
  page = @agent.get("http://localhost/bad_content_type")
10
- assert_raise(Mechanize::ContentTypeError) {
11
- page = Mechanize::Page.new(
12
- page.uri,
13
- page.response,
14
- page.body,
15
- page.code
16
- )
17
- }
18
- begin
19
- page = Mechanize::Page.new(
20
- page.uri,
21
- page.response,
22
- page.body,
23
- page.code
24
- )
25
- rescue Mechanize::ContentTypeError => ex
26
- assert_equal('text/xml', ex.content_type)
10
+
11
+ e = assert_raises Mechanize::ContentTypeError do
12
+ page = Mechanize::Page.new(page.uri,
13
+ page.response,
14
+ page.body,
15
+ page.code)
27
16
  end
17
+
18
+ assert_equal('text/xml', e.content_type)
28
19
  end
29
20
 
30
21
  def test_content_type
@@ -55,9 +46,10 @@ class PluggableParserTest < Test::Unit::TestCase
55
46
  def test_filter
56
47
  @agent.pluggable_parser.html = Filter
57
48
  page = @agent.get("http://localhost/find_link.html")
49
+
58
50
  assert_kind_of(Filter, page)
51
+
59
52
  assert_equal(19, page.links.length)
60
- assert_not_nil(page.link_with(:text => 'Net::DAAP::Client'))
61
53
  assert_equal(1, page.links_with(:text => 'Net::DAAP::Client').length)
62
54
  end
63
55
 
@@ -68,7 +60,6 @@ class PluggableParserTest < Test::Unit::TestCase
68
60
  assert_equal(Filter, @agent.pluggable_parser['text/html'])
69
61
  assert_kind_of(Filter, page)
70
62
  assert_equal(19, page.links.length)
71
- assert_not_nil(page.link_with(:text => 'Net::DAAP::Client'))
72
63
  assert_equal(1, page.links_with(:text => 'Net::DAAP::Client').length)
73
64
  end
74
65
 
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class PostForm < Test::Unit::TestCase
3
+ class PostForm < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @agent = Mechanize.new
6
6
  end
@@ -9,10 +9,8 @@ class PostForm < Test::Unit::TestCase
9
9
  page = @agent.post("http://localhost/form_post",
10
10
  'gender' => 'female'
11
11
  )
12
- assert_not_nil(
13
- page.links.find { |l| l.text == "gender:female" },
14
- "gender field missing"
15
- )
12
+ assert(page.links.find { |l| l.text == "gender:female" },
13
+ "gender field missing")
16
14
  end
17
15
 
18
16
  def test_post_form_json
@@ -28,14 +26,12 @@ class PostForm < Test::Unit::TestCase
28
26
  ['gender', 'male']
29
27
  ]
30
28
  )
31
- assert_not_nil(
32
- page.links.find { |l| l.text == "gender:female" },
33
- "gender field missing"
34
- )
35
- assert_not_nil(
36
- page.links.find { |l| l.text == "gender:male" },
37
- "gender field missing"
38
- )
29
+ assert(page.links.find { |l| l.text == "gender:female" },
30
+ "gender field missing")
31
+
32
+ assert(page.links.find { |l| l.text == "gender:male" },
33
+ "gender field missing")
34
+
39
35
  assert_equal(2, page.links.length)
40
36
  end
41
37
  end