factory_inspector 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,15 +12,25 @@ module FactoryInspector
12
12
 
13
13
  def start_inspection
14
14
  @reports = {}
15
+ @inspection_start_time = Time.now
15
16
  ActiveSupport::Notifications.subscribe('factory_girl.run_factory') do |name, start_time, finish_time, id, payload|
16
17
  analyze(payload[:name], start_time, finish_time, payload[:strategy])
17
18
  end
18
19
  end
19
20
 
20
21
  def generate_report(output_filename)
22
+ inspection_time_in_seconds = Time.now - @inspection_start_time
23
+ factory_time_in_seconds = calculate_total_factory_time_in_seconds
24
+ percentage_time_in_factories = ( (factory_time_in_seconds * 100) / inspection_time_in_seconds )
25
+
21
26
  file = File.open(output_filename, 'w')
22
27
 
23
- file.write "FACTORY INSPECTOR - #{@reports.values.size} FACTORIES USED\n"
28
+ file.write "FACTORY INSPECTOR\n"
29
+ file.write " - #{@reports.values.size} factories used, #{calculate_total_factory_calls} calls made\n"
30
+ file.write " - #{sprintf("%6.4f",inspection_time_in_seconds)} seconds of testing inspected\n"
31
+ file.write " - #{sprintf("%6.4f",factory_time_in_seconds)} seconds in factories\n"
32
+ file.write " - #{sprintf("%4.1f",percentage_time_in_factories)}% testing time is factory calls\n"
33
+ file.write "\n"
24
34
  file.write " FACTORY NAME TOTAL OVERALL TIME PER LONGEST STRATEGIES\n"
25
35
  file.write " CALLS TIME (s) CALL (s) CALL (s) \n"
26
36
  @reports.sort_by{ |name,report| report.time_per_call_in_seconds }.reverse.each do |report_name, report|
@@ -53,6 +63,20 @@ module FactoryInspector
53
63
  @reports[factory_name].update(finish_time - start_time, strategy)
54
64
  end
55
65
 
66
+ private
67
+
68
+ def calculate_total_factory_time_in_seconds
69
+ @reports.values.reduce(0) do |total_time_in_seconds, report|
70
+ total_time_in_seconds + report.total_time_in_seconds
71
+ end
72
+ end
73
+
74
+ def calculate_total_factory_calls
75
+ @reports.values.reduce(0) do |total_calls, report|
76
+ total_calls + report.calls
77
+ end
78
+ end
79
+
56
80
  end
57
81
 
58
82
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryInspector
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-29 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport