spec/support/async_helper.rb
def eventually(options = {})
    timeout    = options[:timeout] || 1 # seconds
    interval   = options[:interval] || 0.0001 # seconds
    time_limit = Time.now + timeout

    loop do
      begin
        yield
      rescue RSpec::Expectations::ExpectationNotMetError => error

      end

      return if error.nil?

      fail error if Time.now >= time_limit
      sleep interval
    end
  end
# Instead of waiting an specific an amount of time and then
# asserting for a certain behaviour, this test helper polls for an assertion
# success every X number of seconds (configurable as interval).
# The test will fail if the assertion doesn't pass after Y number of
# seconds (configurable as timeout).
Instead of waiting an specific an amount of time and then
asserting for a certain behaviour, this test helper polls for an assertion
success every X number of seconds (configurable as interval).
The test will fail if the assertion doesn't pass after Y number of
seconds (configurable as timeout).
Instead of waiting an specific an amount of time and then asserting for a certain behaviour this test helper polls for an assertion success every X number of seconds ( configurable as interval ) . The test will fail if the assertion doesn ' t pass after Y number of seconds ( configurable as timeout ) .
def eventually(options = {})
    timeout    = options[:timeout] || 1 
    interval   = options[:interval] || 0.0001 
    time_limit = Time.now + timeout
    loop do
      begin
        yield
      rescue RSpec::Expectations::ExpectationNotMetError => error
      end
      return if error.nil?
      fail error if Time.now >= time_limit
      sleep interval
    end
  end
def eventually ( options = { } ) timeout = options [ :timeout ] || 1 interval = options [ :interval ] || 0.0001 time_limit = Time . now + timeout loop do begin yield rescue RSpec :: Expectations :: ExpectationNotMetError => error end return if error . nil? fail error if Time . now >= time_limit sleep interval end end
Instead of waiting an specific an amount of time and then
asserting for a certain behaviour, this test helper polls for an assertion
success every X number of seconds (configurable as interval).
Instead of waiting an specific an amount of time and then asserting for a certain behaviour this test helper polls for an assertion success every X number of seconds ( configurable as interval ) .
# seconds # seconds
options