Skip to content

Commit

Permalink
Fixed multiple select value for rack-test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
protocarl committed Feb 19, 2010
1 parent 291bb0f commit 02daf7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/capybara/driver/rack_test_driver.rb
Expand Up @@ -13,8 +13,12 @@ def [](name)
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
Expand Down
10 changes: 10 additions & 0 deletions spec/dsl/select_spec.rb
Expand Up @@ -44,6 +44,16 @@
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')
Expand Down

0 comments on commit 02daf7a

Please sign in to comment.