Module: Lebowski::Foundation::Mixins::WaitActions

Includes:
Lebowski::Foundation
Included in:
ProxyObject
Defined in:
lib/lebowski/foundation/mixins/wait_actions.rb

Overview

Mixin provides actions to wait on something. By waiting no further action will be taken until a condition has been met or a timeout has been reached.

Constant Summary

DEFAULT_TIMEOUT =

seconds

10

Constants included from Lebowski::Foundation

SC_BRANCH_CLOSED, SC_BRANCH_OPEN, SC_BUTTON1_STATUS, SC_BUTTON2_STATUS, SC_BUTTON3_STATUS, SC_LEAF_NODE, SC_MIXED_STATE, SC_PICKER_FIXED, SC_PICKER_MENU, SC_PICKER_POINTER, SC_T_ARRAY, SC_T_BOOL, SC_T_CLASS, SC_T_ERROR, SC_T_FUNCTION, SC_T_HASH, SC_T_NULL, SC_T_NUMBER, SC_T_OBJECT, SC_T_STRING, SC_T_UNDEFINED

Instance Method Summary (collapse)

Instance Method Details

- (Object) wait_until(timeout = nil, &block)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lebowski/foundation/mixins/wait_actions.rb', line 20

def wait_until(timeout=nil, &block)
  timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout
  
  if not timeout.kind_of? Integer or timeout <= 0
    raise ArgumentError.new "Must supply a valid timeout that is greater than 0"
  end
  
  if not block_given?
    raise ArgumentError.new "Must supply a block"
  end

  start_time = Time.now
  current_time = Time.now

  while (current_time - start_time) < timeout
    result = yield self
    return if (result == true)
    sleep 0.5
    current_time = Time.now
  end
  
  raise TimeoutError.new "Timed out after #{timeout} seconds"
  
end