module CucumberAnalytics::World

A module providing suite level analysis functionality.

Constants

REGEX_PATTERN_STRING

A pattern that matches a 'clean' regular expression

SANITARY_STRING

A placeholder string used to mark 'dirty' portions of input strings

STEP_DEF_KEYWORD_PATTERN

A pattern that matches a Cucumber step keyword

STEP_DEF_LINE_PATTERN

A pattern that matches a step definition declaration line

STEP_DEF_PATTERN_CAPTURE_PATTERN

A pattern that captures the regular expression portion of a step definition declaration line

Public Class Methods

clear_step_patterns() click to toggle source

Clears the step patterns that have been loaded into the World.

# File lib/cucumber_analytics/world.rb, line 79
def clear_step_patterns
  @defined_expressions = []
end
defined_steps_in(container) click to toggle source

Returns all defined steps found in the passed container.

# File lib/cucumber_analytics/world.rb, line 126
def defined_steps_in(container)
  all_steps = steps_in(container)

  all_steps.select { |step| World.loaded_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
end
delimiter=(new_delimiter) click to toggle source

Sets the delimiter that will be used by default when determining the boundaries of step arguments.

# File lib/cucumber_analytics/world.rb, line 51
def delimiter=(new_delimiter)
  self.left_delimiter = new_delimiter
  self.right_delimiter = new_delimiter
end
directories_in(container) click to toggle source

Returns all directories found in the passed container.

# File lib/cucumber_analytics/world.rb, line 94
def directories_in(container)
  Array.new.tap { |accumulated_directories| collect_all_in(:directories, container, accumulated_directories) }
end
feature_files_in(container) click to toggle source

Returns all feature files found in the passed container.

# File lib/cucumber_analytics/world.rb, line 99
def feature_files_in(container)
  Array.new.tap { |accumulated_files| collect_all_in(:feature_files, container, accumulated_files) }
end
features_in(container) click to toggle source

Returns all features found in the passed container.

# File lib/cucumber_analytics/world.rb, line 104
def features_in(container)
  Array.new.tap { |accumulated_features| collect_all_in(:features, container, accumulated_features) }
end
left_delimiter() click to toggle source

Returns the left delimiter, which is used to mark the beginning of a step argument.

# File lib/cucumber_analytics/world.rb, line 27
def left_delimiter
  @left_delimiter
end
left_delimiter=(new_delimiter) click to toggle source

Sets the left delimiter that will be used by default when determining step arguments.

# File lib/cucumber_analytics/world.rb, line 33
def left_delimiter=(new_delimiter)
  @left_delimiter = new_delimiter
end
load_step_file(file_path) click to toggle source

Loads the step patterns contained in the given file into the World.

# File lib/cucumber_analytics/world.rb, line 57
def load_step_file(file_path)
  File.open(file_path, 'r') do |file|
    file.readlines.each do |line|
      if step_def_line?(line)
        the_reg_ex = extract_regular_expression(line)
        loaded_step_patterns << the_reg_ex
      end
    end
  end
end
load_step_pattern(pattern) click to toggle source

Loads the step pattern into the World.

# File lib/cucumber_analytics/world.rb, line 69
def load_step_pattern(pattern)
  loaded_step_patterns << pattern
end
loaded_step_patterns() click to toggle source

Returns the step patterns that have been loaded into the World.

# File lib/cucumber_analytics/world.rb, line 74
def loaded_step_patterns
  @defined_expressions ||= []
end
right_delimiter() click to toggle source

Returns the right delimiter, which is used to mark the end of a step argument.

# File lib/cucumber_analytics/world.rb, line 39
def right_delimiter
  @right_delimiter
end
right_delimiter=(new_delimiter) click to toggle source

Sets the right delimiter that will be used by default when determining step arguments.

# File lib/cucumber_analytics/world.rb, line 45
def right_delimiter=(new_delimiter)
  @right_delimiter = new_delimiter
end
steps_in(container) click to toggle source

Returns all steps found in the passed container.

# File lib/cucumber_analytics/world.rb, line 114
def steps_in(container)
  Array.new.tap { |accumulated_steps| collect_all_in(:steps, container, accumulated_steps) }
end
tag_elements_in(container) click to toggle source

Returns all tag elements found in the passed container.

# File lib/cucumber_analytics/world.rb, line 89
def tag_elements_in(container)
  Array.new.tap { |accumulated_tag_elements| collect_all_in(:tag_elements, container, accumulated_tag_elements) }
end
tags_in(container) click to toggle source

Returns all tags found in the passed container.

# File lib/cucumber_analytics/world.rb, line 84
def tags_in(container)
  Array.new.tap { |accumulated_tags| collect_all_in(:tags, container, accumulated_tags) }
end
tests_in(container) click to toggle source

Returns all tests found in the passed container.

# File lib/cucumber_analytics/world.rb, line 109
def tests_in(container)
  Array.new.tap { |accumulated_tests| collect_all_in(:tests, container, accumulated_tests) }
end
undefined_steps_in(container) click to toggle source

Returns all undefined steps found in the passed container.

# File lib/cucumber_analytics/world.rb, line 119
def undefined_steps_in(container)
  all_steps = steps_in(container)

  all_steps.select { |step| !World.loaded_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
end

Private Class Methods

collect_all_in(type_of_thing, container, accumulated_things) click to toggle source

Recursively gathers all things of the given type found in the passed container.

# File lib/cucumber_analytics/world.rb, line 161
def collect_all_in(type_of_thing, container, accumulated_things)
  accumulated_things.concat container.send(type_of_thing) if container.respond_to?(type_of_thing)

  if container.respond_to?(:contains)
    container.contains.each do |child_container|
      collect_all_in(type_of_thing, child_container, accumulated_things)
    end
  end
end
desanitize_line(line) click to toggle source

And be sure to restore the line to its original state.

# File lib/cucumber_analytics/world.rb, line 143
def desanitize_line(line)
  line.gsub(SANITARY_STRING, '\/')
end
extract_regular_expression(line) click to toggle source

Returns the regular expression portion of a step pattern line.

# File lib/cucumber_analytics/world.rb, line 153
def extract_regular_expression(line)
  line = desanitize_line(sanitize_line(line).match(STEP_DEF_PATTERN_CAPTURE_PATTERN)[1])
  line = line.slice(1..(line.length - 2))

  Regexp.new(line)
end
sanitize_line(line) click to toggle source

Make life easier by ensuring that the only forward slashes in the regular expression are the important ones.

# File lib/cucumber_analytics/world.rb, line 138
def sanitize_line(line)
  line.gsub('\/', SANITARY_STRING)
end
step_def_line?(line) click to toggle source

Returns whether or not the passed line is a step pattern.

# File lib/cucumber_analytics/world.rb, line 148
def step_def_line?(line)
  !!(sanitize_line(line) =~ STEP_DEF_LINE_PATTERN)
end