Class: GherkinLint::InvalidStepFlow
- Inherits:
-
Linter
- Object
- Linter
- GherkinLint::InvalidStepFlow
show all
- Defined in:
- lib/gherkin_lint/linter/invalid_step_flow.rb
Overview
service class to lint for invalid step flow
Instance Attribute Summary
Attributes inherited from Linter
#issues
Instance Method Summary
collapse
Methods inherited from Linter
#add_error, #add_warning, #backgrounds, descendants, #elements, #features, #files, #filled_scenarios, #filter_tag, #initialize, #line, #lint_files, #name, #reference, #render_step, #render_step_argument, #scenarios, #steps, #suppress, #suppress_tags, #tag?
Instance Method Details
#given_after_non_given(file, feature, scenario, steps) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/gherkin_lint/linter/invalid_step_flow.rb', line 21
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_error(references, description) if step[:keyword] == 'Given ' && last_step[:keyword] != 'Given '
last_step = step
end
end
|
#last_step_is_an_action(file, feature, scenario, steps) ⇒ Object
16
17
18
19
|
# File 'lib/gherkin_lint/linter/invalid_step_flow.rb', line 16
def last_step_is_an_action(file, feature, scenario, steps)
references = [reference(file, feature, scenario, steps.last)]
add_error(references, 'Last step is an action') if steps.last[:keyword] == 'When '
end
|
#lint ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/gherkin_lint/linter/invalid_step_flow.rb', line 6
def lint
filled_scenarios do |file, feature, scenario|
steps = scenario[:steps].select { |step| step[:keyword] != 'And ' && step[:keyword] != 'But ' }
next if steps.empty?
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
|
#verification_before_action(file, feature, scenario, steps) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/gherkin_lint/linter/invalid_step_flow.rb', line 31
def verification_before_action(file, feature, scenario, steps)
steps.each do |step|
break if step[:keyword] == 'When '
references = [reference(file, feature, scenario, step)]
add_error(references, 'Missing Action') if step[:keyword] == 'Then '
end
end
|