Class: GherkinLint::UseOutline
- Inherits:
-
Linter
- Object
- Linter
- GherkinLint::UseOutline
show all
- Defined in:
- lib/gherkin_lint/linter/use_outline.rb
Overview
service class to lint for using outline
Instance Attribute Summary
Attributes inherited from Linter
#issues
Instance Method Summary
collapse
Methods inherited from Linter
#add_error, #add_warning, #backgrounds, descendants, #elements, #features, #files, #filled_scenarios, #filter_tag, #initialize, #line, #lint_files, #name, #reference, #render_step, #render_step_argument, #scenarios, #steps, #suppress, #suppress_tags, #tag?
Instance Method Details
#check_similarity(scenarios) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/gherkin_lint/linter/use_outline.rb', line 13
def check_similarity(scenarios)
scenarios.product(scenarios) do |lhs, rhs|
next if lhs == rhs
next if lhs[:reference] > rhs[:reference]
similarity = determine_similarity(lhs[:text], rhs[:text])
next unless similarity >= 0.95
references = [lhs[:reference], rhs[:reference]]
add_error(references, "Scenarios are similar by #{similarity.round(3) * 100} %")
end
end
|
#determine_similarity(lhs, rhs) ⇒ Object
24
25
26
27
|
# File 'lib/gherkin_lint/linter/use_outline.rb', line 24
def determine_similarity(lhs, rhs)
matcher = Amatch::Jaro.new lhs
matcher.match rhs
end
|
#gather_scenarios(file, feature) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/gherkin_lint/linter/use_outline.rb', line 29
def gather_scenarios(file, feature)
scenarios = []
return scenarios unless feature.include? :children
feature[:children].each do |scenario|
next unless scenario[:type] == :Scenario
next unless scenario.include? :steps
next if scenario[:steps].empty?
scenarios.push generate_reference(file, feature, scenario)
end
scenarios
end
|
#generate_reference(file, feature, scenario) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/gherkin_lint/linter/use_outline.rb', line 41
def generate_reference(file, feature, scenario)
reference = {}
reference[:reference] = reference(file, feature, scenario)
reference[:text] = scenario[:steps].map { |step| render_step(step) }.join ' '
reference
end
|
#lint ⇒ Object
7
8
9
10
11
|
# File 'lib/gherkin_lint/linter/use_outline.rb', line 7
def lint
features do |file, feature|
check_similarity gather_scenarios(file, feature)
end
end
|