Merge branch 'master' of git://github.com/jnicklas/capybara

This commit is contained in:
Pavel Gabriel 2010-02-19 00:54:51 +02:00
commit 2f314f01d3
8 changed files with 65 additions and 8 deletions

View File

@ -372,6 +372,7 @@ The following people have dedicated their time and effort to Capybara:
* Joseph Wilk
* Matt Wynne
* Piotr Sarnacki
* Pavel Gabriel
== License:

View File

@ -14,7 +14,7 @@ module Capybara
class InfiniteRedirectError < TimeoutError; end
class << self
attr_accessor :debug, :asset_root, :app_host, :run_server
attr_accessor :debug, :asset_root, :app_host, :run_server, :default_host
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
def default_selector

View File

@ -39,7 +39,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
end
def select(option)
node.xpath(".//option[@selected]").each { |node| node.remove_attribute("selected") }
if node['multiple'] != 'multiple'
node.xpath(".//option[@selected]").each { |node| node.remove_attribute("selected") }
end
if option_node = node.xpath(".//option[text()='#{option}']").first ||
node.xpath(".//option[contains(.,'#{option}')]").first
option_node["selected"] = 'selected'
@ -93,9 +96,16 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
merge_param!(params, input['name'].to_s, input['value'].to_s) if input['checked']
end
node.xpath(".//select").map do |select|
option = select.xpath(".//option[@selected]").first
option ||= select.xpath('.//option').first
merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s) if option
if select['multiple'] == 'multiple'
options = select.xpath(".//option[@selected]")
options.each do |option|
merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s)
end
else
option = select.xpath(".//option[@selected]").first
option ||= select.xpath('.//option').first
merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s) if option
end
end
node.xpath(".//input[@type='file']").map do |input|
unless input['value'].to_s.empty?
@ -179,6 +189,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
private
def build_rack_mock_session # :nodoc:
Rack::MockSession.new(app, Capybara.default_host)
end
def current_path
request.path rescue ""
end

View File

@ -9,3 +9,4 @@ Capybara.app = Rack::Builder.new do
end.to_app
Capybara.asset_root = Rails.root.join('public')
Capybara.default_host = "http://test.host"

View File

@ -113,9 +113,12 @@ module Capybara
kind, scope = Capybara.default_selector, kind unless scope
scope = XPath.from_css(scope) if kind == :css
locate(:xpath, scope, "scope '#{scope}' not found on page")
scopes.push(scope)
yield
scopes.pop
begin
scopes.push(scope)
yield
ensure
scopes.pop
end
end
def within_fieldset(locator)

View File

@ -42,5 +42,20 @@ shared_examples_for "select" do
running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
end
end
context "with multiple select" do
it "should select one option" do
@session.select("Ruby", :from => 'Language')
@session.click_button('awesome')
extract_results(@session)['languages'].should == ['Ruby']
end
it "should select multiple options" do
@session.select("Ruby", :from => 'Language')
@session.select("Javascript", :from => 'Language')
@session.click_button('awesome')
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
end
end
end
end

View File

@ -76,6 +76,19 @@ shared_examples_for "within" do
end
}.should raise_error(Capybara::ElementNotFound)
end
it "should restore the scope when an error is raised" do
running {
@session.within("//div[@id='for_bar']") do
running {
running {
@session.within("//div[@id='doesnotexist']") do
end
}.should raise_error(Capybara::ElementNotFound)
}.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(false)
end
}.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(true)
end
end
context "with forms" do

View File

@ -120,6 +120,16 @@
<label for="form_pets_hamster">Hamster</label>
</p>
<p>
<label for="form_languages">Languages</label>
<select name="form[languages][]" id="form_languages" multiple="multiple">
<option>Ruby</option>
<option>SQL</option>
<option>HTML</option>
<option>Javascript</option>
</select>
</p>
<div style="display:none;">
<label for="form_first_name_hidden">
Super Secret