test/stack_printer_test.rb in ruby-prof-0.12.1 vs test/stack_printer_test.rb in ruby-prof-0.12.2
- old
+ new
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
# encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
-require 'tmpdir'
# Test data
# A
# / \
# B C
@@ -41,13 +40,14 @@
end_time = Time.now
expected_time = end_time - start_time
file_contents = nil
assert_nothing_raised { file_contents = print(result) }
- assert file_contents =~ /Thread: (\d+) \(100\.00% ~ ([.0-9]+)\)/
+ # TODO: why are thread ids negative on travis-ci.org (32 bit build maybe?)
+ assert_match(/Thread: (-?\d+) \(100\.00% ~ ([\.0-9]+)\)/, file_contents)
actual_time = $2.to_f
- assert_in_delta(expected_time, actual_time, 0.01)
+ assert_in_delta(expected_time, actual_time, 0.5)
end
def test_method_elimination
RubyProf.start
5.times{STPT.new.a}
@@ -62,12 +62,15 @@
end
private
def print(result)
test = caller.first =~ /in `(.*)'/ ? $1 : "test"
- testfile_name = "#{Dir::tmpdir}/ruby_prof_#{test}.html"
+ testfile_name = "#{RubyProf.tmpdir}/ruby_prof_#{test}.html"
+ # puts "printing to #{testfile_name}"
printer = RubyProf::CallStackPrinter.new(result)
File.open(testfile_name, "w") {|f| printer.print(f, :threshold => 0, :min_percent => 0, :title => "ruby_prof #{test}")}
system("open '#{testfile_name}'") if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
- File.open(testfile_name, "r"){|f| f.read}
+ assert File.exist?(testfile_name), "#{testfile_name} does not exist"
+ assert File.readable?(testfile_name), "#{testfile_name} is no readable"
+ File.read(testfile_name)
end
end