Sha256: 809e70fecc9c2352b7319cbae6617efef69cc6198f288a7ba5b7681d2652e90e

Contents?: true

Size: 1.39 KB

Versions: 6

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_issue(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

6 entries across 6 versions & 1 rubygems

Version Path
gherkin_lint-0.1.2 lib/gherkin_lint/linter/use_outline.rb
gherkin_lint-0.1.1 lib/gherkin_lint/linter/use_outline.rb
gherkin_lint-0.1.0 lib/gherkin_lint/linter/use_outline.rb
gherkin_lint-0.0.14 lib/gherkin_lint/linter/use_outline.rb
gherkin_lint-0.0.13 lib/gherkin_lint/linter/use_outline.rb
gherkin_lint-0.0.12 lib/gherkin_lint/linter/use_outline.rb