Class: CukeSniffer::Hook
- Inherits:
-
RuleTarget
- Object
- RuleTarget
- CukeSniffer::Hook
- Defined in:
- lib/cuke_sniffer/hook.rb
Overview
- Author
-
Robert Cochran ([email protected])
- Copyright
-
Copyright © 2014 Robert Cochran
- License
-
Distributes under the MIT License
Cucumber Hook class used for evaluating rules 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
-
#code ⇒ Object
Array of strings that contain the code kept in the hook.
-
#parameters ⇒ Object
The parameters that are declared on the hook.
-
#start_line ⇒ Object
Integer of the line in which the hook was found.
-
#tags ⇒ Object
The list of tags used as a filter for the hook.
-
#type ⇒ Object
The type of the hook: AfterConfiguration, After, AfterStep, Around, Before, at_exit.
Attributes inherited from RuleTarget
#location, #rules_hash, #score
Instance Method Summary collapse
-
#==(comparison_object) ⇒ Object
:nodoc:.
- #around? ⇒ Boolean
- #calls_block? ⇒ Boolean
- #conflicting_tags? ⇒ Boolean
-
#initialize(location, hook_block) ⇒ Hook
constructor
location must be in the format of “file_pathfile_name.rb:line_number” raw_code is an array of strings that represents the step definition must contain the hook declaration line and the pairing end.
- #rescues? ⇒ Boolean
Methods inherited from RuleTarget
#good?, #is_comment?, #problem_percentage, #store_rule, #store_rule_many_times
Constructor Details
#initialize(location, hook_block) ⇒ Hook
location must be in the format of “file_pathfile_name.rb:line_number” raw_code is an array of strings that represents the step definition must contain the hook declaration line and the pairing end
34 35 36 37 38 39 40 |
# File 'lib/cuke_sniffer/hook.rb', line 34 def initialize(location, hook_block) super(location) @start_line = location.match(/:(?<line>\d*)$/)[:line].to_i end_match_index = (hook_block.size - 1) - hook_block.reverse.index("end") @code = hook_block[1...end_match_index] initialize_hook_signature(hook_block) end |
Instance Attribute Details
#code ⇒ Object
Array of strings that contain the code kept in the hook
28 29 30 |
# File 'lib/cuke_sniffer/hook.rb', line 28 def code @code end |
#parameters ⇒ Object
The parameters that are declared on the hook
22 23 24 |
# File 'lib/cuke_sniffer/hook.rb', line 22 def parameters @parameters end |
#start_line ⇒ Object
Integer of the line in which the hook was found
25 26 27 |
# File 'lib/cuke_sniffer/hook.rb', line 25 def start_line @start_line end |
#tags ⇒ Object
The list of tags used as a filter for the hook
19 20 21 |
# File 'lib/cuke_sniffer/hook.rb', line 19 def @tags end |
#type ⇒ Object
The type of the hook: AfterConfiguration, After, AfterStep, Around, Before, at_exit
16 17 18 |
# File 'lib/cuke_sniffer/hook.rb', line 16 def type @type end |
Instance Method Details
#==(comparison_object) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 |
# File 'lib/cuke_sniffer/hook.rb', line 42 def ==(comparison_object) # :nodoc: super(comparison_object) && comparison_object.type == type && comparison_object. == && comparison_object.parameters == parameters && comparison_object.code == code end |
#around? ⇒ Boolean
50 51 52 |
# File 'lib/cuke_sniffer/hook.rb', line 50 def around? type == 'Around' end |
#calls_block? ⇒ Boolean
54 55 56 |
# File 'lib/cuke_sniffer/hook.rb', line 54 def calls_block? @code.join.to_s.include?("#{@parameters[1]}.call") end |
#conflicting_tags? ⇒ Boolean
58 59 60 61 62 63 64 65 |
# File 'lib/cuke_sniffer/hook.rb', line 58 def = .each do |single_tag| tag = single_tag.gsub("~", "") return true if .include?(tag) and .include?("~#{tag}") end false end |
#rescues? ⇒ Boolean
67 68 69 |
# File 'lib/cuke_sniffer/hook.rb', line 67 def rescues? @code.empty? or @code.join.to_s =~ /.*begin.*rescue.*/ end |