Class: RspecLogFormatter::PerformanceAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_log_formatter/performance_analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ PerformanceAnalyzer

Returns a new instance of PerformanceAnalyzer.


17
18
19
# File 'lib/rspec_log_formatter/performance_analyzer.rb', line 17

def initialize(filepath)
  @history_manager = HistoryManager.new(filepath)
end

Instance Method Details

#analyze(test_description) ⇒ Object


31
32
33
34
35
36
37
38
# File 'lib/rspec_log_formatter/performance_analyzer.rb', line 31

def analyze(test_description)
  @history_manager.results
  .select{ |result| Array(test_description).include? result.description }
  .reduce({}) do |memo, result|
    memo[result.time.to_s] = result.duration
    memo
  end
end

#write(description, filepath) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'lib/rspec_log_formatter/performance_analyzer.rb', line 21

def write(description, filepath)
  chartkick_js = File.open(File.join(File.dirname(__FILE__), './javascripts/chartkick.js')).read
  data = analyze(description)
  context = ERBContext.new({chartkick_js: chartkick_js, plots: data})
  template = ERB.new(File.open(File.join(File.dirname(__FILE__), './templates/charts.html.erb')).read)
  html = template.result(context.get_binding)

  File.open(filepath, 'w').write(html)
end