class RspecLogFormatter::PerformanceAnalyzer

Public Class Methods

new(filepath) click to toggle source
# File lib/rspec_log_formatter/performance_analyzer.rb, line 17
def initialize(filepath)
  @history_manager = HistoryManager.new(filepath)
end

Public Instance Methods

analyze(test_description) click to toggle source
# 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) click to toggle source
# 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