Class: CukeSniffer::Scenario

Inherits:
FeatureRuleTarget show all
Defined in:
lib/cuke_sniffer/scenario.rb

Overview

Author

Robert Cochran ([email protected])

Copyright

Copyright © 2014 Robert Cochran

License

Distributes under the MIT License

This class is a representation of the cucumber objects Background, Scenario, Scenario Outline

Extends CukeSniffer::FeatureRulesEvaluator

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 FeatureRuleTarget

#name, #tags

Attributes inherited from RuleTarget

#location, #rules_hash, #score

Instance Method Summary collapse

Methods inherited from FeatureRuleTarget

#is_comment_and_tag?

Methods inherited from RuleTarget

#good?, #is_comment?, #problem_percentage, #store_rule, #store_rule_many_times

Constructor Details

#initialize(location, scenario) ⇒ Scenario

Location must be in the format of “file_pathfile_name.rb:line_number” Scenario must be a string array containing everything from the first tag to the last example table where applicable.



37
38
39
40
41
42
43
44
# File 'lib/cuke_sniffer/scenario.rb', line 37

def initialize(location, scenario)
  super(location)
  @start_line = location.match(/:(?<line>\d*)$/)[:line].to_i
  @steps = []
  @inline_tables = {}
  @examples_table = []
  split_scenario(scenario)
end

Instance Attribute Details

#examples_tableObject

string array: List of each example row in a scenario outline



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

def examples_table
  @examples_table
end

#inline_tablesObject

hash: Keeps each location and content of an inline table

  • Key: Step string the inline table is attached to

  • Value: Array of all of the lines in the table



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

def inline_tables
  @inline_tables
end

#start_lineObject

int: Line on which the scenario begins



17
18
19
# File 'lib/cuke_sniffer/scenario.rb', line 17

def start_line
  @start_line
end

#stepsObject

string array: List of each step call in a scenario



24
25
26
# File 'lib/cuke_sniffer/scenario.rb', line 24

def steps
  @steps
end

#typeObject

string: The type of scenario Background, Scenario, Scenario Outline



21
22
23
# File 'lib/cuke_sniffer/scenario.rb', line 21

def type
  @type
end

Instance Method Details

#==(comparison_object) ⇒ Object

:nodoc:



46
47
48
49
50
# File 'lib/cuke_sniffer/scenario.rb', line 46

def ==(comparison_object) # :nodoc:
  super(comparison_object) &&
      comparison_object.steps == steps &&
      comparison_object.examples_table == examples_table
end

#commented_examplesObject



66
67
68
69
70
# File 'lib/cuke_sniffer/scenario.rb', line 66

def commented_examples
  @examples_table.select do |example|
    is_comment?(example)
  end
end

#get_step_orderObject



52
53
54
55
56
57
58
59
60
# File 'lib/cuke_sniffer/scenario.rb', line 52

def get_step_order
  order = []
  @steps.each do |line|
    next if is_comment?(line)
    match = line.match(STEP_REGEX)
    order << match[:style] unless match.nil?
  end
  order
end

#get_steps(step_start) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/cuke_sniffer/scenario.rb', line 72

def get_steps(step_start)
  if step_start != "*"
    regex = /^\s*#{step_start}/
  else
    regex = /^\s*[*]/
  end
  @steps.select do |step|
    step =~ regex
  end
end

#outline?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/cuke_sniffer/scenario.rb', line 62

def outline?
  type === 'Scenario Outline'
end