| Class | Test::Unit::TestCase |
| In: |
lib/ruby-prof/profile_test_case.rb
|
| Parent: | Object |
| run | -> | run__profile__ |
# File lib/ruby-prof/profile_test_case.rb, line 61
61: def create_output_directory
62: if not File.exist?(output_directory)
63: Dir.mkdir(output_directory)
64: end
65: end
# File lib/ruby-prof/profile_test_case.rb, line 67
67: def file_extension
68: if printer == RubyProf::FlatPrinter
69: '.html'
70: else
71: '.txt'
72: end
73: end
Add some additional methods
# File lib/ruby-prof/profile_test_case.rb, line 52
52: def min_percent
53: 1
54: end
# File lib/ruby-prof/profile_test_case.rb, line 56
56: def output_directory
57: # Put results in subdirectory called profile
58: File.join(Dir.getwd, 'profile')
59: end
# File lib/ruby-prof/profile_test_case.rb, line 75
75: def printer
76: RubyProf::GraphHtmlPrinter
77: end
# File lib/ruby-prof/profile_test_case.rb, line 11
11: def run(result, &block)
12: test_name = @method_name.to_sym
13: alias_test_name = (@method_name + '__profile__').to_sym
14:
15: self.class.class_eval("alias :#{alias_test_name} :#{test_name}")
16:
17: self.class.send(:define_method, test_name) do
18: # Run the profiler
19: RubyProf.start
20: __send__(alias_test_name)
21: result = RubyProf.stop
22:
23: create_output_directory
24:
25: # Get the result file name
26: file_name = name.gsub(/\(/, '_').gsub(/\)/, '')
27: file_name = self.underscore(file_name)
28: file_path = File.join(output_directory, file_name)
29: file_path += file_extension
30:
31: # Create a printer
32: printer = self.printer.new(result)
33:
34: # Write the results
35: File.open(file_path, 'w') do |file|
36: printer.print(file, min_percent)
37: end
38: end
39:
40: self.run__profile__(result, &block)
41: end