From 1ba0f58dfa37ee9e4a2a2e91ea4f7526aee0dedd Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Wed, 22 Oct 2008 23:28:36 -0500 Subject: [PATCH] added checked? to CheckboxField --- lib/webrat/core/field.rb | 4 ++++ spec/core/field_spec.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 spec/core/field_spec.rb diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 42710cc..11799d3 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -207,6 +207,10 @@ module Webrat raise_error_if_disabled set(@element["value"] || "on") end + + def checked? + @element["checked"] == "checked" + end def uncheck raise_error_if_disabled diff --git a/spec/core/field_spec.rb b/spec/core/field_spec.rb new file mode 100644 index 0000000..4383179 --- /dev/null +++ b/spec/core/field_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") + +module Webrat + describe CheckboxField do + it "should say it is checked if it is" do + checkbox = CheckboxField.new(nil, (Hpricot("")/'input').first) + checkbox.should be_checked + end + + it "should say it is not checked if it is not" do + checkbox = CheckboxField.new(nil, (Hpricot("")/'input').first) + checkbox.should_not be_checked + end + end +end