Sha256: 3b2a90a7db116bfca4264ad71a355675041a6b3f5430932c8422e7e4b29943ea
Contents?: true
Size: 1.41 KB
Versions: 6
Compression:
Stored size: 1.41 KB
Contents
require 'gherkin_lint/linter' module GherkinLint # service class to lint for invalid step flow class InvalidStepFlow < Linter def lint filled_scenarios do |file, feature, scenario| steps = scenario['steps'].select { |step| step['keyword'] != 'And ' && step['keyword'] != 'But ' } last_step_is_an_action(file, feature, scenario, steps) given_after_non_given(file, feature, scenario, steps) verification_before_action(file, feature, scenario, steps) end end def last_step_is_an_action(file, feature, scenario, steps) references = [reference(file, feature, scenario, steps.last)] add_issue(references, 'Last step is an action') if steps.last['keyword'] == 'When ' end def given_after_non_given(file, feature, scenario, steps) last_step = steps.first steps.each do |step| references = [reference(file, feature, scenario, step)] description = 'Given after Action or Verification' add_issue(references, description) if step['keyword'] == 'Given ' && last_step['keyword'] != 'Given ' last_step = step end end def verification_before_action(file, feature, scenario, steps) steps.each do |step| break if step['keyword'] == 'When ' references = [reference(file, feature, scenario, step)] add_issue(references, 'Missing Action') if step['keyword'] == 'Then ' end end end end
Version data entries
6 entries across 6 versions & 1 rubygems