class StackPrinterTest

  1. test/stack_printer_test.rb

Public Instance methods

setup ()
[show source]
# File test/stack_printer_test.rb, line 29
def setup
  # Need to use wall time for this test due to the sleep calls
  RubyProf::measure_mode = RubyProf::WALL_TIME
end
test_method_elimination ()
[show source]
# File test/stack_printer_test.rb, line 50
def test_method_elimination
  RubyProf.start
  5.times{STPT.new.a}
  result = RubyProf.stop
  assert_nothing_raised {
    # result.dump
    result.eliminate_methods!([%rInteger#times/])
    # $stderr.puts "================================"
    # result.dump
    print(result)
  }
end
test_stack_can_be_printed ()
[show source]
# File test/stack_printer_test.rb, line 34
def test_stack_can_be_printed
  start_time = Time.now
  RubyProf.start
  5.times{STPT.new.a}
  result = RubyProf.stop
  end_time = Time.now
  expected_time = end_time - start_time

  file_contents = nil
  assert_nothing_raised { file_contents = print(result) }
  assert file_contents =~ %rThread: (\d+) \(100\.00% ~ ([.0-9]+)\)/
  actual_time = $2.to_f
  difference = (expected_time-actual_time).abs
  assert_in_delta(expected_time, actual_time, 0.01)
end