class Minitest::Hyper::Report

Attributes

reporter[R]

Public Class Methods

new(reporter) click to toggle source
# File lib/minitest/hyper/report.rb, line 9
def initialize(reporter)
  @reporter = reporter
end

Public Instance Methods

dirname() click to toggle source
# File lib/minitest/hyper/report.rb, line 23
def dirname
  Minitest::Hyper.report_dirname
end
filename() click to toggle source
# File lib/minitest/hyper/report.rb, line 27
def filename
  Minitest::Hyper.report_filename
end
url() click to toggle source
# File lib/minitest/hyper/report.rb, line 19
def url
  "file://#{ filename.gsub(/\\/, "/") }"
end
write() click to toggle source
# File lib/minitest/hyper/report.rb, line 13
def write
  ensure_output_dir
  move_existing_file
  write_file
end

Private Instance Methods

css_string() click to toggle source
# File lib/minitest/hyper/report.rb, line 62
def css_string
  File.read(CSS_TEMPLATE)
end
ensure_output_dir() click to toggle source
# File lib/minitest/hyper/report.rb, line 33
def ensure_output_dir
  unless Dir.exist?(dirname)
    FileUtils.mkdir_p dirname
  end
end
move_existing_file() click to toggle source
# File lib/minitest/hyper/report.rb, line 39
def move_existing_file
  if File.exist?(filename)
    ctime = File.ctime(filename)
    time_str = ctime.strftime("%Y%m%d%H%M%S")
    new_name = filename.sub(/\.html$/, "_#{ time_str }.html")
    FileUtils.mv(filename, new_name)
  end
end
template_string() click to toggle source
# File lib/minitest/hyper/report.rb, line 66
def template_string
  File.read(HTML_TEMPLATE)
end
write_file() click to toggle source
# File lib/minitest/hyper/report.rb, line 48
def write_file
  page_info = {
    title: "Minitest::Hyper Test Report",
    styles: css_string,
    timestamp: Time.now
  }
  test_info = reporter.to_h

  erb = ERB.new(template_string)
  File.open(filename, "wb") do |file|
    file.write erb.result(binding)
  end
end