Class: CukeSniffer::StepDefinition

Inherits:
RuleTarget show all
Defined in:
lib/cuke_sniffer/step_definition.rb

Overview

Author

Robert Cochran ([email protected])

Copyright

Copyright © 2013 Robert Cochran

License

Distributes under the MIT License

Translates and evaluates Cucumber step definitions Extends CukeSniffer::RulesEvaluator

Constant Summary

Constants included from RuleConfig

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

Constants included from Constants

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

Instance Attribute Summary collapse

Attributes inherited from RuleTarget

#location, #rules_hash, #score

Instance Method Summary collapse

Methods inherited from RuleTarget

#good?, #problem_percentage

Constructor Details

#initialize(location, step_definition_block) ⇒ StepDefinition

location must be in the format of “file_pathfile_name.rb:line_number” step_definition_block is an array of strings that represents the step definition must contain the regex line and its pairing end



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cuke_sniffer/step_definition.rb', line 46

def initialize(location, step_definition_block)
  @parameters = []
  @calls = {}
  @nested_steps = {}
  super(location)
  extract_start_line(location)
  extract_code(step_definition_block)
  extract_step_definition_signature(step_definition_block)

  detect_nested_steps
end

Instance Attribute Details

#callsObject

hash: Contains each call that is made to a step definition

  • Key: Location in which the step definition is called from

  • Value: The step string that matched the regex

In the case of a fuzzy match it will be a regex of the step call that was the inverse match of the regex translated into a string.



38
39
40
# File 'lib/cuke_sniffer/step_definition.rb', line 38

def calls
  @calls
end

#codeObject

string array: List of all of the content between the regex and the end of the step definition.



41
42
43
# File 'lib/cuke_sniffer/step_definition.rb', line 41

def code
  @code
end

#nested_stepsObject

hash: Contains each nested step call a step definition has

  • Key: location:line of the nested step

  • Value: The step call that appears on the line



30
31
32
# File 'lib/cuke_sniffer/step_definition.rb', line 30

def nested_steps
  @nested_steps
end

#parametersObject

string array: List of the parameters a step definition has



25
26
27
# File 'lib/cuke_sniffer/step_definition.rb', line 25

def parameters
  @parameters
end

#regexObject

Regex: Regex that cucumber uses to match step calls



22
23
24
# File 'lib/cuke_sniffer/step_definition.rb', line 22

def regex
  @regex
end

#start_lineObject

int: Line on which a step definition starts



19
20
21
# File 'lib/cuke_sniffer/step_definition.rb', line 19

def start_line
  @start_line
end

Instance Method Details

#==(comparison_object) ⇒ Object

:nodoc:



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

def ==(comparison_object) # :nodoc:
  comparison_object.regex == regex && comparison_object.parameters == parameters
end

#add_call(location, step_string) ⇒ Object

Adds new location => step_string pairs to the calls hash



59
60
61
# File 'lib/cuke_sniffer/step_definition.rb', line 59

def add_call(location, step_string)
  @calls[location] = step_string
end

#condensed_call_listObject



67
68
69
70
71
72
73
74
# File 'lib/cuke_sniffer/step_definition.rb', line 67

def condensed_call_list
  condensed_list = {}
  @calls.each do |call, step_string|
    condensed_list[step_string] ||= []
    condensed_list[step_string] << call
  end
  condensed_list
end