Class: FactoryInspector::Report
- Inherits:
-
Object
- Object
- FactoryInspector::Report
- Defined in:
- lib/factory_inspector/report.rb
Overview
Report on how a FactoryGirl Factory was used in a test run. Holds simple metrics and can be updated with new calls.
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#factory_name ⇒ Object
readonly
Returns the value of attribute factory_name.
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
-
#total_time_in_seconds ⇒ Object
readonly
Returns the value of attribute total_time_in_seconds.
-
#worst_time_in_seconds ⇒ Object
readonly
Returns the value of attribute worst_time_in_seconds.
Instance Method Summary collapse
-
#initialize(factory_name) ⇒ Report
constructor
A new instance of Report.
- #time_per_call_in_seconds ⇒ Object
-
#update(time, strategy) ⇒ Object
Update this report with a new call * [time] The time taken, in seconds, to call the factory * [strategy] The strategy used by the factory.
Constructor Details
#initialize(factory_name) ⇒ Report
Returns a new instance of Report.
13 14 15 16 17 18 19 |
# File 'lib/factory_inspector/report.rb', line 13 def initialize(factory_name) @factory_name = factory_name @calls = 0 @worst_time_in_seconds = 0 @total_time_in_seconds = 0 @strategies = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
7 8 9 |
# File 'lib/factory_inspector/report.rb', line 7 def calls @calls end |
#factory_name ⇒ Object (readonly)
Returns the value of attribute factory_name.
7 8 9 |
# File 'lib/factory_inspector/report.rb', line 7 def factory_name @factory_name end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
7 8 9 |
# File 'lib/factory_inspector/report.rb', line 7 def strategies @strategies end |
#total_time_in_seconds ⇒ Object (readonly)
Returns the value of attribute total_time_in_seconds.
7 8 9 |
# File 'lib/factory_inspector/report.rb', line 7 def total_time_in_seconds @total_time_in_seconds end |
#worst_time_in_seconds ⇒ Object (readonly)
Returns the value of attribute worst_time_in_seconds.
7 8 9 |
# File 'lib/factory_inspector/report.rb', line 7 def worst_time_in_seconds @worst_time_in_seconds end |
Instance Method Details
#time_per_call_in_seconds ⇒ Object
21 22 23 24 |
# File 'lib/factory_inspector/report.rb', line 21 def time_per_call_in_seconds return 0 if @calls == 0 @total_time_in_seconds / @calls end |
#update(time, strategy) ⇒ Object
Update this report with a new call
- time
-
The time taken, in seconds, to call the factory
- strategy
-
The strategy used by the factory
29 30 31 32 33 34 35 |
# File 'lib/factory_inspector/report.rb', line 29 def update(time, strategy) record_call record_time time if not @strategies.include? strategy @strategies << strategy end end |