From 82b155371931b3e4733ba7f152ad5cc23fa1a3c3 Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Fri, 14 Nov 2008 01:09:18 -0500 Subject: [PATCH] Added RadioField#checked? to indicated whether or not a radio button is checked. --- lib/webrat/core/field.rb | 4 ++++ spec/webrat/core/field_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 065a049..27200fa 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -241,6 +241,10 @@ module Webrat set(@element["value"] || "on") end + def checked? + @element["checked"] == "checked" + end + protected def other_options diff --git a/spec/webrat/core/field_spec.rb b/spec/webrat/core/field_spec.rb index 98ff995..6b7e015 100644 --- a/spec/webrat/core/field_spec.rb +++ b/spec/webrat/core/field_spec.rb @@ -12,4 +12,16 @@ module Webrat checkbox.should_not be_checked end end + + describe RadioField do + it "should say it is checked if it is" do + radio_button = RadioField.new(nil, (Webrat::XML.document("").search('input')).first) + radio_button.should be_checked + end + + it "should say it is not checked if it is not" do + radio_button = RadioField.new(nil, (Webrat::XML.document("").search('input')).first) + radio_button.should_not be_checked + end + end end