Skip to content
 
 

Recently, we debugged some tests that had started failing. The logic was appropriate, but we have some "wait" helper functions so that we only wait as long as necessary until they eventually and silently expire. We would wait one second for the data in the table to load, but after a second, we would proceed as if the table had data and it did not yet.

Once we figured out what was actually happening, we realized that the invisible elephant in the room was the word silently. We came up with requirements for communicating when the timers expire:

  • We do not want to fail the test just because a timer expired.

  • We want the communication to be informative.

  • We don't want to require the developer to pass a message every time they call one of these helper methods.

I found this solution from Andrew Johnson from 2004, but have no way to reach out seventeen years later to thank him for the help. I adapted the solution so that it is less boolean (in his solution, you either print the entire stack trace or just the line that called; mine allows you to pass the number of lines of stack trace that you would like to see or zero for just the line that called it):

module Kernel
  def warn_with_trace(msg = '', tracelength = 10_000)
    trace = caller(1, tracelength)
    where = trace.shift.sub(/:in.*/, '')
    warn "#{where}: Warning: #{msg}"
    warn(trace.map { |t| "\tfrom #{t}" }) if tracelength.positive?
 end
end

Indio Technologies logo

Mark Anderson is Director of Quality at Indio.