This commit is contained in:
John Bintz 2012-09-18 06:05:38 -04:00
commit e247347160
2 changed files with 48 additions and 6 deletions

View File

@ -1,3 +1,5 @@
require 'sourcify'
MAX_TIMES = 20 MAX_TIMES = 20
WAIT_TIME = 0.1 WAIT_TIME = 0.1
@ -6,6 +8,9 @@ def _wait_for_exceptions
if defined?(Capybara::Driver::Webkit::Node::ElementNotDisplayedError) if defined?(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
exceptions << Capybara::Driver::Webkit::Node::ElementNotDisplayedError exceptions << Capybara::Driver::Webkit::Node::ElementNotDisplayedError
end end
if defined?(Selenium::WebDriver::Error::StaleElementReferenceError)
exceptions << Selenium::WebDriver::Error::StaleElementReferenceError
end
exceptions exceptions
end end
@ -19,12 +24,35 @@ def _wait_for_not_exceptions
exceptions exceptions
end end
def wait_for(times = MAX_TIMES) def _wait_for_not_continue_exceptions
exceptions = []
if defined?(Selenium::WebDriver::Error::StaleElementReferenceError)
exceptions << Selenium::WebDriver::Error::StaleElementReferenceError
end
exceptions
end
class WaitingForElementFailure < StandardError
def initialize(code)
@code = code
end
def message
@code.to_source(:strip_enclosure => true)
end
def backtrace
[ @code.source_location.join(":") ]
end
end
def wait_for(times = MAX_TIMES, &block)
1.upto(times) do 1.upto(times) do
ok = false ok = false
begin begin
ok = yield ok = block.()
rescue *_wait_for_exceptions rescue *_wait_for_exceptions
ok = false ok = false
end end
@ -36,10 +64,10 @@ def wait_for(times = MAX_TIMES)
end end
end end
raise StandardError.new("Failed") raise WaitingForElementFailure.new(block)
end end
def wait_for_not(times = MAX_TIMES) def wait_for_not(times = MAX_TIMES, &block)
original_time = Capybara.default_wait_time original_time = Capybara.default_wait_time
Capybara.default_wait_time = 0 Capybara.default_wait_time = 0
@ -47,7 +75,9 @@ def wait_for_not(times = MAX_TIMES)
ok = false ok = false
begin begin
yield block.()
rescue *_wait_for_not_continue_exceptions
ok = false
rescue *_wait_for_not_exceptions rescue *_wait_for_not_exceptions
ok = true ok = true
end end
@ -61,6 +91,6 @@ def wait_for_not(times = MAX_TIMES)
end end
end end
raise StandardError.new('Timed out') raise WaitingForElementFailure.new(block)
end end

View File

@ -0,0 +1,12 @@
require 'cuke-pack/tasks'
task(:default).clear
task :preflight_check do
task('cuke_pack:any_wip').invoke
end
task :default do
task('cuke_pack:precommit').invoke
end