Class: RspecTimer

Inherits:
Object
  • Object
show all
Extended by:
SingleForwardable
Includes:
Singleton
Defined in:
lib/rspec_timer.rb,
lib/rspec_timer/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRspecTimer

Returns a new instance of RspecTimer.



14
15
16
# File 'lib/rspec_timer.rb', line 14

def initialize
  reset_metrics
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



12
13
14
# File 'lib/rspec_timer.rb', line 12

def metrics
  @metrics
end

Instance Method Details

#end_measurement(example) ⇒ Object



29
30
31
32
33
34
# File 'lib/rspec_timer.rb', line 29

def end_measurement(example)
  current_metrics              = metrics_for(example)
  current_metrics[:end_time]   = Time.now
  current_metrics[:total_time] = current_metrics[:end_time] - current_metrics[:start_time]
  example
end

#reset_metricsObject



18
19
20
# File 'lib/rspec_timer.rb', line 18

def reset_metrics
  @metrics = {}
end

#run_and_measure(example) ⇒ Object



36
37
38
39
40
# File 'lib/rspec_timer.rb', line 36

def run_and_measure(example)
  start_measurement(example)
  example.run
  end_measurement(example)
end

#save_metrics_to_file(file_name) ⇒ Object



42
43
44
# File 'lib/rspec_timer.rb', line 42

def save_metrics_to_file(file_name)
  File.write(file_name, YAML.dump(@metrics))
end

#start_measurement(example) ⇒ Object



22
23
24
25
26
27
# File 'lib/rspec_timer.rb', line 22

def start_measurement(example)
  current_metrics              = metrics_for(example)
  current_metrics[:signature]  = signature_for(example)
  current_metrics[:start_time] = Time.now
  example
end