Class: GitlabQuality::TestTooling::CodeCoverage::RspecReport

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/code_coverage/rspec_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(rspec_report) ⇒ RspecReport

Returns a new instance of RspecReport.

Parameters:

  • rspec_report (Hash<String, Object>)

    The content of an RSpec report



11
12
13
# File 'lib/gitlab_quality/test_tooling/code_coverage/rspec_report.rb', line 11

def initialize(rspec_report)
  @rspec_report = rspec_report
end

Instance Method Details

#examplesArray<Hash<String, String>>

Returns Content of the “examples” section of the RSpec report.

Returns:

  • (Array<Hash<String, String>>)

    Content of the “examples” section of the RSpec report



17
18
19
# File 'lib/gitlab_quality/test_tooling/code_coverage/rspec_report.rb', line 17

def examples
  @examples ||= @rspec_report['examples']
end

#tests_to_categoriesHash<String, Array<String>>

Returns Test files mapped to all feature categories they belong to.

Examples:

Return value

{
  "spec/path/to/file_spec.rb" => [
    "feature_category1", "feature_category2"
  ],
  ...
}

Returns:

  • (Hash<String, Array<String>>)

    Test files mapped to all feature categories they belong to



30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab_quality/test_tooling/code_coverage/rspec_report.rb', line 30

def tests_to_categories
  @tests_to_categories ||= examples.to_a.filter_map do |example|
    next unless example.is_a?(Hash)

    file_path = example['file_path']
    next unless file_path.is_a?(String)

    [file_path.gsub('./', ''), Array(example['feature_category']).compact]
  end.to_h
end