Sha256: dcd25dd14b298c6f68ac73f5854b8c29533ab17f5cc359148d1bf0fc4e853215

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require 'chutney/linter'

module Chutney
  # service class to lint for using same tag on all scenarios
  class SameTagForAllScenarios < Linter
    def lint
      lint_scenarios if feature&.scenarios
      lint_examples  if feature&.scenarios
    end

    def lint_scenarios
      tags = scenario_tags
      return if tags.nil? || tags.empty?
      return unless feature.tests.length > 1

      tags.each do |tag|
        next if tag == 'skip'

        add_issue(
          I18n.t('linters.same_tag_for_all_scenarios.feature_level',
                 tag: tag),
          feature
        )
      end
    end

    def lint_examples
      scenarios do |_feature, scenario|
        tags = example_tags(scenario)
        next if tags.nil? || tags.empty?
        next unless scenario.is_a? CukeModeler::Outline
        next unless scenario.examples.length > 1

        tags.each do |tag|
          next if tag == 'skip'

          add_issue(I18n.t('linters.same_tag_for_all_scenarios.example_level',
                           tag: tag), feature, scenario)
        end
      end
    end

    def scenario_tags
      result = nil
      scenarios do |_feature, scenario|
        tags = tags_for(scenario)
        result ||= tags
        result &= tags
      end
      result
    end

    def example_tags(scenario)
      result = nil
      return result unless scenario.is_a?(CukeModeler::Outline) && scenario.examples

      scenario.examples.each do |example|
        return nil unless example.tags

        tags = tags_for(example)
        result = tags if result.nil?

        result &= tags
      end
      result
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
chutney-3.7.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.6.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.5.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.3.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.2.1 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.2.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.1.1 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.1.0 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.0.1 lib/chutney/linter/same_tag_for_all_scenarios.rb
chutney-3.0.0 lib/chutney/linter/same_tag_for_all_scenarios.rb