Class: CukeSniffer::CLI

Inherits:
Object
  • Object
show all
Includes:
Constants, RuleConfig, ROXML
Defined in:
lib/cuke_sniffer/cli.rb

Overview

Author

Robert Cochran ([email protected])

Copyright

Copyright © 2013 Robert Cochran

License

Distributes under the MIT License

Mixins: CukeSniffer::Constants, ROXML

Constant Summary

Constants included from RuleConfig

RuleConfig::ERROR, RuleConfig::FATAL, RuleConfig::INFO, RuleConfig::RULES, RuleConfig::WARNING

Constants included from Constants

CukeSniffer::Constants::COMMENT_REGEX, CukeSniffer::Constants::DATE_REGEX, CukeSniffer::Constants::DEFAULT_OUTPUT_FILE_NAME, CukeSniffer::Constants::FILE_IGNORE_LIST, CukeSniffer::Constants::HOOK_REGEX, CukeSniffer::Constants::HOOK_STYLES, CukeSniffer::Constants::MARKUP_SOURCE, CukeSniffer::Constants::SCENARIO_TITLE_STYLES, CukeSniffer::Constants::STEP_DEFINITION_REGEX, CukeSniffer::Constants::STEP_REGEX, CukeSniffer::Constants::STEP_STYLES, CukeSniffer::Constants::TAG_REGEX, CukeSniffer::Constants::THRESHOLDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ CLI

Does analysis against the passed features and step definition locations

Can be called in several ways.

No argument(assumes current directory is the project)

cuke_sniffer = CukeSniffer::CLI.new

Against single files

cuke_sniffer = CukeSniffer::CLI.new({:features_location =>"my_feature.feature"})

Or

cuke_sniffer = CukeSniffer::CLI.new({:step_definitions_location =>"my_steps.rb"})

Or

cuke_sniffer = CukeSniffer::CLI.new({:hooks_location =>"my_hooks.rb"})

Against folders

cuke_sniffer = CukeSniffer::CLI.new({:features_location =>"my_features_directory\", :step_definitions_location =>"my_steps_directory\"})

Disabling cataloging for improved runtime and no dead steps identified

cuke_sniffer = CukeSniffer::CLI.new({:no_catalog => true})

You can mix and match all of the above examples

Displays the sequence and a . indicator for each new loop in that process. Handles creation of all Feature and StepDefinition objects Then catalogs all step definition calls to be used for rules and identification of dead steps.



89
90
91
92
93
94
# File 'lib/cuke_sniffer/cli.rb', line 89

def initialize(parameters = {})
  initialize_rule_targets(parameters)
  evaluate_rules
  catalog_step_calls if @cataloged
  assess_score
end

Instance Attribute Details

#catalogedObject

Boolean: Status of if the projects step definitions were cataloged for calls



58
59
60
# File 'lib/cuke_sniffer/cli.rb', line 58

def cataloged
  @cataloged
end

#featuresObject

Feature array: All Features gathered from the specified folder



29
30
31
# File 'lib/cuke_sniffer/cli.rb', line 29

def features
  @features
end

#features_locationObject

string: Location of the feature file or root folder that was searched in



40
41
42
# File 'lib/cuke_sniffer/cli.rb', line 40

def features_location
  @features_location
end

#hooksObject

Hook array: All Hooks found in the current directory



52
53
54
# File 'lib/cuke_sniffer/cli.rb', line 52

def hooks
  @hooks
end

#hooks_locationObject

string: Location of the hook file or root folder that was searched in



46
47
48
# File 'lib/cuke_sniffer/cli.rb', line 46

def hooks_location
  @hooks_location
end

#rulesObject

Rules hash: All the rules that exist at runtime and their corresponding data



55
56
57
# File 'lib/cuke_sniffer/cli.rb', line 55

def rules
  @rules
end

#scenariosObject

Scenario array: All Scenarios found in the features from the specified folder



49
50
51
# File 'lib/cuke_sniffer/cli.rb', line 49

def scenarios
  @scenarios
end

#step_definitionsObject

StepDefinition Array: All StepDefinitions objects gathered from the specified folder



32
33
34
# File 'lib/cuke_sniffer/cli.rb', line 32

def step_definitions
  @step_definitions
end

#step_definitions_locationObject

string: Location of the step definition file or root folder that was searched in



43
44
45
# File 'lib/cuke_sniffer/cli.rb', line 43

def step_definitions_location
  @step_definitions_location
end

#summaryObject

Hash: Summary objects and improvement lists

  • Key: symbol, :total_score, :features, :step_definitions, :improvement_list

  • Value: hash or array



37
38
39
# File 'lib/cuke_sniffer/cli.rb', line 37

def summary
  @summary
end

Instance Method Details

#assess_scoreObject



165
166
167
168
169
170
171
172
173
174
# File 'lib/cuke_sniffer/cli.rb', line 165

def assess_score
  puts "\nAssessing Score: "
  initialize_summary
  summarize(:features, @features, "Feature")
  summarize(:scenarios, @scenarios, "Scenario")
  summarize(:step_definitions, @step_definitions, "StepDefinition")
  summarize(:hooks, @hooks, "Hook")
  @summary[:improvement_list] = CukeSniffer::SummaryHelper.sort_improvement_list(@summary[:improvement_list])
  @improvement_list = @summary[:improvement_list]
end

#catalog_step_callsObject

Determines all normal and nested step calls and assigns them to the corresponding step definition. Does direct and fuzzy matching



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cuke_sniffer/cli.rb', line 151

def catalog_step_calls
  puts "\nCataloging Step Calls: "
  steps = CukeSniffer::CukeSnifferHelper.get_all_steps(@features, @step_definitions)
  @step_definitions.each do |step_definition|
    print '.'
    calls = steps.find_all { |location, step| step.gsub(STEP_STYLES, "") =~ step_definition.regex }
    calls.each { |call| step_definition.add_call(call[0], call[1].gsub(STEP_STYLES, "")) }
  end

  steps_with_expressions = CukeSniffer::CukeSnifferHelper.get_steps_with_expressions(steps)
  converted_steps = CukeSniffer::CukeSnifferHelper.convert_steps_with_expressions(steps_with_expressions)
  CukeSniffer::CukeSnifferHelper.catalog_possible_dead_steps(@step_definitions, converted_steps)
end

#cataloged?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/cuke_sniffer/cli.rb', line 176

def cataloged?
  @cataloged
end

#get_dead_stepsObject

Gathers all StepDefinitions that have no calls Returns a hash that has two different types of records 1: String of the file with a dead step with an array of the line and regex of each dead step 2: Symbol of :total with an integer that is the total number of dead steps



145
146
147
# File 'lib/cuke_sniffer/cli.rb', line 145

def get_dead_steps
  CukeSniffer::DeadStepsHelper::build_dead_steps_hash(@step_definitions)
end

#good?Boolean

Returns the status of the overall project based on a comparison of the score to the threshold score

Returns:

  • (Boolean)


97
98
99
# File 'lib/cuke_sniffer/cli.rb', line 97

def good?
  @summary[:total_score] <= Constants::THRESHOLDS["Project"]
end

#output_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html") ⇒ Object

Creates a html file with the collected project details file_name defaults to “cuke_sniffer_results.html” unless specified Second parameter used for passing into the markup.

cuke_sniffer.output_html

Or

cuke_sniffer.output_html("results01-01-0001.html")


118
119
120
# File 'lib/cuke_sniffer/cli.rb', line 118

def output_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html")
  CukeSniffer::Formatter.output_html(self, file_name)
end

#output_min_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html") ⇒ Object

Creates a html file with minimum information: Summary, Rules, Improvement List. file_name defaults to “cuke_sniffer_results.html” unless specified Second parameter used for passing into the markup.

cuke_sniffer.output_min_html

Or

cuke_sniffer.output_min_html("results01-01-0001.html")


128
129
130
# File 'lib/cuke_sniffer/cli.rb', line 128

def output_min_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html")
  CukeSniffer::Formatter.output_min_html(self, file_name)
end

#output_resultsObject

Prints out a summary of the results and the list of improvements to be made



108
109
110
# File 'lib/cuke_sniffer/cli.rb', line 108

def output_results
  CukeSniffer::Formatter.output_console(self)
end

#output_xml(file_name = DEFAULT_OUTPUT_FILE_NAME + ".xml") ⇒ Object

Creates a xml file with the collected project details file_name defaults to “cuke_sniffer.xml” unless specified

cuke_sniffer.output_xml

Or

cuke_sniffer.output_xml("cuke_sniffer01-01-0001.xml")


137
138
139
# File 'lib/cuke_sniffer/cli.rb', line 137

def output_xml(file_name = DEFAULT_OUTPUT_FILE_NAME + ".xml")
  CukeSniffer::Formatter.output_xml(self, file_name)
end

#problem_percentageObject

Calculates the score to threshold percentage of an object Return: Float



103
104
105
# File 'lib/cuke_sniffer/cli.rb', line 103

def problem_percentage
  @summary[:total_score].to_f / Constants::THRESHOLDS["Project"].to_f
end