mechanize 2.7.2 → 2.7.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 540e567d390aebe104b22b2c11c726c9bceef098
4
- data.tar.gz: c86f1051ac42694d9390856a53724a1b76019a35
3
+ metadata.gz: c12fbfdafc2cf8b5e94edf3db704c3ed421331f9
4
+ data.tar.gz: 0993d3a38d4241baa07167ba77a74cdd378e58fd
5
5
  SHA512:
6
- metadata.gz: 949355d69adf7c58dfa355508e25044535f2880f7a7640d29ee8177d354850fb972dc625c4fac32c7b7e7496d5ca9eae94ad3fb47fc4ee37a45ad9d19f3a10d7
7
- data.tar.gz: c0a04825b124542b1d5eee4749402bfe64de7ba49b52952054f1fe92cd2d6607628174e76d8d2ca3f8be90b0da46871cb26db55be0fc3bf388ff0c266daf82f7
6
+ metadata.gz: 3f07973adedd7639b1dd91e37c91ec7d74a1d5ad85ff87b2668f7ecedd30c0e12d6a954b3fe3634764a29f745cec6084eb83b795fd9ee46203d8b8653d0f3cb1
7
+ data.tar.gz: a89b922deb0fd98ba15d35a7a130e28b373082d3a9505885594bb8c4689b5014cbf6a46238385bd9d046ce8f6ba42abc552c2cf97f90acc2b6521722463f3b3e
@@ -1,5 +1,16 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ === 2.7.3
4
+
5
+ * New Features
6
+ * Allow net-http-persistent instance to be named. #324, John Weir.
7
+ * #save and #save! return filename #340
8
+ * Updated mime-types requirement to 2.x versions. #348 by Jeff Nyman.
9
+
10
+ * Bug fix
11
+ * Ensure Download#save! defaults back to original filename if
12
+ none is provided (#300)
13
+
3
14
  === 2.7.2
4
15
 
5
16
  * Bug fix
@@ -21,6 +21,7 @@ lib/mechanize/cookie_jar.rb
21
21
  lib/mechanize/directory_saver.rb
22
22
  lib/mechanize/download.rb
23
23
  lib/mechanize/element_matcher.rb
24
+ lib/mechanize/element_not_found_error.rb
24
25
  lib/mechanize/file.rb
25
26
  lib/mechanize/file_connection.rb
26
27
  lib/mechanize/file_request.rb
@@ -159,6 +160,7 @@ test/test_mechanize_cookie.rb
159
160
  test/test_mechanize_cookie_jar.rb
160
161
  test/test_mechanize_directory_saver.rb
161
162
  test/test_mechanize_download.rb
163
+ test/test_mechanize_element_not_found_error.rb
162
164
  test/test_mechanize_file.rb
163
165
  test/test_mechanize_file_connection.rb
164
166
  test/test_mechanize_file_request.rb
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ hoe = Hoe.spec 'mechanize' do
20
20
 
21
21
  self.extra_deps << ['net-http-digest_auth', '~> 1.1', '>= 1.1.1']
22
22
  self.extra_deps << ['net-http-persistent', '~> 2.5', '>= 2.5.2']
23
- self.extra_deps << ['mime-types', '~> 1.17', '>= 1.17.2']
24
- self.extra_deps << ['http-cookie', '~> 1.0.0']
23
+ self.extra_deps << ['mime-types', '~> 2.0']
24
+ self.extra_deps << ['http-cookie', '~> 1.0']
25
25
  self.extra_deps << ['nokogiri', '~> 1.4']
26
26
  self.extra_deps << ['ntlm-http', '~> 0.1', '>= 0.1.1']
27
27
  self.extra_deps << ['webrobots', '< 0.2', '>= 0.0.9']
@@ -73,7 +73,7 @@ class Mechanize
73
73
  ##
74
74
  # The version of Mechanize you are using.
75
75
 
76
- VERSION = '2.7.2'
76
+ VERSION = '2.7.3'
77
77
 
78
78
  ##
79
79
  # Base mechanize error class
@@ -169,9 +169,17 @@ class Mechanize
169
169
  # a.proxy_host = 'proxy.example'
170
170
  # a.proxy_port = 8080
171
171
  # end
172
+ #
173
+ # If you need segregated SSL connections give each agent a unique
174
+ # name. Otherwise the connections will be shared. This is
175
+ # particularly important if you are using certifcates.
176
+ #
177
+ # agent_1 = Mechanize.new 'conn1'
178
+ # agent_2 = Mechanize.new 'conn2'
179
+ #
172
180
 
173
- def initialize
174
- @agent = Mechanize::HTTP::Agent.new
181
+ def initialize(connection_name = 'mechanize')
182
+ @agent = Mechanize::HTTP::Agent.new(connection_name)
175
183
  @agent.context = self
176
184
  @log = nil
177
185
 
@@ -1285,6 +1293,7 @@ Use of #auth and #basic_auth are deprecated due to a security vulnerability.
1285
1293
 
1286
1294
  end
1287
1295
 
1296
+ require 'mechanize/element_not_found_error'
1288
1297
  require 'mechanize/response_read_error'
1289
1298
  require 'mechanize/chunked_termination_error'
1290
1299
  require 'mechanize/content_type_error'
@@ -51,6 +51,7 @@ class Mechanize::Download
51
51
 
52
52
  ##
53
53
  # Saves a copy of the body_io to +filename+
54
+ # returns the filename
54
55
 
55
56
  def save filename = nil
56
57
  filename = find_free_name filename
@@ -63,8 +64,10 @@ class Mechanize::Download
63
64
  # Use this method to save the content of body_io to +filename+.
64
65
  # This method will overwrite any existing filename that exists with the
65
66
  # same name.
67
+ # returns the filename
66
68
 
67
69
  def save! filename = nil
70
+ filename ||= @filename
68
71
  dirname = File.dirname filename
69
72
  FileUtils.mkdir_p dirname
70
73
 
@@ -73,6 +76,8 @@ class Mechanize::Download
73
76
  io.write @body_io.read 16384
74
77
  end
75
78
  end
79
+
80
+ filename
76
81
  end
77
82
 
78
83
  end
@@ -28,6 +28,13 @@ module Mechanize::ElementMatcher
28
28
  f
29
29
  end
30
30
 
31
+ def #{singular}_with! criteria = {}
32
+ f = #{singular}_with(criteria)
33
+ raise Mechanize::ElementNotFoundError.new(self, :#{singular}, criteria) if f.nil?
34
+ yield f if block_given?
35
+ f
36
+ end
37
+
31
38
  def select_#{plural} selector
32
39
  if selector.nil? then
33
40
  #{plural}
@@ -0,0 +1,19 @@
1
+ ##
2
+ # Raised when an an element was not found on the Page
3
+
4
+ class Mechanize::ElementNotFoundError < Mechanize::Error
5
+
6
+ attr_reader :source
7
+ attr_reader :element
8
+ attr_reader :conditions
9
+
10
+ def initialize source, element, conditions
11
+ @source = source
12
+ @element = element
13
+ @conditions = conditions
14
+
15
+ super "Element #{element} with conditions #{conditions} was not found"
16
+ end
17
+
18
+ end
19
+
@@ -50,10 +50,15 @@ class Mechanize::File
50
50
 
51
51
  ##
52
52
  # Use this method to save the content of this object to +filename+.
53
+ # returns the filename
53
54
  #
54
55
  # file.save 'index.html'
55
- # file.save 'index.html' # saves index.html.1
56
- # file.save 'index.html'
56
+ # file.save 'index.html' # saves to index.html.1
57
+ #
58
+ # uri = URI 'http://localhost/test.html'
59
+ # file = Mechanize::File.new uri, nil, ''
60
+ # filename = file.save # saves to test.html
61
+ # puts filename # test.html
57
62
 
58
63
  def save filename = nil
59
64
  filename = find_free_name filename
@@ -66,17 +71,22 @@ class Mechanize::File
66
71
  # Use this method to save the content of this object to +filename+.
67
72
  # This method will overwrite any existing filename that exists with the
68
73
  # same name.
74
+ # returns the filename
69
75
  #
70
76
  # file.save 'index.html'
71
77
  # file.save! 'index.html' # overwrite original file
78
+ # filename = file.save! 'index.html' # overwrite original file with filename 'index.html'
72
79
 
73
80
  def save! filename = nil
81
+ filename ||= @filename
74
82
  dirname = File.dirname filename
75
83
  FileUtils.mkdir_p dirname
76
84
 
77
85
  open filename, 'wb' do |f|
78
86
  f.write body
79
87
  end
88
+
89
+ filename
80
90
  end
81
91
 
82
92
  end
@@ -369,6 +369,12 @@ class Mechanize::Form
369
369
  # Example:
370
370
  # form.field_with(:id => "exact_field_id").value = 'hello'
371
371
 
372
+ ##
373
+ # :method: field_with!(criteria)
374
+ #
375
+ # Same as +field_with+ but raises an ElementNotFoundError if no field matches
376
+ # +criteria+
377
+
372
378
  ##
373
379
  # :method: fields_with(criteria)
374
380
  #
@@ -387,6 +393,12 @@ class Mechanize::Form
387
393
  # Example:
388
394
  # form.button_with(:value => /submit/).value = 'hello'
389
395
 
396
+ ##
397
+ # :method: button_with!(criteria)
398
+ #
399
+ # Same as +button_with+ but raises an ElementNotFoundError if no button
400
+ # matches +criteria+
401
+
390
402
  ##
391
403
  # :method: buttons_with(criteria)
392
404
  #
@@ -405,6 +417,12 @@ class Mechanize::Form
405
417
  # Example:
406
418
  # form.file_upload_with(:file_name => /picture/).value = 'foo'
407
419
 
420
+ ##
421
+ # :mehtod: file_upload_with!(criteria)
422
+ #
423
+ # Same as +file_upload_with+ but raises an ElementNotFoundError if no button
424
+ # matches +criteria+
425
+
408
426
  ##
409
427
  # :method: file_uploads_with(criteria)
410
428
  #
@@ -423,6 +441,12 @@ class Mechanize::Form
423
441
  # Example:
424
442
  # form.radiobutton_with(:name => /woo/).check
425
443
 
444
+ ##
445
+ # :mehtod: radiobutton_with!(criteria)
446
+ #
447
+ # Same as +radiobutton_with+ but raises an ElementNotFoundError if no button
448
+ # matches +criteria+
449
+
426
450
  ##
427
451
  # :method: radiobuttons_with(criteria)
428
452
  #
@@ -441,6 +465,12 @@ class Mechanize::Form
441
465
  # Example:
442
466
  # form.checkbox_with(:name => /woo/).check
443
467
 
468
+ ##
469
+ # :mehtod: checkbox_with!(criteria)
470
+ #
471
+ # Same as +checkbox_with+ but raises an ElementNotFoundError if no button
472
+ # matches +criteria+
473
+
444
474
  ##
445
475
  # :method: checkboxes_with(criteria)
446
476
  #
@@ -38,6 +38,12 @@ class Mechanize::Form::MultiSelectList < Mechanize::Form::Field
38
38
  #
39
39
  # select_list.option_with(:value => '1').value = 'foo'
40
40
 
41
+ ##
42
+ # :mehtod: option_with!(criteria)
43
+ #
44
+ # Same as +option_with+ but raises an ElementNotFoundError if no button
45
+ # matches +criteria+
46
+
41
47
  ##
42
48
  # :method: options_with
43
49
  #
@@ -125,7 +125,9 @@ class Mechanize::HTTP::Agent
125
125
  # Creates a new Mechanize HTTP user agent. The user agent is an
126
126
  # implementation detail of mechanize and its API may change at any time.
127
127
 
128
- def initialize
128
+ # The connection_name can be used to segregate SSL connections.
129
+ # Agents with different names will not share the same persistent connection.
130
+ def initialize(connection_name = 'mechanize')
129
131
  @allowed_error_codes = []
130
132
  @conditional_requests = true
131
133
  @context = nil
@@ -174,7 +176,7 @@ class Mechanize::HTTP::Agent
174
176
  @scheme_handlers['relative'] = @scheme_handlers['http']
175
177
  @scheme_handlers['file'] = @scheme_handlers['http']
176
178
 
177
- @http = Net::HTTP::Persistent.new 'mechanize'
179
+ @http = Net::HTTP::Persistent.new connection_name
178
180
  @http.idle_timeout = 5
179
181
  @http.keep_alive = 300
180
182
  end
@@ -223,6 +223,12 @@ class Mechanize::Page < Mechanize::File
223
223
  # ...
224
224
  # end
225
225
 
226
+ ##
227
+ # :mehtod: form_with!(criteria)
228
+ #
229
+ # Same as +form_with+ but raises an ElementNotFoundError if no button matches
230
+ # +criteria+
231
+
226
232
  ##
227
233
  # :method: forms_with
228
234
  #
@@ -245,6 +251,12 @@ class Mechanize::Page < Mechanize::File
245
251
  # Example:
246
252
  # page.link_with(:href => /foo/).click
247
253
 
254
+ ##
255
+ # :mehtod: link_with!(criteria)
256
+ #
257
+ # Same as +link_with+ but raises an ElementNotFoundError if no button matches
258
+ # +criteria+
259
+
248
260
  ##
249
261
  # :method: links_with
250
262
  #
@@ -268,6 +280,12 @@ class Mechanize::Page < Mechanize::File
268
280
  # Example:
269
281
  # page.base_with(:href => /foo/).click
270
282
 
283
+ ##
284
+ # :mehtod: base_with!(criteria)
285
+ #
286
+ # Same as +base_with+ but raises an ElementNotFoundError if no button matches
287
+ # +criteria+
288
+
271
289
  ##
272
290
  # :method: bases_with
273
291
  #
@@ -290,6 +308,12 @@ class Mechanize::Page < Mechanize::File
290
308
  # Example:
291
309
  # page.frame_with(:src => /foo/).click
292
310
 
311
+ ##
312
+ # :mehtod: frame_with!(criteria)
313
+ #
314
+ # Same as +frame_with+ but raises an ElementNotFoundError if no button matches
315
+ # +criteria+
316
+
293
317
  ##
294
318
  # :method: frames_with
295
319
  #
@@ -312,6 +336,12 @@ class Mechanize::Page < Mechanize::File
312
336
  # Example:
313
337
  # page.iframe_with(:src => /foo/).click
314
338
 
339
+ ##
340
+ # :mehtod: iframe_with!(criteria)
341
+ #
342
+ # Same as +iframe_with+ but raises an ElementNotFoundError if no button
343
+ # matches +criteria+
344
+
315
345
  ##
316
346
  # :method: iframes_with
317
347
  #
@@ -334,6 +364,12 @@ class Mechanize::Page < Mechanize::File
334
364
  # Example:
335
365
  # page.image_with(:alt => /main/).fetch.save
336
366
 
367
+ ##
368
+ # :mehtod: image_with!(criteria)
369
+ #
370
+ # Same as +image_with+ but raises an ElementNotFoundError if no button matches
371
+ # +criteria+
372
+
337
373
  ##
338
374
  # :method: images_with
339
375
  #
@@ -99,7 +99,7 @@ class Mechanize::PluggableParser
99
99
  @parsers[mime_type.simplified] ||
100
100
  @parsers[mime_type.media_type] ||
101
101
  default
102
- rescue MIME::InvalidContentType
102
+ rescue MIME::Type::InvalidContentType
103
103
  default
104
104
  end
105
105
 
@@ -1293,6 +1293,14 @@ but not <a href="/" rel="me nofollow">this</a>!
1293
1293
  assert @mech.visited?('http://localhost/response_code?code=302')
1294
1294
  end
1295
1295
 
1296
+ def test_no_frames_exists
1297
+ page = @mech.get("http://localhost/empty_form.html");
1298
+ assert_nil page.frame_with(:name => 'noframe')
1299
+ assert_raises Mechanize::ElementNotFoundError do
1300
+ page.frame_with!(:name => 'noframe')
1301
+ end
1302
+ end
1303
+
1296
1304
  def assert_header(page, header)
1297
1305
  headers = {}
1298
1306
 
@@ -25,9 +25,24 @@ class TestMechanizeDownload < Mechanize::TestCase
25
25
  download = @parser.new uri, nil, body_io
26
26
 
27
27
  in_tmpdir do
28
- download.save
28
+ filename = download.save
29
29
 
30
30
  assert File.exist? 'foo.html'
31
+ assert_equal "foo.html", filename
32
+ end
33
+ end
34
+
35
+ def test_save_bang
36
+ uri = URI.parse 'http://example/foo.html'
37
+ body_io = StringIO.new '0123456789'
38
+
39
+ download = @parser.new uri, nil, body_io
40
+
41
+ in_tmpdir do
42
+ filename = download.save!
43
+
44
+ assert File.exist? 'foo.html'
45
+ assert_equal "foo.html", filename
31
46
  end
32
47
  end
33
48
 
@@ -43,9 +58,20 @@ class TestMechanizeDownload < Mechanize::TestCase
43
58
  download = @parser.new uri, nil, body_io
44
59
 
45
60
  in_tmpdir do
46
- download.save
61
+ filename = download.save
47
62
 
48
63
  assert File.exist? 'foo.html'
64
+ assert_equal "foo.html", filename
65
+
66
+ filename = download.save
67
+
68
+ assert File.exist? 'foo.html.1'
69
+ assert_equal "foo.html.1", filename
70
+
71
+ filename = download.save
72
+
73
+ assert File.exist? 'foo.html.2'
74
+ assert_equal "foo.html.2", filename
49
75
  end
50
76
  end
51
77
  end
@@ -0,0 +1,15 @@
1
+ require 'mechanize/test_case'
2
+
3
+ class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
4
+
5
+ def test_to_s
6
+ page = fake_page
7
+
8
+ error = Mechanize::ElementNotFoundError.new(page, :element, :conditions)
9
+
10
+ assert_match(/element/, error.to_s)
11
+ assert_match(/conditions/, error.to_s)
12
+ end
13
+
14
+ end
15
+
@@ -14,20 +14,23 @@ class TestMechanizeFile < Mechanize::TestCase
14
14
 
15
15
  Dir.mktmpdir do |dir|
16
16
  Dir.chdir dir do
17
- page.save 'test.html'
17
+ filename = page.save 'test.html'
18
18
 
19
19
  assert File.exist? 'test.html'
20
20
  assert_equal '0123456789', File.read('test.html')
21
+ assert_equal "test.html", filename
21
22
 
22
- page.save 'test.html'
23
+ filename = page.save 'test.html'
23
24
 
24
25
  assert File.exist? 'test.html.1'
25
26
  assert_equal '0123456789', File.read('test.html.1')
27
+ assert_equal "test.html.1", filename
26
28
 
27
- page.save 'test.html'
29
+ filename = page.save 'test.html'
28
30
 
29
31
  assert File.exist? 'test.html.2'
30
32
  assert_equal '0123456789', File.read('test.html.2')
33
+ assert_equal "test.html.2", filename
31
34
  end
32
35
  end
33
36
  end
@@ -38,17 +41,20 @@ class TestMechanizeFile < Mechanize::TestCase
38
41
 
39
42
  Dir.mktmpdir do |dir|
40
43
  Dir.chdir dir do
41
- page.save
44
+ filename = page.save
42
45
 
43
46
  assert File.exist? 'test.html'
47
+ assert_equal "test.html", filename
44
48
 
45
- page.save
49
+ filename = page.save
46
50
 
47
51
  assert File.exist? 'test.html.1'
52
+ assert_equal "test.html.1", filename
48
53
 
49
- page.save
54
+ filename = page.save
50
55
 
51
56
  assert File.exist? 'test.html.2'
57
+ assert_equal "test.html.2", filename
52
58
  end
53
59
  end
54
60
  end
@@ -59,11 +65,13 @@ class TestMechanizeFile < Mechanize::TestCase
59
65
 
60
66
  Dir.mktmpdir do |dir|
61
67
  Dir.chdir dir do
62
- page.save
68
+ filename = page.save
63
69
  assert File.exist? 'test.html'
70
+ assert_equal "test.html", filename
64
71
 
65
- page.save
72
+ filename = page.save
66
73
  assert File.exist? 'test.html.1'
74
+ assert_equal "test.html.1", filename
67
75
  end
68
76
  end
69
77
  end
@@ -81,14 +89,16 @@ class TestMechanizeFile < Mechanize::TestCase
81
89
 
82
90
  Dir.mktmpdir do |dir|
83
91
  Dir.chdir dir do
84
- page.save 'test.html'
92
+ filename = page.save 'test.html'
85
93
 
86
94
  assert File.exist? 'test.html'
95
+ assert_equal "test.html", filename
87
96
 
88
- page.save! 'test.html'
97
+ filename = page.save! 'test.html'
89
98
 
90
99
  assert File.exist? 'test.html'
91
100
  refute File.exist? 'test.html.1'
101
+ assert_equal "test.html", filename
92
102
  end
93
103
  end
94
104
  end
@@ -484,6 +484,13 @@ class TestMechanizeForm < Mechanize::TestCase
484
484
  end.submit
485
485
  end
486
486
 
487
+ def test_post_with_bang
488
+ page = @mech.get("http://localhost/form_test.html")
489
+ page.form_with!(:name => 'post_form1') do |form|
490
+ form.first_name = 10
491
+ end.submit
492
+ end
493
+
487
494
  def test_post
488
495
  page = @mech.get("http://localhost/form_test.html")
489
496
  post_form = page.forms.find { |f| f.name == "post_form1" }
@@ -893,6 +900,22 @@ class TestMechanizeForm < Mechanize::TestCase
893
900
  assert(form.has_field?('intarweb'))
894
901
  end
895
902
 
903
+ def test_fill_unexisting_form
904
+ page = @mech.get("http://localhost/empty_form.html")
905
+ assert_raises(NoMethodError) {
906
+ page.form_with(:name => 'no form') { |f| f.foo = 'bar' }
907
+ }
908
+ begin
909
+ page.form_with!(:name => 'no form') { |f| f.foo = 'bar' }
910
+ rescue => e
911
+ assert_instance_of Mechanize::ElementNotFoundError, e
912
+ assert_kind_of Mechanize::Page, e.source
913
+ assert_equal :form, e.element
914
+ assert_kind_of Hash, e.conditions
915
+ assert_equal 'no form', e.conditions[:name]
916
+ end
917
+ end
918
+
896
919
  def test_field_error
897
920
  @page = @mech.get('http://localhost/empty_form.html')
898
921
  form = @page.forms.first
@@ -33,6 +33,11 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
33
33
  realm
34
34
  end
35
35
 
36
+ def test_agent_is_named
37
+ assert_equal 'mechanize', Mechanize::HTTP::Agent.new.http.name
38
+ assert_equal 'unique', Mechanize::HTTP::Agent.new('unique').http.name
39
+ end
40
+
36
41
  def test_auto_io
37
42
  Tempfile.open 'input' do |input_io|
38
43
  input_io.binmode
@@ -1584,6 +1589,11 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1584
1589
  assert_equal 'invalid value for port: "nonexistent service"', e.message
1585
1590
  end
1586
1591
 
1592
+ def test_setting_agent_name
1593
+ mech = Mechanize.new 'user-set-name'
1594
+ assert_equal 'user-set-name', mech.agent.http.name
1595
+ end
1596
+
1587
1597
  def test_ssl
1588
1598
  in_tmpdir do
1589
1599
  store = OpenSSL::X509::Store.new
@@ -12,6 +12,16 @@ class TestMechanizeLink < Mechanize::TestCase
12
12
  @mech.history.last.uri.to_s)
13
13
  end
14
14
 
15
+ def test_click_bang
16
+ page = @mech.get("http://localhost/frame_test.html")
17
+ link = page.link_with!(:text => "Form Test")
18
+
19
+ assert_equal('Form Test', link.text)
20
+ page = link.click
21
+ assert_equal("http://localhost/form_test.html",
22
+ @mech.history.last.uri.to_s)
23
+ end
24
+
15
25
  def test_click_base
16
26
  page = @mech.get("http://google.com/tc_base_link.html")
17
27
  page = page.links.first.click
@@ -34,6 +44,22 @@ class TestMechanizeLink < Mechanize::TestCase
34
44
  # HACK no assertion
35
45
  end
36
46
 
47
+ def test_click_unexiting_link
48
+ page = @mech.get("http://google.com/tc_links.html")
49
+ assert_raises NoMethodError do
50
+ page.link_with(:text => 'no link').click
51
+ end
52
+ begin
53
+ page.link_with!(:text => 'no link').click
54
+ rescue => e
55
+ assert_instance_of Mechanize::ElementNotFoundError, e
56
+ assert_kind_of Mechanize::Page, e.source
57
+ assert_equal :link, e.element
58
+ assert_kind_of Hash, e.conditions
59
+ assert_equal 'no link', e.conditions[:text]
60
+ end
61
+ end
62
+
37
63
  def test_click_empty_href
38
64
  page = @mech.get("http://google.com/tc_links.html?q=test#anchor")
39
65
  link = page.link_with(:text => 'empty href')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-08-13 00:00:00.000000000 Z
15
+ date: 2013-11-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: net-http-digest_auth
@@ -60,34 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
- version: '1.17'
64
- - - '>='
65
- - !ruby/object:Gem::Version
66
- version: 1.17.2
63
+ version: '2.0'
67
64
  type: :runtime
68
65
  prerelease: false
69
66
  version_requirements: !ruby/object:Gem::Requirement
70
67
  requirements:
71
68
  - - ~>
72
69
  - !ruby/object:Gem::Version
73
- version: '1.17'
74
- - - '>='
75
- - !ruby/object:Gem::Version
76
- version: 1.17.2
70
+ version: '2.0'
77
71
  - !ruby/object:Gem::Dependency
78
72
  name: http-cookie
79
73
  requirement: !ruby/object:Gem::Requirement
80
74
  requirements:
81
75
  - - ~>
82
76
  - !ruby/object:Gem::Version
83
- version: 1.0.0
77
+ version: '1.0'
84
78
  type: :runtime
85
79
  prerelease: false
86
80
  version_requirements: !ruby/object:Gem::Requirement
87
81
  requirements:
88
82
  - - ~>
89
83
  - !ruby/object:Gem::Version
90
- version: 1.0.0
84
+ version: '1.0'
91
85
  - !ruby/object:Gem::Dependency
92
86
  name: nokogiri
93
87
  requirement: !ruby/object:Gem::Requirement
@@ -249,6 +243,7 @@ files:
249
243
  - lib/mechanize/directory_saver.rb
250
244
  - lib/mechanize/download.rb
251
245
  - lib/mechanize/element_matcher.rb
246
+ - lib/mechanize/element_not_found_error.rb
252
247
  - lib/mechanize/file.rb
253
248
  - lib/mechanize/file_connection.rb
254
249
  - lib/mechanize/file_request.rb
@@ -387,6 +382,7 @@ files:
387
382
  - test/test_mechanize_cookie_jar.rb
388
383
  - test/test_mechanize_directory_saver.rb
389
384
  - test/test_mechanize_download.rb
385
+ - test/test_mechanize_element_not_found_error.rb
390
386
  - test/test_mechanize_file.rb
391
387
  - test/test_mechanize_file_connection.rb
392
388
  - test/test_mechanize_file_request.rb
@@ -462,6 +458,7 @@ test_files:
462
458
  - test/test_mechanize_cookie_jar.rb
463
459
  - test/test_mechanize_directory_saver.rb
464
460
  - test/test_mechanize_download.rb
461
+ - test/test_mechanize_element_not_found_error.rb
465
462
  - test/test_mechanize_file.rb
466
463
  - test/test_mechanize_file_connection.rb
467
464
  - test/test_mechanize_file_request.rb