Class: GherkinLint::UnknownVariable
- Inherits:
-
Linter
- Object
- Linter
- GherkinLint::UnknownVariable
show all
- Defined in:
- lib/gherkin_lint/linter/unknown_variable.rb
Overview
service class to lint for unknown variables
Instance Attribute Summary
Attributes inherited from Linter
#issues
Instance Method Summary
collapse
Methods inherited from Linter
#add_error, #add_warning, #backgrounds, #elements, #features, #files, #filled_scenarios, #filter_tag, #gather_tags, #initialize, #line, #lint_files, #name, #reference, #render_step, #scenarios, #steps, #suppress, #suppress_tags, #tag?
Instance Method Details
#gather_vars(string) ⇒ Object
27
28
29
|
# File 'lib/gherkin_lint/linter/unknown_variable.rb', line 27
def gather_vars(string)
string.scan(/<.+?>/).map { |val| val[1..-2] }
end
|
#known_variables(scenario) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/gherkin_lint/linter/unknown_variable.rb', line 31
def known_variables(scenario)
(scenario['examples'] || []).map do |example|
next unless example.key? 'rows'
example['rows'].first['cells'].map(&:strip)
end.flatten
end
|
#lint ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/gherkin_lint/linter/unknown_variable.rb', line 6
def lint
filled_scenarios do |file, feature, scenario|
known_vars = Set.new known_variables scenario
scenario['steps'].each do |step|
step_vars(step).each do |used_var|
next if known_vars.include? used_var
references = [reference(file, feature, scenario)]
add_error(references, "'<#{used_var}>' is unknown")
end
end
end
end
|
#step_vars(step) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/gherkin_lint/linter/unknown_variable.rb', line 19
def step_vars(step)
vars = gather_vars step['name']
vars += gather_vars step['doc_string']['value'] if step.key? 'doc_string'
vars + (step['rows'] || []).map do |row|
row['cells'].map { |value| gather_vars value }.flatten
end.flatten
end
|