Class: CukeSniffer::CLI
- Inherits:
-
Object
- Object
- CukeSniffer::CLI
- 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
-
#features ⇒ Object
Feature array: All Features gathered from the specified folder.
-
#features_location ⇒ Object
string: Location of the feature file or root folder that was searched in.
-
#hooks ⇒ Object
Hook array: All Hooks found in the current directory.
-
#hooks_location ⇒ Object
string: Location of the hook file or root folder that was searched in.
-
#rules ⇒ Object
Rules hash: All the rules that exist at runtime and their corresponding data.
-
#scenarios ⇒ Object
Scenario array: All Scenarios found in the features from the specified folder.
-
#step_definitions ⇒ Object
StepDefinition Array: All StepDefinitions objects gathered from the specified folder.
-
#step_definitions_location ⇒ Object
string: Location of the step definition file or root folder that was searched in.
-
#summary ⇒ Object
Hash: Summary objects and improvement lists * Key: symbol, :total_score, :features, :step_definitions, :improvement_list * Value: hash or array.
Instance Method Summary collapse
-
#catalog_step_calls ⇒ Object
Determines all normal and nested step calls and assigns them to the corresponding step definition.
-
#get_dead_steps ⇒ Object
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.
-
#good? ⇒ Boolean
Returns the status of the overall project based on a comparison of the score to the threshold score.
-
#initialize(parameters = {}) ⇒ CLI
constructor
Does analysis against the passed features and step definition locations.
-
#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.
-
#output_min_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html") ⇒ Object
Creates a html file with minimum information: Summary, Rules, Improvement List.
-
#output_results ⇒ Object
Prints out a summary of the results and the list of improvements to be made.
-
#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”).
-
#problem_percentage ⇒ Object
Calculates the score to threshold percentage of an object Return: Float.
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\"})
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.
82 83 84 85 86 87 |
# File 'lib/cuke_sniffer/cli.rb', line 82 def initialize(parameters = {}) initialize_rule_targets(parameters) evaluate_rules catalog_step_calls assess_score end |
Instance Attribute Details
#features ⇒ Object
Feature array: All Features gathered from the specified folder
28 29 30 |
# File 'lib/cuke_sniffer/cli.rb', line 28 def features @features end |
#features_location ⇒ Object
string: Location of the feature file or root folder that was searched in
39 40 41 |
# File 'lib/cuke_sniffer/cli.rb', line 39 def features_location @features_location end |
#hooks ⇒ Object
Hook array: All Hooks found in the current directory
51 52 53 |
# File 'lib/cuke_sniffer/cli.rb', line 51 def hooks @hooks end |
#hooks_location ⇒ Object
string: Location of the hook file or root folder that was searched in
45 46 47 |
# File 'lib/cuke_sniffer/cli.rb', line 45 def hooks_location @hooks_location end |
#rules ⇒ Object
Rules hash: All the rules that exist at runtime and their corresponding data
54 55 56 |
# File 'lib/cuke_sniffer/cli.rb', line 54 def rules @rules end |
#scenarios ⇒ Object
Scenario array: All Scenarios found in the features from the specified folder
48 49 50 |
# File 'lib/cuke_sniffer/cli.rb', line 48 def scenarios @scenarios end |
#step_definitions ⇒ Object
StepDefinition Array: All StepDefinitions objects gathered from the specified folder
31 32 33 |
# File 'lib/cuke_sniffer/cli.rb', line 31 def step_definitions @step_definitions end |
#step_definitions_location ⇒ Object
string: Location of the step definition file or root folder that was searched in
42 43 44 |
# File 'lib/cuke_sniffer/cli.rb', line 42 def step_definitions_location @step_definitions_location end |
#summary ⇒ Object
Hash: Summary objects and improvement lists
-
Key: symbol, :total_score, :features, :step_definitions, :improvement_list
-
Value: hash or array
36 37 38 |
# File 'lib/cuke_sniffer/cli.rb', line 36 def summary @summary end |
Instance Method Details
#catalog_step_calls ⇒ Object
Determines all normal and nested step calls and assigns them to the corresponding step definition. Does direct and fuzzy matching
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cuke_sniffer/cli.rb', line 144 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 |
#get_dead_steps ⇒ Object
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
138 139 140 |
# File 'lib/cuke_sniffer/cli.rb', line 138 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
90 91 92 |
# File 'lib/cuke_sniffer/cli.rb', line 90 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")
111 112 113 |
# File 'lib/cuke_sniffer/cli.rb', line 111 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")
121 122 123 |
# File 'lib/cuke_sniffer/cli.rb', line 121 def output_min_html(file_name = DEFAULT_OUTPUT_FILE_NAME + ".html") CukeSniffer::Formatter.output_min_html(self, file_name) end |
#output_results ⇒ Object
Prints out a summary of the results and the list of improvements to be made
101 102 103 |
# File 'lib/cuke_sniffer/cli.rb', line 101 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")
130 131 132 |
# File 'lib/cuke_sniffer/cli.rb', line 130 def output_xml(file_name = DEFAULT_OUTPUT_FILE_NAME + ".xml") CukeSniffer::Formatter.output_xml(self, file_name) end |
#problem_percentage ⇒ Object
Calculates the score to threshold percentage of an object Return: Float
96 97 98 |
# File 'lib/cuke_sniffer/cli.rb', line 96 def problem_percentage @summary[:total_score].to_f / Constants::THRESHOLDS["Project"].to_f end |