# frozen_string_literal: true module GitlabQuality module TestTooling module TestResult class BaseTestResult IGNORED_FAILURES = [ 'Net::ReadTimeout', '403 Forbidden - Your account has been blocked' ].freeze SHARED_EXAMPLES_CALLERS = %w[include_examples it_behaves_like].freeze attr_reader :report def initialize(report:, token: nil, project: nil, ref: 'master') @report = report @token = token @project = project @ref = ref end def stage @stage ||= file[%r{(?:api|browser_ui)/(?:(?:\d+_)?(\w+))}, 1] || category end def name raise NotImplementedError end def file raise NotImplementedError end def line_number raise NotImplementedError end def section raise NotImplementedError end def category raise NotImplementedError end def skipped? raise NotImplementedError end def failures raise NotImplementedError end def failures? failures.any? end def full_stacktrace failures.each do |failure| message = failure['message'] || "" message_lines = failure['message_lines'] || [] next if IGNORED_FAILURES.any? { |e| message.include?(e) } return message_lines.empty? ? message : message_lines.join("\n") end end def calls_shared_examples? reported_line = files_client.file_contents_at_line(line_number) return false unless reported_line SHARED_EXAMPLES_CALLERS.any? { |caller_method| reported_line.strip.start_with?(caller_method) } end def files_client @files_client ||= GitlabClient::RepositoryFilesClient.new( token: token, project: project, file_path: file, ref: ref) end private attr_reader :token, :project, :ref end end end end