Class: FactoryInspector::Inspector
- Inherits:
-
Object
- Object
- FactoryInspector::Inspector
- Defined in:
- lib/factory_inspector.rb
Instance Method Summary collapse
-
#analyze(factory_name, start_time, finish_time, strategy) ⇒ Object
Callback for use by ActiveSupport::Notifications, not for end user use directly though it has to be public for ActiveSupport to see it.
- #generate_report(output_filename) ⇒ Object
- #start_inspection ⇒ Object
Instance Method Details
#analyze(factory_name, start_time, finish_time, strategy) ⇒ Object
Callback for use by ActiveSupport::Notifications, not for end user use directly though it has to be public for ActiveSupport to see it.
- factory_name
-
Factory name
- start_time
-
The start time of the factory call
- finish_time
-
The finish time of the factory call
- strategy
-
The strategy used when calling the factory
59 60 61 62 63 64 |
# File 'lib/factory_inspector.rb', line 59 def analyze(factory_name, start_time, finish_time, strategy) if not @reports.has_key? factory_name @reports[factory_name] = FactoryInspector::Report.new(factory_name) end @reports[factory_name].update(finish_time - start_time, strategy) end |
#generate_report(output_filename) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/factory_inspector.rb', line 21 def generate_report(output_filename) inspection_time_in_seconds = Time.now - @inspection_start_time factory_time_in_seconds = calculate_total_factory_time_in_seconds percentage_time_in_factories = ( (factory_time_in_seconds * 100) / inspection_time_in_seconds ) file = File.open(output_filename, 'w') file.write "FACTORY INSPECTOR\n" file.write " - #{@reports.values.size} factories used, #{calculate_total_factory_calls} calls made\n" file.write " - #{sprintf("%6.4f",inspection_time_in_seconds)} seconds of testing inspected\n" file.write " - #{sprintf("%6.4f",factory_time_in_seconds)} seconds in factories\n" file.write " - #{sprintf("%4.1f",percentage_time_in_factories)}% testing time is factory calls\n" file.write "\n" file.write " FACTORY NAME TOTAL OVERALL TIME PER LONGEST STRATEGIES\n" file.write " CALLS TIME (s) CALL (s) CALL (s) \n" @reports.sort_by{ |name,report| report.time_per_call_in_seconds }.reverse.each do |report_name, report| line = sprintf(" %-30.30s % 5.0d %8.4f %5.5f %5.4f %s\n", report.factory_name, report.calls, report.total_time_in_seconds, report.time_per_call_in_seconds, report.worst_time_in_seconds, report.strategies) file.write(line) end file.close end |
#start_inspection ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/factory_inspector.rb', line 13 def start_inspection @reports = {} @inspection_start_time = Time.now ActiveSupport::Notifications.subscribe('factory_girl.run_factory') do |name, start_time, finish_time, id, payload| analyze(payload[:name], start_time, finish_time, payload[:strategy]) end end |