Module: CucumberAnalytics::World

Defined in:
lib/cucumber_analytics/world.rb

Constant Summary collapse

SANITARY_STRING =
'___!!!___'
STEP_KEYWORD_PATTERN =
'\s*(?:Given|When|Then|And|But|\*)\s*'

Class Method Summary collapse

Class Method Details

.defined_step_patternsObject

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



48
49
50
# File 'lib/cucumber_analytics/world.rb', line 48

def self.defined_step_patterns
  @@defined_expressions
end

.defined_steps_in(container) ⇒ Object

Returns all defined steps found in the passed container.



95
96
97
98
99
# File 'lib/cucumber_analytics/world.rb', line 95

def self.defined_steps_in(container)
  all_steps = steps_in(container)

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

.features_in(container) ⇒ Object

Returns all features found in the passed container.



67
68
69
70
71
# File 'lib/cucumber_analytics/world.rb', line 67

def self.features_in(container)
  Array.new.tap do |accumulated_features|
    collect_features(accumulated_features, container)
  end
end

.files_in(container) ⇒ Object

Returns all feature files found in the passed container.



60
61
62
63
64
# File 'lib/cucumber_analytics/world.rb', line 60

def self.files_in(container)
  Array.new.tap do |accumulated_files|
    collect_files(accumulated_files, container)
  end
end

.left_delimiterObject

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



11
12
13
# File 'lib/cucumber_analytics/world.rb', line 11

def self.left_delimiter
  @left_delimiter || @right_delimiter
end

.left_delimiter=(new_delimiter) ⇒ Object

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



17
18
19
# File 'lib/cucumber_analytics/world.rb', line 17

def self.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.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cucumber_analytics/world.rb', line 34

def self.load_step_file(file_path)
  @@defined_expressions ||= []

  File.open(file_path, 'r') do |file|
    file.readlines.each do |line|
      if step_def_line?(line)
        the_reg_ex = extract_regular_expression(line)
        @@defined_expressions << the_reg_ex
      end
    end
  end
end

.right_delimiterObject

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



23
24
25
# File 'lib/cucumber_analytics/world.rb', line 23

def self.right_delimiter
  @right_delimiter || @left_delimiter
end

.right_delimiter=(new_delimiter) ⇒ Object

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



29
30
31
# File 'lib/cucumber_analytics/world.rb', line 29

def self.right_delimiter=(new_delimiter)
  @right_delimiter = new_delimiter
end

.steps_in(container) ⇒ Object

Returns all steps found in the passed container.



81
82
83
84
85
# File 'lib/cucumber_analytics/world.rb', line 81

def self.steps_in(container)
  Array.new.tap do |accumulated_steps|
    collect_steps(accumulated_steps, container)
  end
end

.tags_in(container) ⇒ Object

Returns all tags found in the passed container.



53
54
55
56
57
# File 'lib/cucumber_analytics/world.rb', line 53

def self.tags_in(container)
  Array.new.tap do |accumulated_tags|
    collect_tags(accumulated_tags, container)
  end
end

.tests_in(container) ⇒ Object

Returns all tests found in the passed container.



74
75
76
77
78
# File 'lib/cucumber_analytics/world.rb', line 74

def self.tests_in(container)
  Array.new.tap do |accumulated_tests|
    collect_tests(accumulated_tests, container)
  end
end

.undefined_steps_in(container) ⇒ Object

Returns all undefined steps found in the passed container.



88
89
90
91
92
# File 'lib/cucumber_analytics/world.rb', line 88

def self.undefined_steps_in(container)
  all_steps = steps_in(container)

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