class RSpecTracer::HTMLReporter::Reporter
Attributes
examples[R]
examples_dependency[R]
files_dependency[R]
flaky_examples[R]
last_run[R]
Public Class Methods
new()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 11 def initialize @reporter = RSpecTracer.runner.reporter format_last_run format_examples format_flaky_examples format_examples_dependency format_files_dependency end
Public Instance Methods
generate_report()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 21 def generate_report 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 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 Instance Methods
asset_output_path()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 123 def asset_output_path @asset_output_path ||= begin asset_output_path = File.join(RSpecTracer.report_path, 'assets', RSpecTracer::VERSION) FileUtils.mkdir_p(asset_output_path) asset_output_path end end
assets_path(name)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 133 def assets_path(name) File.join('./assets', RSpecTracer::VERSION, name) end
copy_assets()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 40 def copy_assets Dir[File.join(File.dirname(__FILE__), 'public/*')].each do |path| FileUtils.cp_r(path, asset_output_path) end end
example_location(file_name, line_number)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 115 def example_location(file_name, line_number) "#{shortened_file_name(file_name)}:#{line_number}" end
example_result_css_class(example_result)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 188 def example_result_css_class(example_result) case example_result when 'Passed' 'green' when 'Failed' 'red' when 'Pending' 'yellow' else 'blue' end end
example_run_local_time(utc_time)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 74 def example_run_local_time(utc_time) case utc_time when Time utc_time.localtime.strftime('%Y-%m-%d %H:%M:%S') when String Time.parse(utc_time).localtime.strftime('%Y-%m-%d %H:%M:%S') else utc_time.inspect end end
example_status_css_class(example_status)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 177 def example_status_css_class(example_status) case example_status.split.first when 'Failed', 'Flaky' 'red' when 'Pending' 'yellow' else 'blue' end end
format_examples()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 55 def format_examples @examples = {} @reporter.all_examples.each_pair do |example_id, example| @examples[example_id] = { id: example_id, description: example[:full_description], location: example_location(example[:rerun_file_name], example[:rerun_line_number]), status: example[:run_reason] || 'Skipped', result: example[:execution_result][:status].capitalize, last_run: example_run_local_time(example[:execution_result][:finished_at]) } end end
format_examples_dependency()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 85 def format_examples_dependency @examples_dependency = [] @reporter.dependency.each_pair do |example_id, files| @examples_dependency << { example_id: example_id, example: @examples[example_id][:description], files_count: files.count, files: files.map { |file_name| shortened_file_name(file_name) }.sort.join(', ') } end end
format_files_dependency()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 98 def format_files_dependency @files_dependency = [] @reporter.reverse_dependency.each_pair do |main_file_name, data| short_file_name = shortened_file_name(main_file_name) @files_dependency << { name: short_file_name, example_count: data[:example_count], file_count: data[:examples].count, files: data[:examples] .map { |file_name, count| "#{shortened_file_name(file_name)}: #{count}" } .join(', ') } end end
format_flaky_examples()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 70 def format_flaky_examples @flaky_examples = @examples.slice(*@reporter.flaky_examples).values end
format_last_run()
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 46 def format_last_run @last_run = @reporter.last_run.slice( :actual_count, :failed_examples, :pending_examples, :skipped_examples ) end
formatted_examples(title, examples)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 137 def formatted_examples(title, 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
formatted_examples_dependency(title, examples_dependency)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 153 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) template(title_id).result(current_binding) end
formatted_files_dependency(title, files_dependency)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 161 def formatted_files_dependency(title, files_dependency) 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
formatted_flaky_examples(title, flaky_examples)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 145 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
report_container_id(title)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 169 def report_container_id(title) title.gsub(/\s+/, ' ').downcase.tr(' ', '_') end
shortened_file_name(file_name)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 119 def shortened_file_name(file_name) file_name.sub(%r{^/}, '') end
template(name)
click to toggle source
# File lib/rspec_tracer/html_reporter/reporter.rb, line 173 def template(name) ERB.new(File.read(File.join(File.dirname(__FILE__), 'views/', "#{name}.erb"))) end