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 © 2014 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.



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

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



69
70
71
# File 'lib/cuke_sniffer/cli.rb', line 69

def cataloged
  @cataloged
end

#featuresObject

Feature array: All Features gathered from the specified folder



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

def features
  @features
end

#features_locationObject

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



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

def features_location
  @features_location
end

#hooksObject

Hook array: All Hooks found in the current directory



63
64
65
# File 'lib/cuke_sniffer/cli.rb', line 63

def hooks
  @hooks
end

#hooks_locationObject

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



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

def hooks_location
  @hooks_location
end

#rulesObject

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



66
67
68
# File 'lib/cuke_sniffer/cli.rb', line 66

def rules
  @rules
end

#scenariosObject

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



60
61
62
# File 'lib/cuke_sniffer/cli.rb', line 60

def scenarios
  @scenarios
end

#step_definitionsObject

StepDefinition Array: All StepDefinitions objects gathered from the specified folder



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

def step_definitions
  @step_definitions
end

#step_definitions_locationObject

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



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

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



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

def summary
  @summary
end

Instance Method Details

#assess_scoreObject



186
187
188
189
190
191
192
193
194
195
# File 'lib/cuke_sniffer/cli.rb', line 186

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



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/cuke_sniffer/cli.rb', line 171

def catalog_step_calls
  puts "\nCataloging Step Calls: "
  steps = CukeSniffer::CukeSnifferHelper.get_all_steps(@features, @step_definitions)
  steps_map = build_steps_map(steps)
  @step_definitions.each do |step_definition|
    print '.'
    calls = steps_map.find_all {|step, location| step =~ step_definition.regex }
    step_definition.calls = build_stored_calls_map(calls)
  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)


197
198
199
# File 'lib/cuke_sniffer/cli.rb', line 197

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



165
166
167
# File 'lib/cuke_sniffer/cli.rb', line 165

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)


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

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")


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

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

#output_junit_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")


157
158
159
# File 'lib/cuke_sniffer/cli.rb', line 157

def output_junit_xml(file_name = DEFAULT_OUTPUT_FILE_NAME + ".xml")
  CukeSniffer::Formatter.output_junit_xml(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")


139
140
141
# File 'lib/cuke_sniffer/cli.rb', line 139

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



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

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")


148
149
150
# File 'lib/cuke_sniffer/cli.rb', line 148

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



114
115
116
# File 'lib/cuke_sniffer/cli.rb', line 114

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