Sha256: 7d3412067a892ebfebcea6a25360d485682ecf6e725a64bd444c7aed9b928614

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require 'chutney/linter'
require 'chutney/linter/tag_collector'

module Chutney
  # service class to lint for too many different tags
  class TooManyDifferentTags < Linter
    include TagCollector

    def lint
      overall_tags = []
      overall_references = []
      features do |file, feature|
        tags = tags_for_feature(feature)
        overall_tags += tags
        references = [reference(file, feature)]
        overall_references += references unless tags.empty?
        
        warn_single_feature(references, tags)
      end
      warn_across_all_features(overall_references, overall_tags)
    end

    def warn_single_feature(references, tags)
      tags.uniq!
      references.uniq!
      return false unless tags.length >= 3
      
      add_error(references, "Used #{tags.length} Tags within single Feature")
    end

    def warn_across_all_features(references, tags)
      tags.uniq!
      references.uniq!
      return false unless tags.length >= 10
      
      add_error(references, "Used #{tags.length} Tags across all Features")
    end

    def tags_for_feature(feature)
      return [] unless feature.include? :children
      
      gather_tags(feature) + feature[:children].map { |scenario| gather_tags(scenario) }.flatten
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chutney-1.6.3 lib/chutney/linter/too_many_different_tags.rb
chutney-1.6.2 lib/chutney/linter/too_many_different_tags.rb
chutney-1.6.1 lib/chutney/linter/too_many_different_tags.rb
chutney-1.6.0 lib/chutney/linter/too_many_different_tags.rb
chutney-0.5.0 lib/chutney/linter/too_many_different_tags.rb