Sha256: b9f5bf933d41e2caa91d8b52e27cdf721abf22f3b0336163d5faea9cf94377df
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 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? :children feature[:children].each do |scenario| next unless scenario[:type] == :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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gherkin_lint-0.4.2 | lib/gherkin_lint/linter/use_outline.rb |
gherkin_lint-0.4.1 | lib/gherkin_lint/linter/use_outline.rb |
gherkin_lint-0.4.0 | lib/gherkin_lint/linter/use_outline.rb |