Class: Greener::Checker::Style::FeatureName

Inherits:
Base
  • Object
show all
Defined in:
lib/greener/checker/style/feature_name.rb

Overview

Ensure .feature filename matches feature name in the Gherkin e.g. filename_of_feature.feature => “Feature: filename of feature”

Constant Summary collapse

MSG =
"feature title does not match file name"

Instance Attribute Summary

Attributes inherited from Base

#violations

Instance Method Summary collapse

Methods inherited from Base

#feature, #initialize, #log_violation, #message, #raw_line

Constructor Details

This class inherits a constructor from Greener::Checker::Base

Instance Method Details

#allow_punctuation?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/greener/checker/style/feature_name.rb', line 38

def allow_punctuation?
  @config["AllowPunctuation"]
end

#enforce_title_case?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/greener/checker/style/feature_name.rb', line 42

def enforce_title_case?
  @config["EnforceTitleCase"]
end

#runObject



12
13
14
15
16
17
# File 'lib/greener/checker/style/feature_name.rb', line 12

def run
  return unless @config["Enabled"]

  run_against_filename
  run_against_titlecase
end

#run_against_filenameObject



19
20
21
22
23
24
25
26
# File 'lib/greener/checker/style/feature_name.rb', line 19

def run_against_filename
  filename_without_extension = File.basename(@path, ".*")
  expected = feature[:name]
  expected = expected.gsub(/[^0-9a-z ]/i, "") if allow_punctuation?
  expected = expected.downcase.gsub(" ", "_")
  return if filename_without_extension == expected
  log_violation(feature[:location][:line], feature[:location][:column])
end

#run_against_titlecaseObject



28
29
30
31
32
33
34
35
36
# File 'lib/greener/checker/style/feature_name.rb', line 28

def run_against_titlecase
  return unless enforce_title_case?
  return if feature[:name].titlecase == feature[:name]
  log_violation(
    feature[:location][:line],
    feature[:location][:column],
    "feature title is not title case. expected: #{feature[:name].titlecase}"
  )
end