Sha256: 1b67cb2002cad3a343807f804fff0e4d99e9519e314e0c9a70eb4b8e89d8a841
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 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={}) return super unless block_given? 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.3 | lib/polonium/wait_for.rb |
polonium-0.3.2 | lib/polonium/wait_for.rb |