added checked? to CheckboxField

This commit is contained in:
David Chelimsky 2008-10-22 23:28:36 -05:00
parent 070f36ce51
commit 1ba0f58dfa
2 changed files with 19 additions and 0 deletions

View File

@ -207,6 +207,10 @@ module Webrat
raise_error_if_disabled raise_error_if_disabled
set(@element["value"] || "on") set(@element["value"] || "on")
end end
def checked?
@element["checked"] == "checked"
end
def uncheck def uncheck
raise_error_if_disabled raise_error_if_disabled

15
spec/core/field_spec.rb Normal file
View File

@ -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 type='checkbox' checked='checked'>")/'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 type='checkbox'>")/'input').first)
checkbox.should_not be_checked
end
end
end