Class: Spinach::Auditor

Inherits:
Runner
  • Object
show all
Defined in:
lib/spinach/auditor.rb

Overview

The auditor audits steps and determines if any are missing or obsolete.

It is a subclass of Runner because it uses many of the Runner’s features when auditing.

Instance Attribute Summary collapse

Attributes inherited from Runner

#filenames, #step_definitions_path, #support_path

Instance Method Summary collapse

Methods inherited from Runner

#default_reporter_options, #init_reporters, #orderer, #require_dependencies, #require_frameworks, #required_files, #step_definition_files, #support_files

Constructor Details

#initialize(filenames) ⇒ Auditor

Returns a new instance of Auditor.



12
13
14
15
16
# File 'lib/spinach/auditor.rb', line 12

def initialize(filenames)
  super(filenames)
  @unused_steps = {}
  @used_steps = Set.new
end

Instance Attribute Details

#unused_stepsObject

Returns the value of attribute unused_steps.



10
11
12
# File 'lib/spinach/auditor.rb', line 10

def unused_steps
  @unused_steps
end

#used_stepsObject

Returns the value of attribute used_steps.



10
11
12
# File 'lib/spinach/auditor.rb', line 10

def used_steps
  @used_steps
end

Instance Method Details

#runObject

audits features



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spinach/auditor.rb', line 21

def run
  require_dependencies

  # Find any missing steps in each file, and keep track of unused steps
  clean = true
  filenames.each do |file|
    result = audit_file(file)
    clean &&= result # set to false if any result is false
  end

  # At the end, report any unused steps
  report_unused_steps

  # If the audit was clean, make sure the user knows
  puts "\nAudit clean - no missing steps.".colorize(:light_green) if clean

  true
end