From 02daf7a32f7836bcecacbcc83fa27490d6bcd93a Mon Sep 17 00:00:00 2001 From: Carl Porth Date: Fri, 19 Feb 2010 14:20:03 -0800 Subject: [PATCH] Fixed multiple select value for rack-test driver --- lib/capybara/driver/rack_test_driver.rb | 8 ++++++-- spec/dsl/select_spec.rb | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/capybara/driver/rack_test_driver.rb b/lib/capybara/driver/rack_test_driver.rb index 673472a6..11fc7998 100644 --- a/lib/capybara/driver/rack_test_driver.rb +++ b/lib/capybara/driver/rack_test_driver.rb @@ -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 diff --git a/spec/dsl/select_spec.rb b/spec/dsl/select_spec.rb index 994da94d..dbebae5d 100644 --- a/spec/dsl/select_spec.rb +++ b/spec/dsl/select_spec.rb @@ -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')