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 Method Summary collapse

Methods inherited from Linter

#initialize, #lint, #name

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



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

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



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

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

  parent_feature_model.tests.all? do |test|
    test_steps = test.steps || []
    test_steps.first == model_steps.first
  end
end