mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Rename WaitUntil to timeout
This commit is contained in:
parent
42aa6615b2
commit
d7938b9cd9
5 changed files with 37 additions and 37 deletions
|
@ -1,6 +1,7 @@
|
|||
require 'uri'
|
||||
require 'net/http'
|
||||
require 'rack'
|
||||
require 'capybara/timeout'
|
||||
|
||||
class Capybara::Server
|
||||
class Identify
|
||||
|
@ -65,7 +66,7 @@ class Capybara::Server
|
|||
end
|
||||
Capybara.log "checking if application has booted"
|
||||
|
||||
Capybara::WaitUntil.timeout(10) do
|
||||
Capybara.timeout(10) do
|
||||
if responsive?
|
||||
Capybara.log("application has booted")
|
||||
true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'forwardable'
|
||||
require 'capybara/wait_until'
|
||||
require 'capybara/timeout'
|
||||
|
||||
module Capybara
|
||||
class Session
|
||||
|
@ -242,7 +242,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def wait_until(timeout = Capybara.default_wait_time)
|
||||
WaitUntil.timeout(timeout,driver) { yield }
|
||||
Capybara.timeout(timeout,driver) { yield }
|
||||
end
|
||||
|
||||
def execute_script(script)
|
||||
|
|
27
lib/capybara/timeout.rb
Normal file
27
lib/capybara/timeout.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Capybara
|
||||
class << self
|
||||
|
||||
##
|
||||
# Provides timeout similar to standard library Timeout, but avoids threads
|
||||
#
|
||||
def timeout(seconds = 1, driver = nil, &block)
|
||||
start_time = Time.now
|
||||
|
||||
result = nil
|
||||
|
||||
until result
|
||||
return result if result = yield
|
||||
|
||||
delay = seconds - (Time.now - start_time)
|
||||
if delay <= 0
|
||||
raise TimeoutError
|
||||
end
|
||||
|
||||
driver && driver.wait_until(delay)
|
||||
|
||||
sleep(0.05)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
module Capybara
|
||||
#Provides timeout similar to standard library Timeout, but avoids threads
|
||||
class WaitUntil
|
||||
|
||||
class << self
|
||||
|
||||
def timeout(seconds = 1, driver = nil, &block)
|
||||
start_time = Time.now
|
||||
|
||||
result = nil
|
||||
|
||||
until result
|
||||
return result if result = yield
|
||||
|
||||
delay = seconds - (Time.now - start_time)
|
||||
if delay <= 0
|
||||
raise TimeoutError
|
||||
end
|
||||
|
||||
driver && driver.wait_until(delay)
|
||||
|
||||
sleep(0.05)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +1,24 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
|
||||
require 'capybara'
|
||||
require 'capybara/wait_until'
|
||||
require 'capybara/timeout'
|
||||
|
||||
module Capybara
|
||||
|
||||
describe WaitUntil do
|
||||
describe '.timeout' do
|
||||
|
||||
it "should return result of yield if it returns true value within timeout" do
|
||||
WaitUntil.timeout { "hello" }.should == "hello"
|
||||
Capybara.timeout { "hello" }.should == "hello"
|
||||
end
|
||||
|
||||
it "should keep trying within timeout" do
|
||||
count = 0
|
||||
WaitUntil.timeout { count += 1; count == 5 ? count : nil }.should == 5
|
||||
Capybara.timeout { count += 1; count == 5 ? count : nil }.should == 5
|
||||
end
|
||||
|
||||
it "should raise Capybara::TimeoutError if block fails to return true within timeout" do
|
||||
running do
|
||||
WaitUntil.timeout(0.1) { false }
|
||||
Capybara.timeout(0.1) { false }
|
||||
end.should raise_error(::Capybara::TimeoutError)
|
||||
end
|
||||
|
Loading…
Reference in a new issue