Class: CukeLinter::TestShouldUseBackgroundLinter

Inherits:
Linter
  • Object
show all
Defined in:
lib/cuke_linter/linters/test_should_use_background_linter.rb

Overview

A linter that detects scenarios and outlines within a feature that all share common beginning steps

Instance Attribute Summary

Attributes inherited from Linter

#name

Instance Method Summary collapse

Methods inherited from Linter

#initialize, #lint

Constructor Details

This class inherits a constructor from CukeLinter::Linter

Instance Method Details

#messageObject

The message used to describe the problem that has been found



24
25
26
# File 'lib/cuke_linter/linters/test_should_use_background_linter.rb', line 24

def message
  'Test shares steps with all other tests in feature. Use a background.'
end

#rule(model) ⇒ Object

The rule used to determine if a model has a problem



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cuke_linter/linters/test_should_use_background_linter.rb', line 9

def rule(model)
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)

  model_steps          = model.steps || []
  parent_feature_model = model.get_ancestor(:feature)

  return false unless parent_feature_model.tests.count > 1

  matching_steps     = all_first_steps_match?(parent_feature_model, model_steps)
  none_parameterized = no_parameterized_steps?(parent_feature_model)

  matching_steps && none_parameterized
end