Class: GherkinLint::SameTagForAllScenarios

Inherits:
Linter
  • Object
show all
Defined in:
lib/gherkin_lint.rb

Overview

service class to lint for using same tag on all scenarios

Instance Attribute Summary

Attributes inherited from Linter

#issues

Instance Method Summary collapse

Methods inherited from Linter

#add_issue, #backgrounds, #features, #files, #filled_scenarios, #gather_tags, #initialize, #line, #lint_files, #name, #reference, #render_step, #scenarios, #steps

Constructor Details

This class inherits a constructor from GherkinLint::Linter

Instance Method Details

#gather_same_tags(feature) ⇒ Object



539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/gherkin_lint.rb', line 539

def gather_same_tags(feature)
  result = nil
  return result unless feature.include? 'elements'
  feature['elements'].each do |scenario|
    next if scenario['keyword'] == 'Background'
    return nil unless scenario.include? 'tags'
    tags = scenario['tags'].map { |tag| tag['name'] }
    result = tags if result.nil?
    result &= tags
  end
  result
end

#lintObject



526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/gherkin_lint.rb', line 526

def lint
  features do |file, feature|
    tags = gather_same_tags feature
    next if tags.nil?
    next if tags.length < 1
    next unless feature['elements'].length > 1
    references = [reference(file, feature)]
    tags.each do |tag|
      add_issue(references, "Tag '#{tag}' should be used at Feature level")
    end
  end
end