Module: Wrong::Eventually

Included in:
Helpers
Defined in:
lib/wrong/eventually.rb

Constant Summary collapse

NO_BLOCK_PASSED =
"you must pass a block to the eventually method"

Instance Method Summary collapse

Instance Method Details

#eventually(options = {}, &block) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wrong/eventually.rb', line 5

def eventually options = {}, &block
  raise NO_BLOCK_PASSED if block.nil?
  timeout = options[:timeout] || 5
  delay = options[:delay] || 0.25
  last_error = nil
  success = nil
  begin_time = Time.now      
  while (Time.now - begin_time) < timeout
    begin
      aver(:assert, &block)
      return
    rescue Exception => e
      last_error = e
      sleep delay
    end
  end
  raise last_error
end