Fixed multiple select value for rack-test driver

This commit is contained in:
Carl Porth 2010-02-19 14:20:03 -08:00
parent 291bb0fe72
commit 02daf7a32f
2 changed files with 16 additions and 2 deletions

View File

@ -13,8 +13,12 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
attr_name = name.to_s
case
when 'select' == tag_name && 'value' == attr_name
option = node.xpath(".//option[@selected='selected']").first || node.xpath(".//option").first
option.content if option
if node['multiple'] == 'multiple'
node.xpath(".//option[@selected='selected']").map { |option| option.content }
else
option = node.xpath(".//option[@selected='selected']").first || node.xpath(".//option").first
option.content if option
end
when 'input' == tag_name && 'checkbox' == type && 'checked' == attr_name
node[attr_name] == 'checked' ? true : false
else

View File

@ -44,6 +44,16 @@ shared_examples_for "select" do
end
context "with multiple select" do
it "should return an empty value" do
@session.find_field('Language').value.should == []
end
it "should return value of the selected options" do
@session.select("Ruby", :from => 'Language')
@session.select("Javascript", :from => 'Language')
@session.find_field('Language').value.should include('Ruby', 'Javascript')
end
it "should select one option" do
@session.select("Ruby", :from => 'Language')
@session.click_button('awesome')