Class: SitePrism::Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/site_prism/waiter.rb

Overview

SitePrism::Waiter

Class Method Summary collapse

Class Method Details

.wait_until_true(wait_time = Capybara.default_max_wait_time, sleep_duration = 0.05) ⇒ Boolean

A looper that will wait until the passed in block evaluates to true Alternatively it will time out once the wait_time is exceeded

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/site_prism/waiter.rb', line 10

def self.wait_until_true(wait_time = Capybara.default_max_wait_time, sleep_duration = 0.05)
  Timer.run(wait_time) do |timer|
    loop do
      return true if yield
      break if timer.done?

      sleep(sleep_duration)
    end
    raise SitePrism::TimeoutError, "Timed out after #{wait_time}s."
  end
end