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
49 50 51 52 53 54 |
# File 'lib/factory_inspector.rb', line 49 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/factory_inspector.rb', line 20 def generate_report(output_filename) file = File.open(output_filename, 'w') file.write "FACTORY INSPECTOR - #{@reports.values.size} FACTORIES USED\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(" %-25.25s % 5.0d %5.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 |
# File 'lib/factory_inspector.rb', line 13 def start_inspection @reports = {} 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 |