Sha256: 771cbd7397d769eaf1b4e76d9917dafff68c9c91bb1d83299382c6c160a248c6
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
require 'amatch' require 'gherkin_lint/linter' module GherkinLint # service class to lint for using outline class UseOutline < Linter def lint features do |file, feature| check_similarity gather_scenarios(file, feature) end end 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 def determine_similarity(lhs, rhs) matcher = Amatch::Jaro.new lhs matcher.match rhs end def gather_scenarios(file, feature) scenarios = [] return scenarios unless feature.include? 'elements' feature['elements'].each do |scenario| next unless scenario['keyword'] == 'Scenario' next unless scenario.include? 'steps' scenarios.push generate_reference(file, feature, scenario) end scenarios end 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gherkin_lint-0.3.1 | lib/gherkin_lint/linter/use_outline.rb |
gherkin_lint-0.3.0 | lib/gherkin_lint/linter/use_outline.rb |