Module: CucumberAnalytics::World
- Defined in:
- lib/cucumber_analytics/world.rb
Overview
A module providing suite level analysis functionality.
Constant Summary collapse
- SANITARY_STRING =
A placeholder string used to mark ‘dirty’ portions of input strings
'___SANITIZED_BY_CUCUMBER_ANALYTICS___'
- STEP_DEF_KEYWORD_PATTERN =
A pattern that matches a Cucumber step keyword
'(?:Given|When|Then|And|But)'
- REGEX_PATTERN_STRING =
A pattern that matches a ‘clean’ regular expression
'\/[^\/]*\/'
- STEP_DEF_LINE_PATTERN =
A pattern that matches a step definition declaration line
/^\s*#{World::STEP_DEF_KEYWORD_PATTERN}\s*\(?\s*#{REGEX_PATTERN_STRING}\s*\)?/
- STEP_DEF_PATTERN_CAPTURE_PATTERN =
A pattern that captures the regular expression portion of a step definition declaration line
/^\s*#{World::STEP_DEF_KEYWORD_PATTERN}\s*\(?\s*(#{REGEX_PATTERN_STRING})\s*\)?/
Class Method Summary collapse
-
.clear_step_patterns ⇒ Object
Clears the step patterns that have been loaded into the World.
-
.defined_steps_in(container) ⇒ Object
Returns all defined steps found in the passed container.
-
.delimiter=(new_delimiter) ⇒ Object
Sets the delimiter that will be used by default when determining the boundaries of step arguments.
-
.directories_in(container) ⇒ Object
Returns all directories found in the passed container.
-
.feature_files_in(container) ⇒ Object
Returns all feature files found in the passed container.
-
.features_in(container) ⇒ Object
Returns all features found in the passed container.
-
.left_delimiter ⇒ Object
Returns the left delimiter, which is used to mark the beginning of a step argument.
-
.left_delimiter=(new_delimiter) ⇒ Object
Sets the left delimiter that will be used by default when determining step arguments.
-
.load_step_file(file_path) ⇒ Object
Loads the step patterns contained in the given file into the World.
-
.load_step_pattern(pattern) ⇒ Object
Loads the step pattern into the World.
-
.loaded_step_patterns ⇒ Object
Returns the step patterns that have been loaded into the World.
-
.right_delimiter ⇒ Object
Returns the right delimiter, which is used to mark the end of a step argument.
-
.right_delimiter=(new_delimiter) ⇒ Object
Sets the right delimiter that will be used by default when determining step arguments.
-
.steps_in(container) ⇒ Object
Returns all steps found in the passed container.
-
.tag_elements_in(container) ⇒ Object
Returns all tag elements found in the passed container.
-
.tags_in(container) ⇒ Object
Returns all tags found in the passed container.
-
.tests_in(container) ⇒ Object
Returns all tests found in the passed container.
-
.undefined_steps_in(container) ⇒ Object
Returns all undefined steps found in the passed container.
Class Method Details
.clear_step_patterns ⇒ Object
Clears the step patterns that have been loaded into the World.
79 80 81 |
# File 'lib/cucumber_analytics/world.rb', line 79 def clear_step_patterns @defined_expressions = [] end |
.defined_steps_in(container) ⇒ Object
Returns all defined steps found in the passed container.
126 127 128 129 130 |
# 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) ⇒ Object
Sets the delimiter that will be used by default when determining the boundaries of step arguments.
51 52 53 54 |
# 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) ⇒ Object
Returns all directories found in the passed container.
94 95 96 |
# 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) ⇒ Object
Returns all feature files found in the passed container.
99 100 101 |
# 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) ⇒ Object
Returns all features found in the passed container.
104 105 106 |
# 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 ⇒ Object
Returns the left delimiter, which is used to mark the beginning of a step argument.
27 28 29 |
# File 'lib/cucumber_analytics/world.rb', line 27 def left_delimiter @left_delimiter end |
.left_delimiter=(new_delimiter) ⇒ Object
Sets the left delimiter that will be used by default when determining step arguments.
33 34 35 |
# File 'lib/cucumber_analytics/world.rb', line 33 def left_delimiter=(new_delimiter) @left_delimiter = new_delimiter end |
.load_step_file(file_path) ⇒ Object
Loads the step patterns contained in the given file into the World.
57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
Loads the step pattern into the World.
69 70 71 |
# File 'lib/cucumber_analytics/world.rb', line 69 def load_step_pattern(pattern) loaded_step_patterns << pattern end |
.loaded_step_patterns ⇒ Object
Returns the step patterns that have been loaded into the World.
74 75 76 |
# File 'lib/cucumber_analytics/world.rb', line 74 def loaded_step_patterns @defined_expressions ||= [] end |
.right_delimiter ⇒ Object
Returns the right delimiter, which is used to mark the end of a step argument.
39 40 41 |
# File 'lib/cucumber_analytics/world.rb', line 39 def right_delimiter @right_delimiter end |
.right_delimiter=(new_delimiter) ⇒ Object
Sets the right delimiter that will be used by default when determining step arguments.
45 46 47 |
# File 'lib/cucumber_analytics/world.rb', line 45 def right_delimiter=(new_delimiter) @right_delimiter = new_delimiter end |
.steps_in(container) ⇒ Object
Returns all steps found in the passed container.
114 115 116 |
# 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) ⇒ Object
Returns all tag elements found in the passed container.
89 90 91 |
# 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) ⇒ Object
Returns all tags found in the passed container.
84 85 86 |
# File 'lib/cucumber_analytics/world.rb', line 84 def (container) Array.new.tap { || collect_all_in(:tags, container, ) } end |
.tests_in(container) ⇒ Object
Returns all tests found in the passed container.
109 110 111 |
# 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) ⇒ Object
Returns all undefined steps found in the passed container.
119 120 121 122 123 |
# 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 |