class Chutney::UnknownVariable
service class to lint for unknown variables
Public Instance Methods
gather_vars(string)
click to toggle source
# File lib/chutney/linter/unknown_variable.rb, line 36 def gather_vars(string) string.scan(/<.+?>/).map { |val| val[1..-2] } end
gather_vars_from_argument(argument)
click to toggle source
# File lib/chutney/linter/unknown_variable.rb, line 28 def gather_vars_from_argument(argument) return gather_vars argument.content if argument.is_a? CukeModeler::DocString argument.rows.map do |row| row.cells.map { |cell| gather_vars cell.value }.flatten end.flatten end
known_variables(scenario)
click to toggle source
# File lib/chutney/linter/unknown_variable.rb, line 40 def known_variables(scenario) return [] unless scenario.is_a? CukeModeler::Outline scenario.examples.map { |ex| ex.rows.first.cells.map(&:value) }.flatten end
lint()
click to toggle source
# File lib/chutney/linter/unknown_variable.rb, line 6 def lint filled_scenarios do |feature, scenario| known_vars = Set.new(known_variables(scenario)) scenario.steps.each do |step| step_vars(step).each do |used_var| next if known_vars.include? used_var add_issue( I18n.t('linters.unknown_variable', variable: used_var), feature, scenario ) end end end end
step_vars(step)
click to toggle source
# File lib/chutney/linter/unknown_variable.rb, line 21 def step_vars(step) vars = gather_vars step.text return vars unless step.block vars + gather_vars_from_argument(step.block) end