Created
March 2, 2010 20:02
-
-
Save smparkes/319853 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/capybara/driver/base.rb b/lib/capybara/driver/base.rb | |
index 6cf8c00..effb1bd 100644 | |
--- a/lib/capybara/driver/base.rb | |
+++ b/lib/capybara/driver/base.rb | |
@@ -19,6 +19,9 @@ class Capybara::Driver::Base | |
false | |
end | |
+ def wait_until *args | |
+ end | |
+ | |
def response_headers | |
raise Capybara::NotSupportedByDriverError | |
end | |
@@ -34,4 +37,8 @@ class Capybara::Driver::Base | |
def cleanup! | |
end | |
+ def has_shortcircuit_timeout | |
+ false | |
+ end | |
+ | |
end | |
diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb | |
index 0bbcf7b..a6a9abb 100644 | |
--- a/lib/capybara/session.rb | |
+++ b/lib/capybara/session.rb | |
@@ -21,16 +21,11 @@ module Capybara | |
end | |
def driver | |
- @driver ||= case mode | |
- when :rack_test | |
- Capybara::Driver::RackTest.new(app) | |
- when :selenium | |
- Capybara::Driver::Selenium.new(app) | |
- when :celerity | |
- Capybara::Driver::Celerity.new(app) | |
- when :culerity | |
- Capybara::Driver::Culerity.new(app) | |
- else | |
+ @driver ||= begin | |
+ string = mode.to_s | |
+ string.gsub!(%r{(^.)|(_.)}) { |m| m[m.length-1,1].upcase } | |
+ Capybara::Driver.const_get(string.to_sym).new(app) | |
+ rescue NameError | |
raise Capybara::DriverNotFoundError, "no driver called #{mode} was found" | |
end | |
end | |
@@ -245,7 +240,7 @@ module Capybara | |
end | |
def wait_until(timeout = Capybara.default_wait_time) | |
- WaitUntil.timeout(timeout) { yield } | |
+ WaitUntil.timeout(timeout,driver) { yield } | |
end | |
def evaluate_script(script) | |
diff --git a/lib/capybara/wait_until.rb b/lib/capybara/wait_until.rb | |
index 88d5a70..7d66197 100644 | |
--- a/lib/capybara/wait_until.rb | |
+++ b/lib/capybara/wait_until.rb | |
@@ -4,7 +4,7 @@ module Capybara | |
class << self | |
- def timeout(seconds = 1, &block) | |
+ def timeout(seconds = 1, driver = nil, &block) | |
start_time = Time.now | |
result = nil | |
@@ -12,9 +12,12 @@ module Capybara | |
until result | |
return result if result = yield | |
- if (Time.now - start_time) > seconds | |
- raise TimeoutError | |
+ delay = seconds - (Time.now - start_time) | |
+ if delay <= 0 | |
+ raise TimeoutError | |
end | |
+ | |
+ driver && driver.wait_until(delay) | |
end | |
end | |
diff --git a/spec/session_with_javascript_support_spec.rb b/spec/session_with_javascript_support_spec.rb | |
index d414c7b..7f3f613 100644 | |
--- a/spec/session_with_javascript_support_spec.rb | |
+++ b/spec/session_with_javascript_support_spec.rb | |
@@ -91,12 +91,17 @@ shared_examples_for "session with javascript support" do | |
end | |
it "should default to Capybara.default_wait_time before timeout" do | |
+ @session.driver # init the driver to exclude init timing from test | |
start = Time.now | |
Capybara.default_wait_time = 0.2 | |
begin | |
@session.wait_until { false } | |
rescue Capybara::TimeoutError; end | |
- (Time.now - start).should be_close(0.2, 0.1) | |
+ if @session.driver.has_shortcircuit_timeout | |
+ (Time.now - start).should be_close(0, 0.1) | |
+ else | |
+ (Time.now - start).should be_close(0.2, 0.1) | |
+ end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment