Class: Chutney::UseBackground
- Inherits:
-
Linter
- Object
- Linter
- Chutney::UseBackground
show all
- Defined in:
- lib/chutney/linter/use_background.rb
Overview
service class to lint for using background
Instance Attribute Summary
Attributes inherited from Linter
#configuration, #filename, #issues
Instance Method Summary
collapse
Methods inherited from Linter
#add_issue, #and_word?, #background, #background_word?, #but_word?, descendants, #dialect, #dialect_word, #elements, #examples_word?, #feature, #feature_word?, #filled_scenarios, #given_word?, #initialize, linter_name, #linter_name, #location, #off_switch?, #render_step, #render_step_argument, #scenario_outline_word?, #scenarios, #steps, #tags_for, #then_word?, #type, #when_word?
Instance Method Details
#expand_examples(examples, prototypes) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/chutney/linter/use_background.rb', line 43
def expand_examples(examples, prototypes)
examples.each do |example|
prototypes = prototypes.map { |prototype| expand_outlines(prototype, example) }.flatten
end
prototypes
end
|
#expand_outlines(sentence, example) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/chutney/linter/use_background.rb', line 50
def expand_outlines(sentence, example)
result = []
= example.rows.first.cells.map(&:value)
example.rows.each_with_index do |row, idx|
next if idx.zero?
modified_sentence = sentence.dup
.zip(row.cells.map(&:value)).map do |key, value|
modified_sentence.gsub!("<#{key}>", value)
end
result.push modified_sentence
end
result
end
|
#expanded_steps(&block) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/chutney/linter/use_background.rb', line 33
def expanded_steps(&block)
scenarios do |_feature, scenario|
next unless scenario.steps
prototypes = [render_step(scenario.steps.first)]
prototypes = expand_examples(scenario.examples, prototypes) if scenario.is_a? CukeModeler::Outline
prototypes.each(&block)
end
end
|
#gather_givens ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/chutney/linter/use_background.rb', line 17
def gather_givens
return unless feature.children
has_non_given_step = false
scenarios do |_feature, scenario|
next unless scenario.steps
has_non_given_step = true unless given_word?(scenario.steps.first.keyword)
end
return if has_non_given_step
result = []
expanded_steps { |given| result.push given }
result
end
|
#lint ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/chutney/linter/use_background.rb', line 6
def lint
return unless filled_scenarios.count > 1
givens = gather_givens
return if givens.nil?
return if givens.length <= 1
return if givens.uniq.length > 1
add_issue(I18n.t('linters.use_background', step: givens.uniq.first), feature)
end
|