Welcome to mirror list, hosted at ThFree Co, Russian Federation.

example.rb « rspec_flaky « gitlab « lib « gitlab-rspec_flaky « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc3980e1e8de6f88c0fbfb8994d9c65ba6bee917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'forwardable'
require 'digest'

module Gitlab
  module RspecFlaky
    # This is a wrapper class for RSpec::Core::Example
    class Example
      extend Forwardable

      def_delegators :execution_result, :status, :exception

      def initialize(rspec_example)
        @rspec_example = rspec_example.respond_to?(:example) ? rspec_example.example : rspec_example
      end

      def uid
        @uid ||= Digest::MD5.hexdigest("#{description}-#{file}") # rubocop:disable Fips/MD5 -- MD5 is only used to compute and ID and we need to keep using for back-compat
      end

      def example_id
        rspec_example.id
      end

      def file
        metadata[:file_path]
      end

      def line
        metadata[:line_number]
      end

      def description
        metadata[:full_description]
      end

      def attempts
        rspec_example.respond_to?(:attempts) ? rspec_example.attempts : 1
      end

      def feature_category
        metadata[:feature_category]
      end

      def to_h
        {
          example_id: example_id,
          file: file,
          line: line,
          description: description,
          last_attempts_count: attempts,
          feature_category: feature_category
        }
      end

      private

      attr_reader :rspec_example

      def metadata
        rspec_example.metadata
      end

      def execution_result
        rspec_example.execution_result
      end
    end
  end
end