Sha256: 30e17f7219d7163026a261f8fb00e05d4c654f5b743ea5bba9429f60dda26b7f

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Polonium
  module WaitFor
    Context = Struct.new(:message)
    # Poll continuously for the return value of the block to be true. You can use this to assert that a client side
    # or server side condition was met.
    #   wait_for do
    #     User.count == 5
    #   end
    def wait_for(params={})
      timeout = params[:timeout] || default_wait_for_time
      message = params[:message] || "Timeout exceeded"
      configuration = Context.new(message)
      begin_time = time_class.now
      while (time_class.now - begin_time) < timeout
        if value = yield(configuration)
          return value
        end
        return value if value
        sleep 0.25
      end
      flunk(configuration.message + " (after #{timeout} sec)")
      true
    end

    def default_wait_for_time
      5
    end

    def time_class
      Time
    end

    # The default Selenium Core client side timeout.
    def default_timeout
      @default_timeout ||= 20000
    end
    attr_writer :default_timeout

    def flunk(message)
      raise Polonium::PoloniumError, message
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polonium-0.3.1 lib/polonium/wait_for.rb
polonium-0.3.0 lib/polonium/wait_for.rb