class SpecifyHtmlReport
rubocop:disable Metrics/ClassLength
Constants
- DEFAULT_REPORT_PATH
- REPORT_PATH
- SCREEN_GRAB_PATH
- VIDEO_RECORD_PATH
Public Class Methods
new(_output)
click to toggle source
# File lib/specify_html_reporter.rb, line 22 def initialize(_output) create_report_directory create_screen_grabs_directory create_video_records_directory provide_report_resources @group_collection = {} @group_level = 0 end
Public Instance Methods
close(_notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 81 def close(_notification) File.open("#{REPORT_PATH}/overview.html", "w") do |f| @overview = @group_collection overview_results overview_durations @total_examples = @passed + @failed + @pending overview_file = File.read( File.dirname(__FILE__) + "/../templates/overview.erb" ) f.puts ERB.new(overview_file).result(binding) end end
example_failed(notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 71 def example_failed(notification) @group_example_failure_count += 1 @examples << Example.new(notification.example) end
example_group_finished(notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 44 def example_group_finished(notification) @group_level -= 1 return unless @group_level.zero? group_file = notification.group.description.parameterize @title = notification.group.description File.open("#{REPORT_PATH}/#{group_file}.html", "w") do |f| construct_report_file(notification) report_file = File.read( File.dirname(__FILE__) + "/../templates/report.erb" ) f.puts ERB.new(report_file).result(binding) end end
example_group_started(_notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 32 def example_group_started(_notification) return unless @group_level.zero? @examples = [] @group_example_count = 0 @group_example_success_count = 0 @group_example_failure_count = 0 @group_example_pending_count = 0 @group_level += 1 end
example_passed(notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 66 def example_passed(notification) @group_example_success_count += 1 @examples << Example.new(notification.example) end
example_pending(notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 76 def example_pending(notification) @group_example_pending_count += 1 @examples << Example.new(notification.example) end
example_started(_notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 62 def example_started(_notification) @group_example_count += 1 end
Private Instance Methods
build_group_collection(notification, status, status_values)
click to toggle source
# File lib/specify_html_reporter.rb, line 137 def build_group_collection(notification, status, status_values) type_class_map = { passed: 'success', failed: 'danger', pending: 'warning' } @group_collection[notification.group.description.parameterize] = { group: notification.group.description, status: status, status_type: type_class_map[status.to_sym], passed: status_values.select { |s| s == 'passed' }, failed: status_values.select { |s| s == 'failed' }, pending: status_values.select { |s| s == 'pending' }, duration: @summary_duration } end
construct_report_file(notification)
click to toggle source
# File lib/specify_html_reporter.rb, line 100 def construct_report_file(notification) report_results report_durations Example.load_spec_comments!(@examples) status_values = @examples.map(&:status) status = if status_values.include?('failed') 'failed' elsif status_values.include?('passed') 'passed' else 'pending' end build_group_collection(notification, status, status_values) end
create_report_directory()
click to toggle source
# File lib/specify_html_reporter.rb, line 193 def create_report_directory FileUtils.rm_rf(REPORT_PATH) if File.exist?(REPORT_PATH) FileUtils.mkpath(REPORT_PATH) end
create_screen_grabs_directory()
click to toggle source
# File lib/specify_html_reporter.rb, line 198 def create_screen_grabs_directory FileUtils.mkdir_p SCREEN_GRAB_PATH unless File.exist?(SCREEN_GRAB_PATH) end
create_video_records_directory()
click to toggle source
# File lib/specify_html_reporter.rb, line 202 def create_video_records_directory FileUtils.mkdir_p VIDEO_RECORD_PATH unless File.exist?(VIDEO_RECORD_PATH) end
overview_durations()
click to toggle source
# File lib/specify_html_reporter.rb, line 179 def overview_durations duration_values = @overview.values.map { |e| e[:duration] } duration_keys = duration_values.size.times.to_a @durations = duration_keys.zip( duration_values.map { |d| d.to_f.round(5) } ) @summary_duration = duration_values .map { |d| d.to_f.round(5) } .inject(0) { |sum, i| sum + i } .to_s(:rounded, precision: 5) end
overview_results()
click to toggle source
# File lib/specify_html_reporter.rb, line 155 def overview_results overview_results_passed overview_results_failed overview_results_pending end
overview_results_failed()
click to toggle source
# File lib/specify_html_reporter.rb, line 167 def overview_results_failed @failed = @overview.values .map { |g| g[:failed].size } .inject(0) { |sum, i| sum + i } end
overview_results_passed()
click to toggle source
# File lib/specify_html_reporter.rb, line 161 def overview_results_passed @passed = @overview.values .map { |g| g[:passed].size } .inject(0) { |sum, i| sum + i } end
overview_results_pending()
click to toggle source
# File lib/specify_html_reporter.rb, line 173 def overview_results_pending @pending = @overview.values .map { |g| g[:pending].size } .inject(0) { |sum, i| sum + i } end
provide_report_resources()
click to toggle source
# File lib/specify_html_reporter.rb, line 206 def provide_report_resources FileUtils.cp_r( File.dirname(__FILE__) + "/../resources", REPORT_PATH ) end
report_durations()
click to toggle source
# File lib/specify_html_reporter.rb, line 126 def report_durations duration_values = @examples.map(&:run_time) duration_keys = duration_values.size.times.to_a @durations = duration_keys.zip(duration_values) @summary_duration = duration_values .inject(0) { |sum, i| sum + i } .to_s(:rounded, precision: 5) end
report_results()
click to toggle source
# File lib/specify_html_reporter.rb, line 120 def report_results @passed = @group_example_success_count @failed = @group_example_failure_count @pending = @group_example_pending_count end