Sha256: 9ab1125ac02e4090913d50ad005b89cff2133038d083acc2909b97b1c40cd78c

Contents?: true

Size: 657 Bytes

Versions: 6

Compression:

Stored size: 657 Bytes

Contents

module TakeAtMostHelper
  # Assert that it takes at most a certain amount of time to run a block.
  #
  # @example
  #  # Assert that it takes at most 1 second to run the block
  #  take_at_most(1) { sleep 0.5 }
  #
  # @param time [Integer, Float] The maximum amount of time the block is allowed to
  #  run in seconds.
  # @yield Block to run.
  # @raise [StandardError] Raises error if the block takes longer than the
  #  specified time to run.
  def take_at_most(time)
    start = Time.now
    yield
    elapsed = Time.now - start
    return if elapsed <= time

    raise "Expected block to take at most #{time} seconds, but took #{elapsed}"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
appsignal-4.0.6-java spec/support/helpers/take_at_most_helper.rb
appsignal-4.0.6 spec/support/helpers/take_at_most_helper.rb
appsignal-4.0.5-java spec/support/helpers/take_at_most_helper.rb
appsignal-4.0.5 spec/support/helpers/take_at_most_helper.rb
appsignal-4.0.4-java spec/support/helpers/take_at_most_helper.rb
appsignal-4.0.4 spec/support/helpers/take_at_most_helper.rb