Class: Soaspec::Wait
- Inherits:
-
Object
- Object
- Soaspec::Wait
- Defined in:
- lib/soaspec/wait.rb
Overview
Class to enable waiting for an expected condition to return true
Constant Summary collapse
- DEFAULT_TIMEOUT =
5
- DEFAULT_INTERVAL =
0.2
Class Method Summary collapse
-
.until(opts = {}) ⇒ Object
Wait until the given block returns a true value.
Class Method Details
.until(opts = {}) ⇒ Object
Wait until the given block returns a true value.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/soaspec/wait.rb', line 19 def self.until(opts = {}) timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) ignored = Array(opts[:ignore] || NoElementAtPath) interval = opts.fetch(:interval, DEFAULT_INTERVAL) end_time = Time.now + timeout last_error = nil until Time.now > end_time begin result = yield return result if result rescue *ignored => last_error # swallowed end sleep interval end msg = opts[:message] ? opts[:message].dup : "timed out after #{timeout} seconds with interval of #{interval}" msg << " (#{last_error.})" if last_error raise Soaspec::TimeOutError, msg end |