mechanize 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,5 +1,13 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ == 0.6.2
4
+
5
+ * Added a yield to Page#form so that dealing with forms can be more DSL like.
6
+ * Added the parsed page to the ResponseCodeError so that the parsed results
7
+ can be accessed even in the event of an error.
8
+ http://rubyforge.org/pipermail/mechanize-users/2006-September/000007.html
9
+ * Updated documentation (Thanks to Paul Smith)
10
+
3
11
  == 0.6.1
4
12
 
5
13
  * Added a method to Form called "submit". Now forms can be submitted by
data/GUIDE CHANGED
@@ -34,19 +34,19 @@ Now that we've fetched google's homepage, lets try listing all of the links:
34
34
  We can list the links, but Mechanize gives a few shortcuts to help us find a
35
35
  link to click on. Lets say we wanted to click the link whose text is 'News'.
36
36
  Normally, we would have to do this:
37
- page = agent.click page.links.find { |l| l.name == 'News' }
37
+ page = agent.click page.links.find { |l| l.text == 'News' }
38
38
  But Mechanize gives us a shortcut. Instead we can say this:
39
- page = agent.click page.links.name('News')
39
+ page = agent.click page.links.text('News')
40
40
  That shortcut says "find all links with the name 'News'". You're probably
41
41
  thinking "there could be multiple links with that text!", and you would be
42
42
  correct! If you pass a list of links to the "click" method, Mechanize will
43
43
  click on the first one. If you wanted to click on the second news link, you
44
44
  could do this:
45
- agent.click page.links.name('News')[1]
45
+ agent.click page.links.text('News')[1]
46
46
  We can even find a link with a certain href like so:
47
47
  page.links.href('/something')
48
48
  Or chain them together to find a link with certain text and certain href:
49
- page.links.name('News').href('/something')
49
+ page.links.text('News').href('/something')
50
50
 
51
51
  These shortcuts that mechanize provides are available on any list that you
52
52
  can fetch like frames, iframes, or forms. Now that we know how to find and
data/NOTES CHANGED
@@ -1,5 +1,22 @@
1
1
  = Mechanize Release Notes
2
2
 
3
+ == 0.6.2 (Bridget)
4
+
5
+ Mechanize 0.6.2 (Bridget) is a fairly small bug fix release. You can now
6
+ access the parsed page when a ResponseCodeError is thrown. For example, this
7
+ loads a page that doesn't exist, but gives you access to the parsed 404 page:
8
+ begin
9
+ WWW::Mechanize.new().get('http://google.com/asdfasdfadsf.html')
10
+ rescue WWW::Mechanize::ResponseCodeError => ex
11
+ puts ex.page
12
+ end
13
+ Accessing forms is now more DSL like. When manipulating a form, for example,
14
+ you can use the following syntax:
15
+ page.form('formname') { |form|
16
+ form.first_name = "Aaron"
17
+ }.submit
18
+ Documentation has also been updated thanks to Paul Smith.
19
+
3
20
  == 0.6.1 (Chuck)
4
21
 
5
22
  Mechanize version 0.6.1 (Chuck) is done, and is ready for you to use. This
@@ -20,9 +20,15 @@ module WWW
20
20
  # Any other response code is up to the user to handle.
21
21
  class ResponseCodeError < RuntimeError
22
22
  attr_reader :response_code
23
+ attr_reader :page
23
24
 
24
- def initialize(response_code)
25
- @response_code = response_code
25
+ def initialize(page)
26
+ @page = page
27
+ @response_code = page.code
28
+ end
29
+
30
+ def inspect
31
+ response_code
26
32
  end
27
33
  end
28
34
  end
@@ -1,5 +1,5 @@
1
1
  module WWW
2
2
  class Mechanize
3
- Version = '0.6.1'
3
+ Version = '0.6.2'
4
4
  end
5
5
  end
@@ -63,7 +63,9 @@ module WWW
63
63
  end
64
64
 
65
65
  def form(name)
66
- forms.name(name).first
66
+ f = forms.name(name).first
67
+ yield f if block_given?
68
+ f
67
69
  end
68
70
 
69
71
  private
data/lib/mechanize.rb CHANGED
@@ -410,7 +410,7 @@ class Mechanize
410
410
  request = fetch_request(abs_uri)
411
411
  return fetch_page(abs_uri, request, page)
412
412
  else
413
- raise ResponseCodeError.new(page.code), "Unhandled response", caller
413
+ raise ResponseCodeError.new(page), "Unhandled response", caller
414
414
  end
415
415
  }
416
416
  }
data/test/tc_errors.rb CHANGED
@@ -19,6 +19,14 @@ class MechErrorsTest < Test::Unit::TestCase
19
19
  }
20
20
  end
21
21
 
22
+ def test_non_exist
23
+ begin
24
+ page = @agent.get("http://localhost:#{PORT}/bad_form_test.html")
25
+ rescue RuntimeError => ex
26
+ assert_equal("404", ex.inspect)
27
+ end
28
+ end
29
+
22
30
  def test_too_many_radio
23
31
  page = @agent.get("http://localhost:#{PORT}/form_test.html")
24
32
  form = page.forms.name('post_form1').first
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: mechanize
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.1
7
- date: 2006-09-23 00:00:00 -07:00
6
+ version: 0.6.2
7
+ date: 2006-10-10 00:00:00 -07:00
8
8
  summary: Mechanize provides automated web-browsing
9
9
  require_paths:
10
10
  - lib