Class: Chutney::UseOutline

Inherits:
Linter
  • Object
show all
Defined in:
lib/chutney/linter/use_outline.rb

Overview

service class to lint for using outline

Instance Attribute Summary

Attributes inherited from Linter

#configuration, #filename, #issues

Instance Method Summary collapse

Methods inherited from Linter

#and_word?, #background, #background_word?, #but_word?, descendants, #dialect, #dialect_word, #elements, #examples_word?, #feature, #feature_word?, #filled_scenarios, #given_word?, #initialize, #linter_name, linter_name, #location, #off_switch?, #render_step, #render_step_argument, #scenario_outline_word?, #scenarios, #steps, #tags_for, #then_word?, #type, #when_word?

Constructor Details

This class inherits a constructor from Chutney::Linter

Instance Method Details

#add_issue(lhs, rhs, pct) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/chutney/linter/use_outline.rb', line 24

def add_issue(lhs, rhs, pct)
  super(I18n.t('linters.use_outline',
               pct:,
               lhs_name: lhs[:name],
               lhs_line: lhs[:reference][:line],
               rhs_name: rhs[:name],
               rhs_line: rhs[:reference][:line]),
              feature)
end

#check_similarity(scenarios) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chutney/linter/use_outline.rb', line 10

def check_similarity(scenarios)
  scenarios.product(scenarios) do |lhs, rhs|
    next if lhs == rhs
    next if lhs[:reference][:line] > rhs[:reference][:line]

    similarity = determine_similarity(lhs[:text], rhs[:text])
    next unless similarity >= 0.95

    similarity_pct = similarity.round(3) * 100

    add_issue(lhs, rhs, similarity_pct)
  end
end

#determine_similarity(lhs, rhs) ⇒ Object



34
35
36
37
# File 'lib/chutney/linter/use_outline.rb', line 34

def determine_similarity(lhs, rhs)
  matcher = Amatch::Jaro.new(lhs)
  matcher.match(rhs)
end

#gather_scenarios(feature) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chutney/linter/use_outline.rb', line 39

def gather_scenarios(feature)
  scenarios = []
  return scenarios if feature.nil? || !feature.tests

  scenarios do |_feature, scenario|
    next unless scenario.steps
    next if scenario.steps.empty?

    scenarios.push generate_reference(feature, scenario)
  end
  scenarios
end

#generate_reference(feature, scenario) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/chutney/linter/use_outline.rb', line 52

def generate_reference(feature, scenario)
  reference = {}
  reference[:reference] = location(feature, scenario, nil)
  reference[:name] = "#{scenario.keyword}: #{scenario.name}"
  reference[:text] = scenario.steps.map { |step| render_step(step) }.join ' '
  reference
end

#lintObject



6
7
8
# File 'lib/chutney/linter/use_outline.rb', line 6

def lint
  check_similarity(gather_scenarios(feature))
end