Sha256: e47733290e27462c65e498a4a1626c5f865d22dfef15166909d7cc50b91e724a

Contents?: true

Size: 1.19 KB

Versions: 27

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module AllureRspec
  # Suite label generator
  #
  class SuiteLabels
    include Utils

    def initialize(example_group)
      @example_group = example_group
    end

    # Get test suite labels
    # @return [Array<Allure::Label>]
    def fetch
      parents = example_group.parent_groups.map do |group|
        group.description.empty? ? "Anonymous" : group.description
      end

      labels = []
      labels << Allure::ResultUtils.suite_label(suite(parents))
      labels << Allure::ResultUtils.parent_suite_label(parent_suite(parents)) if parent_suite(parents)
      labels << Allure::ResultUtils.sub_suite_label(sub_suites(parents)) if sub_suites(parents)

      labels
    end

    private

    attr_reader :example_group

    # @param [Array<String>] parents
    # @return [String]
    def suite(parents)
      parents.length == 1 ? parents.last : parents[-2]
    end

    # @param [Array<String>] parents
    # @return [String]
    def parent_suite(parents)
      parents.length > 1 ? parents.last : nil
    end

    # @param [Array<String>] parents
    # @return [String]
    def sub_suites(parents)
      parents.length > 2 ? parents[0..-3].join(" > ") : nil
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
allure-rspec-2.25.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.5 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.4 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.3 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.2 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.1 lib/allure_rspec/suite_labels.rb
allure-rspec-2.24.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.23.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.22.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.21.2 lib/allure_rspec/suite_labels.rb
allure-rspec-2.21.1 lib/allure_rspec/suite_labels.rb
allure-rspec-2.21.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.20.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.19.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.18.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.17.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.16.2 lib/allure_rspec/suite_labels.rb
allure-rspec-2.16.1 lib/allure_rspec/suite_labels.rb
allure-rspec-2.16.0 lib/allure_rspec/suite_labels.rb
allure-rspec-2.15.0 lib/allure_rspec/suite_labels.rb