<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/chooses_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,8 @@
 == SVN
 
-* Fix bad reference to #select method in README (Patch from Luke Melia)
+* Add save_and_open_page to aid in debugging
+* Add radio button support via #chooses method
+* Docfix: bad reference to #select method in README (Patch from Luke Melia)
 * Allow specifying the input name/label when doing a select (Patch from David Chelimsky)
 * Raise a specific exception if the developer tries to manipulate form elements before loading a page (Patch from James Deville)
 * Add basic support for Rails-generated JavaScript link tags</diff>
      <filename>History.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,3 @@
-Option button support
 Full support for multiple forms on a page
 Track the current form based on the location of the last manipulated input, use this as a default for clicks_button
 Make current_url work with redirections</diff>
      <filename>TODO.txt</filename>
    </modified>
    <modified>
      <diff>@@ -139,6 +139,18 @@ module ActionController
           add_form_data(input, input.attributes[&quot;value&quot;])
         end
       end
+
+      # Verifies that an input radio button exists on the current page and marks it
+      # as checked, so that the value will be submitted with the form.
+      #
+      # Example:
+      #   chooses 'First Option'
+      def chooses(field)
+        radio = find_field_by_name_or_label(field)
+        return flunk(&quot;Could not find radio button #{field.inspect}&quot;) if radio.nil?
+        return flunk(&quot;Input #{radio.inspect} is not a radio button&quot;) unless radio.attributes['type'] == 'radio'
+        add_form_data(radio, radio.attributes[&quot;value&quot;] || &quot;on&quot;)
+      end        
       
       # Verifies that a submit button exists for the form, then submits the form, follows
       # any redirects, and verifies the final page was successful.
@@ -158,6 +170,21 @@ module ActionController
       
       def submits_form(form_id = nil) # :nodoc:
       end
+      
+      # Saves the currently loaded page out to RAILS_ROOT/tmp/ and opens it in the default
+      # web browser if on OS X. Useful for debugging.
+      # 
+      # Example:
+      #   save_and_open_page
+      def save_and_open_page
+        return unless File.exist?(RAILS_ROOT + &quot;/tmp&quot;)
+        
+        filename = &quot;webrat-#{Time.now.to_i}.html&quot; 
+     	  File.open(RAILS_ROOT + &quot;/tmp/#{filename}&quot;, &quot;w&quot;) do |f| 
+     	    f.write response.body 
+     	  end 
+     	  `open tmp/#{filename}`
+     	end
     
     protected # Methods you could call, but probably shouldn't
     
@@ -222,7 +249,7 @@ module ActionController
       
       def find_button(value = nil) # :nodoc:
         return nil unless value
-        submit_buttons.detect { |el| el.attributes[&quot;value&quot;] == value }
+        submit_buttons.detect { |el| el.attributes[&quot;value&quot;] =~ /^\W*#{value}\b/i }
       end
       
       def add_form_data(input_element, value) # :nodoc:
@@ -269,7 +296,12 @@ module ActionController
         debug_log &quot;REQUESTING PAGE: #{method.to_s.upcase} #{url} with #{data.inspect}&quot;
         @current_url = url
         self.send &quot;#{method}_via_redirect&quot;, @current_url, data || {}
-        assert_response :success
+        
+        if response.body =~ /Exception caught/ || response.body.blank? 
+          save_and_open_page
+       	end
+       	
+       	assert_response :success
         reset_dom
       end
       
@@ -343,7 +375,8 @@ module ActionController
       def add_default_params_for(form) # :nodoc:
         add_default_params_from_inputs_for(form)
         add_default_params_from_checkboxes_for(form)
-        add_default_params_from_textateas_for(form)
+        add_default_params_from_radio_buttons_for(form)
+        add_default_params_from_textareas_for(form)
       end
       
       def add_default_params_from_inputs_for(form) # :nodoc:
@@ -362,7 +395,16 @@ module ActionController
         end
       end
       
-      def add_default_params_from_textateas_for(form) # :nodoc:
+      def add_default_params_from_radio_buttons_for(form) # :nodoc:
+        (form / &quot;input&quot;).each do |input|
+          next if input.attributes[&quot;type&quot;] != &quot;radio&quot;
+          if input.attributes[&quot;checked&quot;] == &quot;checked&quot;
+            add_form_data(input, input.attributes[&quot;value&quot;])
+          end
+        end
+      end
+      
+      def add_default_params_from_textareas_for(form) # :nodoc:
         (form / &quot;textarea&quot;).each do |input|
           add_form_data(input, input.inner_html)
         end</diff>
      <filename>lib/webrat/session.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,8 @@ class ClicksButtonTest &lt; Test::Unit::TestCase
     @session = ActionController::Integration::Session.new
     @session.stubs(:assert_response)
     @session.stubs(:get_via_redirect)
-    @session.stubs(:response).returns(@response=mock)
+    @response = mock
+    @session.stubs(:response).returns(@response)
   end
   
   def test_should_fail_if_no_buttons
@@ -158,6 +159,20 @@ class ClicksButtonTest &lt; Test::Unit::TestCase
     @session.clicks_button
   end
   
+  def test_should_send_default_radio_options
+    @response.stubs(:body).returns(&lt;&lt;-EOS)
+      &lt;form method=&quot;get&quot; action=&quot;/login&quot;&gt;
+        &lt;input id=&quot;user_gender_male&quot; name=&quot;user[gender]&quot; type=&quot;radio&quot; value=&quot;M&quot; /&gt;
+        &lt;label for=&quot;user_gender_male&quot;&gt;Male&lt;/label&gt;
+        &lt;input id=&quot;user_gender_female&quot; name=&quot;user[gender]&quot; type=&quot;radio&quot; value=&quot;F&quot; checked=&quot;checked&quot; /&gt;
+        &lt;label for=&quot;user_gender_female&quot;&gt;Female&lt;/label&gt;
+        &lt;input type=&quot;submit&quot; /&gt;
+      &lt;/form&gt;
+    EOS
+    @session.expects(:get_via_redirect).with(&quot;/login&quot;, &quot;user&quot; =&gt; {&quot;gender&quot; =&gt; &quot;F&quot;})
+    @session.clicks_button
+  end
+  
   def test_should_send_correct_data_for_rails_style_unchecked_fields
     @response.stubs(:body).returns(&lt;&lt;-EOS)
       &lt;form method=&quot;get&quot; action=&quot;/login&quot;&gt;</diff>
      <filename>test/clicks_button_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,16 @@
 require File.dirname(__FILE__) + &quot;/helper&quot;
 
+RAILS_ROOT = &quot;.&quot; unless defined?(RAILS_ROOT)
+
 class VisitsTest &lt; Test::Unit::TestCase
+
   def setup
     @session = ActionController::Integration::Session.new
     @session.stubs(:assert_response)
     @session.stubs(:get_via_redirect)
+    @response = mock
+    @session.stubs(:response).returns(@response)
+    @response.stubs(:body).returns(&quot;&quot;)
   end
 
   def test_should_use_get</diff>
      <filename>test/visits_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7b85e0d15ad07abfd61543348d166551b970eba6</id>
    </parent>
  </parents>
  <author>
    <name>Bryan Helmkamp</name>
    <email>bryan@brynary.com</email>
  </author>
  <url>http://github.com/gwynm/webrat/commit/f7420463fdd2fb0dd7e1c66833d5d7e6f4f0ac68</url>
  <id>f7420463fdd2fb0dd7e1c66833d5d7e6f4f0ac68</id>
  <committed-date>2008-03-02T17:06:43-08:00</committed-date>
  <authored-date>2008-03-02T17:06:43-08:00</authored-date>
  <message>Add save_and_open_page. Add radio button support via #chooses method</message>
  <tree>be3b2909613c2301996b699306a33cedd3f59723</tree>
  <committer>
    <name>Bryan Helmkamp</name>
    <email>bryan@brynary.com</email>
  </committer>
</commit>
