lib/rspec_tracer/html_reporter/reporter.rb in rspec-tracer-0.5.0 vs lib/rspec_tracer/html_reporter/reporter.rb in rspec-tracer-0.6.0
- old
+ new
@@ -4,37 +4,47 @@
require 'time'
module RSpecTracer
module HTMLReporter
class Reporter
- attr_reader :last_run, :examples, :examples_dependency, :files_dependency
+ attr_reader :last_run, :examples, :flaky_examples, :examples_dependency, :files_dependency
def initialize
@reporter = RSpecTracer.runner.reporter
format_last_run
format_examples
+ format_flaky_examples
format_examples_dependency
format_files_dependency
end
def generate_report
- Dir[File.join(File.dirname(__FILE__), 'public/*')].each do |path|
- FileUtils.cp_r(path, asset_output_path)
- end
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ copy_assets
+
file_name = File.join(RSpecTracer.report_path, 'index.html')
File.open(file_name, 'wb') do |file|
file.puts(template('layout').result(binding))
end
- puts "RSpecTracer generated HTML report to #{file_name}"
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ elpased = RSpecTracer::TimeFormatter.format_time(ending - starting)
+
+ puts "RSpecTracer generated HTML report to #{file_name} (took #{elpased})"
end
private
+ def copy_assets
+ Dir[File.join(File.dirname(__FILE__), 'public/*')].each do |path|
+ FileUtils.cp_r(path, asset_output_path)
+ end
+ end
+
def format_last_run
@last_run = @reporter.last_run.slice(
:actual_count,
:failed_examples,
:pending_examples,
@@ -55,10 +65,14 @@
last_run: example_run_local_time(example[:execution_result][:finished_at])
}
end
end
+ def format_flaky_examples
+ @flaky_examples = @examples.slice(*@reporter.flaky_examples).values
+ end
+
def example_run_local_time(utc_time)
case utc_time
when Time
utc_time.localtime.strftime('%Y-%m-%d %H:%M:%S')
when String
@@ -126,10 +140,18 @@
current_binding.local_variable_set(:title_id, title_id)
template(title_id).result(current_binding)
end
+ def formatted_flaky_examples(title, flaky_examples)
+ title_id = report_container_id(title)
+ current_binding = binding
+
+ current_binding.local_variable_set(:title_id, title_id)
+ template(title_id).result(current_binding)
+ end
+
def formatted_examples_dependency(title, examples_dependency)
title_id = report_container_id(title)
current_binding = binding
current_binding.local_variable_set(:title_id, title_id)
@@ -152,10 +174,10 @@
ERB.new(File.read(File.join(File.dirname(__FILE__), 'views/', "#{name}.erb")))
end
def example_status_css_class(example_status)
case example_status.split.first
- when 'Failed'
+ when 'Failed', 'Flaky'
'red'
when 'Pending'
'yellow'
else
'blue'