Module: GherkinLint::TagConstraint

Included in:
RequiredTagsStartsWith
Defined in:
lib/gherkin_lint/linter/tag_constraint.rb

Overview

Mixin to lint for tags that have certain string contraints

Instance Method Summary collapse

Instance Method Details

#lintObject



4
5
6
7
8
9
10
11
# File 'lib/gherkin_lint/linter/tag_constraint.rb', line 4

def lint
  scenarios do |file, feature, scenario|
    next if match_pattern? tags(feature)
    next if match_pattern? tags(scenario)
    references = [reference(file, feature, scenario)]
    add_error(references, 'Required Tag not found')
  end
end

#match_pattern?(_tags) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


23
24
25
# File 'lib/gherkin_lint/linter/tag_constraint.rb', line 23

def match_pattern?(_tags)
  raise NoMethodError, 'This is an abstraction that must be implemented by the includer'
end

#matcher(pattern) ⇒ Object



18
19
20
21
# File 'lib/gherkin_lint/linter/tag_constraint.rb', line 18

def matcher(pattern)
  @pattern = pattern
  validate_input
end

#tags(element) ⇒ Object



13
14
15
16
# File 'lib/gherkin_lint/linter/tag_constraint.rb', line 13

def tags(element)
  return [] unless element.include? :tags
  element[:tags].map { |a| a[:name] }
end

#validate_inputObject



27
28
29
30
# File 'lib/gherkin_lint/linter/tag_constraint.rb', line 27

def validate_input
  raise 'No Tags provided in the YAML' if @pattern.nil?
  warn 'Required Tags matcher has no value' if @pattern.empty?
end