Sha256: 86fd8cdc0e33ed63865592afa75798b94a5915351e40dc8f915a8c0c48bb4b02

Contents?: true

Size: 622 Bytes

Versions: 18

Compression:

Stored size: 622 Bytes

Contents

module SpecHelpers
  module Wait
    # Wait before the value of the "before" Proc becomes "becomes",
    # but only wait until "duration" number of seconds,
    # while checking the value each "interval" seconds interval.
    def wait(duration: 5.seconds, interval: (0.5).second, before:, becomes:)
      # use a different thread to prevent blocking the main thread due to sleep()
      Thread.new do
        start = Time.now

        loop do
          break if becomes.call(before.call)
          sleep interval.seconds
          break if (Time.now - start).seconds > duration
        end
      end.join
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
live_record-1.0.2 spec/helpers/wait.rb
live_record-1.0.1 spec/helpers/wait.rb
live_record-1.0.0 spec/helpers/wait.rb
live_record-0.3.6 spec/helpers/wait.rb
live_record-0.3.4 spec/helpers/wait.rb
live_record-0.3.3 spec/helpers/wait.rb
live_record-0.3.2 spec/helpers/wait.rb
live_record-0.3.1 spec/helpers/wait.rb
live_record-0.3.0 spec/helpers/wait.rb
live_record-0.2.8 spec/helpers/wait.rb
live_record-0.2.7 spec/helpers/wait.rb
live_record-0.2.6 spec/helpers/wait.rb
live_record-0.2.5 spec/helpers/wait.rb
live_record-0.2.4 spec/helpers/wait.rb
live_record-0.2.3 spec/helpers/wait.rb
live_record-0.2.2 spec/helpers/wait.rb
live_record-0.2.1 spec/helpers/wait.rb
live_record-0.2.0 spec/helpers/wait.rb