From 55476db4bd02b7b58f69d2f358c3304010f0ee6c Mon Sep 17 00:00:00 2001 From: Rob Holland Date: Mon, 4 Oct 2010 21:17:07 +0100 Subject: [PATCH] Fix the rack driver to favour option's value attributes over their content. --- Gemfile | 15 ++- Gemfile.lock | 117 +++++++++++++++++------ lib/capybara/driver/rack_test_driver.rb | 4 +- lib/capybara/spec/session/select_spec.rb | 8 ++ lib/capybara/spec/views/form.erb | 1 + 5 files changed, 111 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index 632c37e0..bb6961b9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,14 @@ -source :gemcutter +source 'http://gemcutter.org' -gemspec +gem 'rails', '3.0.0' + +group :development, :test do + gem 'nokogiri' + gem 'xpath' + gem 'sinatra' + gem 'culerity' + gem 'selenium-webdriver' + gem 'launchy' + gem 'rspec-rails', '>= 2.0.0.beta.20' + gem 'cucumber-rails' +end diff --git a/Gemfile.lock b/Gemfile.lock index 04f8d7f1..e360a85d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,37 +1,92 @@ -PATH - remote: . - specs: - capybara (0.3.9) - celerity (>= 0.7.9) - culerity (>= 0.2.4) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (>= 0.0.27) - xpath (>= 0.1.0) - GEM - remote: http://rubygems.org/ + remote: http://gemcutter.org/ specs: - celerity (0.8.2) + abstract (1.0.0) + actionmailer (3.0.0) + actionpack (= 3.0.0) + mail (~> 2.2.5) + actionpack (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + builder (~> 2.1.2) + erubis (~> 2.6.6) + i18n (~> 0.4.1) + rack (~> 1.2.1) + rack-mount (~> 0.6.12) + rack-test (~> 0.5.4) + tzinfo (~> 0.3.23) + activemodel (3.0.0) + activesupport (= 3.0.0) + builder (~> 2.1.2) + i18n (~> 0.4.1) + activerecord (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + arel (~> 1.0.0) + tzinfo (~> 0.3.23) + activeresource (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + activesupport (3.0.0) + arel (1.0.1) + activesupport (~> 3.0.0) + builder (2.1.2) configuration (1.1.0) + cucumber (0.9.2) + builder (~> 2.1.2) + diff-lcs (~> 1.1.2) + gherkin (~> 2.2.5) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + cucumber-rails (0.3.2) + cucumber (>= 0.8.0) culerity (0.2.12) diff-lcs (1.1.2) + erubis (2.6.6) + abstract (>= 1.0.0) ffi (0.6.3) rake (>= 0.8.7) ffi (0.6.3-java) + gherkin (2.2.8) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + gherkin (2.2.8-java) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + i18n (0.4.1) + json (1.4.6) + json (1.4.6-java) json_pure (1.4.6) launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) + mail (2.2.6.1) + activesupport (>= 2.3.6) + mime-types + treetop (>= 1.4.5) mime-types (1.16) nokogiri (1.4.3.1) nokogiri (1.4.3.1-java) weakling (>= 0.0.3) + polyglot (0.3.1) rack (1.2.1) - rack-test (0.5.4) + rack-mount (0.6.13) + rack (>= 1.0.0) + rack-test (0.5.6) rack (>= 1.0) + rails (3.0.0) + actionmailer (= 3.0.0) + actionpack (= 3.0.0) + activerecord (= 3.0.0) + activeresource (= 3.0.0) + activesupport (= 3.0.0) + bundler (~> 1.0.0) + railties (= 3.0.0) + railties (3.0.0) + actionpack (= 3.0.0) + activesupport (= 3.0.0) + rake (>= 0.8.4) + thor (~> 0.14.0) rake (0.8.7) rspec (2.0.0.beta.22) rspec-core (= 2.0.0.beta.22) @@ -43,6 +98,8 @@ GEM rspec-mocks (2.0.0.beta.22) rspec-core (= 2.0.0.beta.22) rspec-expectations (= 2.0.0.beta.22) + rspec-rails (2.0.0.beta.22) + rspec (= 2.0.0.beta.22) rubyzip (0.9.4) selenium-webdriver (0.0.28) ffi (>= 0.6.1) @@ -50,25 +107,25 @@ GEM rubyzip sinatra (1.0) rack (>= 1.0) + term-ansicolor (1.0.5) + thor (0.14.3) + treetop (1.4.8) + polyglot (>= 0.3.1) + tzinfo (0.3.23) weakling (0.0.4-java) xpath (0.1.0) - yard (0.6.1) PLATFORMS java ruby DEPENDENCIES - capybara! - celerity (>= 0.7.9) - culerity (>= 0.2.4) - launchy (>= 0.3.5) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - rspec (>= 2.0.0.beta.22) - selenium-webdriver (>= 0.0.27) - sinatra (>= 0.9.4) - xpath (>= 0.1.0) - yard (>= 0.5.8) + cucumber-rails + culerity + launchy + nokogiri + rails (= 3.0.0) + rspec-rails (>= 2.0.0.beta.20) + selenium-webdriver + sinatra + xpath diff --git a/lib/capybara/driver/rack_test_driver.rb b/lib/capybara/driver/rack_test_driver.rb index 6ec7a935..3413ea95 100644 --- a/lib/capybara/driver/rack_test_driver.rb +++ b/lib/capybara/driver/rack_test_driver.rb @@ -14,10 +14,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base case when 'select' == tag_name && 'value' == attr_name if native['multiple'] == 'multiple' - native.xpath(".//option[@selected='selected']").map { |option| option.content } + native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content } else option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first - option.content if option + option[:value] || option.content if option end when 'input' == tag_name && 'checkbox' == type && 'checked' == attr_name native[attr_name] == 'checked' ? true : false diff --git a/lib/capybara/spec/session/select_spec.rb b/lib/capybara/spec/session/select_spec.rb index 63f4d379..ec75ca25 100644 --- a/lib/capybara/spec/session/select_spec.rb +++ b/lib/capybara/spec/session/select_spec.rb @@ -13,6 +13,10 @@ shared_examples_for "select" do @session.find_field('Title').value.should == 'Miss' end + it "should return the value attribute rather than content if present" do + @session.find_field('Locale').value.should == 'en' + end + it "should select an option from a select box by id" do @session.select("Finish", :from => 'form_locale') @session.click_button('awesome') @@ -92,6 +96,10 @@ shared_examples_for "select" do @session.click_button('awesome') extract_results(@session)['languages'].should include('Ruby', 'Javascript') end + + it "should return value attribute rather than content if present" do + @session.find_field('Underwear').value.should include('thermal') + end end end end diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index 6e2069c1..a6cdc63e 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -155,6 +155,7 @@ +