cuke_modeler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.simplecov +8 -0
- data/Gemfile +4 -0
- data/History.rdoc +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +38 -0
- data/cuke_modeler.gemspec +29 -0
- data/features/analysis/test_comparison.feature +123 -0
- data/features/analysis/test_manipulation.feature +37 -0
- data/features/modeling/background_modeling.feature +75 -0
- data/features/modeling/background_output.feature +130 -0
- data/features/modeling/directory_modeling.feature +120 -0
- data/features/modeling/directory_output.feature +13 -0
- data/features/modeling/doc_string_modeling.feature +63 -0
- data/features/modeling/doc_string_output.feature +71 -0
- data/features/modeling/example_modeling.feature +111 -0
- data/features/modeling/example_output.feature +192 -0
- data/features/modeling/feature_file_modeling.feature +64 -0
- data/features/modeling/feature_file_output.feature +13 -0
- data/features/modeling/feature_modeling.feature +164 -0
- data/features/modeling/feature_output.feature +244 -0
- data/features/modeling/outline_modeling.feature +100 -0
- data/features/modeling/outline_output.feature +197 -0
- data/features/modeling/row_modeling.feature +77 -0
- data/features/modeling/row_output.feature +27 -0
- data/features/modeling/scenario_modeling.feature +89 -0
- data/features/modeling/scenario_output.feature +147 -0
- data/features/modeling/step_modeling.feature +85 -0
- data/features/modeling/step_output.feature +52 -0
- data/features/modeling/table_modeling.feature +52 -0
- data/features/modeling/table_output.feature +42 -0
- data/features/modeling/table_row_modeling.feature +67 -0
- data/features/modeling/table_row_output.feature +27 -0
- data/features/modeling/tag_modeling.feature +58 -0
- data/features/modeling/tag_output.feature +16 -0
- data/features/step_definitions/action_steps.rb +3 -0
- data/features/step_definitions/background_steps.rb +81 -0
- data/features/step_definitions/directory_steps.rb +52 -0
- data/features/step_definitions/doc_string_steps.rb +63 -0
- data/features/step_definitions/feature_file_steps.rb +41 -0
- data/features/step_definitions/feature_steps.rb +96 -0
- data/features/step_definitions/outline_steps.rb +252 -0
- data/features/step_definitions/setup_steps.rb +50 -0
- data/features/step_definitions/spec_steps.rb +18 -0
- data/features/step_definitions/step_steps.rb +159 -0
- data/features/step_definitions/table_steps.rb +54 -0
- data/features/step_definitions/tag_steps.rb +61 -0
- data/features/step_definitions/test_steps.rb +114 -0
- data/features/step_definitions/verification_steps.rb +9 -0
- data/features/support/env.rb +27 -0
- data/features/support/transforms.rb +3 -0
- data/lib/cuke_modeler.rb +29 -0
- data/lib/cuke_modeler/background.rb +38 -0
- data/lib/cuke_modeler/containing.rb +18 -0
- data/lib/cuke_modeler/directory.rb +86 -0
- data/lib/cuke_modeler/doc_string.rb +87 -0
- data/lib/cuke_modeler/example.rb +184 -0
- data/lib/cuke_modeler/feature.rb +147 -0
- data/lib/cuke_modeler/feature_element.rb +73 -0
- data/lib/cuke_modeler/feature_file.rb +77 -0
- data/lib/cuke_modeler/nested.rb +34 -0
- data/lib/cuke_modeler/outline.rb +68 -0
- data/lib/cuke_modeler/parsing.rb +32 -0
- data/lib/cuke_modeler/raw.rb +20 -0
- data/lib/cuke_modeler/row.rb +64 -0
- data/lib/cuke_modeler/scenario.rb +45 -0
- data/lib/cuke_modeler/sourceable.rb +20 -0
- data/lib/cuke_modeler/step.rb +214 -0
- data/lib/cuke_modeler/table.rb +90 -0
- data/lib/cuke_modeler/table_row.rb +64 -0
- data/lib/cuke_modeler/tag.rb +62 -0
- data/lib/cuke_modeler/taggable.rb +54 -0
- data/lib/cuke_modeler/test_element.rb +77 -0
- data/lib/cuke_modeler/version.rb +3 -0
- data/lib/cuke_modeler/world.rb +113 -0
- data/spec/integration/background_integration_spec.rb +72 -0
- data/spec/integration/directory_integration_spec.rb +48 -0
- data/spec/integration/doc_string_integration_spec.rb +66 -0
- data/spec/integration/example_integration_spec.rb +94 -0
- data/spec/integration/feature_file_integration_spec.rb +44 -0
- data/spec/integration/feature_integration_spec.rb +152 -0
- data/spec/integration/outline_integration_spec.rb +92 -0
- data/spec/integration/scenario_integration_spec.rb +80 -0
- data/spec/integration/step_integration_spec.rb +184 -0
- data/spec/integration/table_integration_spec.rb +86 -0
- data/spec/integration/table_row_integration_spec.rb +68 -0
- data/spec/integration/tag_integration_spec.rb +67 -0
- data/spec/integration/world_integration_spec.rb +13 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/unit/background_unit_spec.rb +55 -0
- data/spec/unit/bare_bones_unit_specs.rb +13 -0
- data/spec/unit/containing_element_unit_specs.rb +17 -0
- data/spec/unit/directory_unit_spec.rb +103 -0
- data/spec/unit/doc_string_unit_spec.rb +109 -0
- data/spec/unit/example_unit_spec.rb +251 -0
- data/spec/unit/feature_element_unit_spec.rb +19 -0
- data/spec/unit/feature_element_unit_specs.rb +46 -0
- data/spec/unit/feature_file_unit_spec.rb +94 -0
- data/spec/unit/feature_unit_spec.rb +135 -0
- data/spec/unit/nested_element_unit_specs.rb +36 -0
- data/spec/unit/nested_unit_spec.rb +37 -0
- data/spec/unit/outline_unit_spec.rb +91 -0
- data/spec/unit/parsing_unit_spec.rb +21 -0
- data/spec/unit/prepopulated_unit_specs.rb +13 -0
- data/spec/unit/raw_element_unit_specs.rb +24 -0
- data/spec/unit/raw_unit_spec.rb +25 -0
- data/spec/unit/row_unit_spec.rb +55 -0
- data/spec/unit/scenario_unit_spec.rb +71 -0
- data/spec/unit/sourceable_unit_spec.rb +17 -0
- data/spec/unit/sourced_element_unit_specs.rb +18 -0
- data/spec/unit/step_unit_spec.rb +259 -0
- data/spec/unit/table_row_unit_spec.rb +55 -0
- data/spec/unit/table_unit_spec.rb +96 -0
- data/spec/unit/tag_unit_spec.rb +51 -0
- data/spec/unit/taggable_unit_spec.rb +78 -0
- data/spec/unit/tagged_element_unit_specs.rb +63 -0
- data/spec/unit/test_element_unit_spec.rb +40 -0
- data/spec/unit/test_element_unit_specs.rb +31 -0
- data/spec/unit/world_unit_spec.rb +130 -0
- metadata +364 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A class modeling the table of a Step.
|
|
4
|
+
|
|
5
|
+
class Table
|
|
6
|
+
|
|
7
|
+
include Containing
|
|
8
|
+
include Raw
|
|
9
|
+
include Nested
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# The contents of the table
|
|
13
|
+
#
|
|
14
|
+
# Deprecated
|
|
15
|
+
attr_accessor :contents
|
|
16
|
+
|
|
17
|
+
# The row elements that make up the table
|
|
18
|
+
attr_accessor :row_elements
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Creates a new Table object and, if *source* is provided, populates
|
|
22
|
+
# the object.
|
|
23
|
+
def initialize(source = nil)
|
|
24
|
+
@contents = []
|
|
25
|
+
@row_elements = []
|
|
26
|
+
|
|
27
|
+
parsed_table = process_source(source)
|
|
28
|
+
|
|
29
|
+
build_table(parsed_table) if parsed_table
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Returns a gherkin representation of the table.
|
|
33
|
+
def to_s
|
|
34
|
+
row_elements.empty? ? '' : row_elements.collect { |row| row_output_string(row) }.join("\n")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def process_source(source)
|
|
42
|
+
case
|
|
43
|
+
when source.is_a?(String)
|
|
44
|
+
parse_table(source)
|
|
45
|
+
else
|
|
46
|
+
source
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def parse_table(source_text)
|
|
51
|
+
base_file_string = "Feature:\nScenario:\n* step\n"
|
|
52
|
+
source_text = base_file_string + source_text
|
|
53
|
+
|
|
54
|
+
parsed_file = Parsing::parse_text(source_text)
|
|
55
|
+
|
|
56
|
+
parsed_file.first['elements'].first['steps'].first['rows']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def build_table(table)
|
|
60
|
+
populate_contents(table)
|
|
61
|
+
populate_row_elements(table)
|
|
62
|
+
populate_raw_element(table)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def populate_contents(table)
|
|
66
|
+
@contents = table.collect { |row| row['cells'] }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def populate_row_elements(table)
|
|
70
|
+
table.each do |row|
|
|
71
|
+
@row_elements << build_child_element(TableRow, row)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def row_output_string(row)
|
|
76
|
+
row_text = '|'
|
|
77
|
+
|
|
78
|
+
row.cells.count.times do |count|
|
|
79
|
+
row_text << " #{row.cells[count].ljust(determine_buffer_size(count))} |"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
row_text
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def determine_buffer_size(index)
|
|
86
|
+
row_elements.collect { |row| row.cells[index].length }.max || 0
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A class modeling a step table row.
|
|
4
|
+
|
|
5
|
+
class TableRow
|
|
6
|
+
|
|
7
|
+
include Sourceable
|
|
8
|
+
include Raw
|
|
9
|
+
include Nested
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# The cells that make up the row
|
|
13
|
+
attr_accessor :cells
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Creates a new TableRow object and, if *source* is provided, populates
|
|
17
|
+
# the object.
|
|
18
|
+
def initialize(source = nil)
|
|
19
|
+
parsed_row = process_source(source)
|
|
20
|
+
|
|
21
|
+
@cells = []
|
|
22
|
+
|
|
23
|
+
build_row(parsed_row) if parsed_row
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns a gherkin representation of the table row.
|
|
27
|
+
def to_s
|
|
28
|
+
"| #{cells.join(' | ')} |"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def process_source(source)
|
|
36
|
+
case
|
|
37
|
+
when source.is_a?(String)
|
|
38
|
+
parse_row(source)
|
|
39
|
+
else
|
|
40
|
+
source
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def parse_row(source_text)
|
|
45
|
+
base_file_string = "Feature: Fake feature to parse\nScenario:\n* fake step\n"
|
|
46
|
+
source_text = base_file_string + source_text
|
|
47
|
+
|
|
48
|
+
parsed_file = Parsing::parse_text(source_text)
|
|
49
|
+
|
|
50
|
+
parsed_file.first['elements'].first['steps'].first['rows'].first
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def build_row(parsed_row)
|
|
54
|
+
populate_element_source_line(parsed_row)
|
|
55
|
+
populate_row_cells(parsed_row)
|
|
56
|
+
populate_raw_element(parsed_row)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def populate_row_cells(parsed_row)
|
|
60
|
+
@cells = parsed_row['cells']
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A class modeling a Tag.
|
|
4
|
+
|
|
5
|
+
class Tag
|
|
6
|
+
|
|
7
|
+
include Raw
|
|
8
|
+
include Sourceable
|
|
9
|
+
include Nested
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# The name of the Tag
|
|
13
|
+
attr_accessor :name
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Creates a new Tag object and, if *source* is provided, populates the
|
|
17
|
+
# object.
|
|
18
|
+
def initialize(source = nil)
|
|
19
|
+
parsed_tag = process_source(source)
|
|
20
|
+
|
|
21
|
+
build_tag(parsed_tag) if parsed_tag
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns gherkin representation of the tag.
|
|
25
|
+
def to_s
|
|
26
|
+
name || ''
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def process_source(source)
|
|
34
|
+
case
|
|
35
|
+
when source.is_a?(String)
|
|
36
|
+
parse_tag(source)
|
|
37
|
+
else
|
|
38
|
+
source
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def parse_tag(source_text)
|
|
43
|
+
base_file_string = "\nFeature: Fake feature to parse"
|
|
44
|
+
source_text = source_text + base_file_string
|
|
45
|
+
|
|
46
|
+
parsed_file = Parsing::parse_text(source_text)
|
|
47
|
+
|
|
48
|
+
parsed_file.first['tags'].first
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def build_tag(parsed_tag)
|
|
52
|
+
populate_name(parsed_tag)
|
|
53
|
+
populate_raw_element(parsed_tag)
|
|
54
|
+
populate_element_source_line(parsed_tag)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def populate_name(parsed_tag)
|
|
58
|
+
@name = parsed_tag['name']
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A mix-in module containing methods used by elements that can be tagged.
|
|
4
|
+
|
|
5
|
+
module Taggable
|
|
6
|
+
|
|
7
|
+
# The tags which are directly assigned to the element
|
|
8
|
+
attr_accessor :tags
|
|
9
|
+
|
|
10
|
+
# The tag elements belonging to the element
|
|
11
|
+
attr_accessor :tag_elements
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Returns the tags which are indirectly assigned to the element (i.e. they
|
|
15
|
+
# have been inherited from a parent element).
|
|
16
|
+
def applied_tags
|
|
17
|
+
@parent_element.respond_to?(:all_tags) ? @parent_element.all_tags : []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Returns the tags elements which are indirectly assigned to the element
|
|
21
|
+
# (i.e. they have been inherited from a parent element).
|
|
22
|
+
def applied_tag_elements
|
|
23
|
+
@parent_element.respond_to?(:all_tag_elements) ? @parent_element.all_tag_elements : []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns all of the tags which are applicable to the element.
|
|
27
|
+
def all_tags
|
|
28
|
+
applied_tags + @tags
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns all of the tag elements which are applicable to the element.
|
|
32
|
+
def all_tag_elements
|
|
33
|
+
applied_tag_elements + @tag_elements
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def populate_element_tags(parsed_element)
|
|
41
|
+
if parsed_element['tags']
|
|
42
|
+
parsed_element['tags'].each do |tag|
|
|
43
|
+
@tags << tag['name']
|
|
44
|
+
@tag_elements << build_child_element(Tag, tag)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def tag_output_string
|
|
50
|
+
tag_elements.collect { |tag| tag.name }.join(' ')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A class modeling an element that contains steps.
|
|
4
|
+
|
|
5
|
+
class TestElement < FeatureElement
|
|
6
|
+
|
|
7
|
+
include Containing
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# The steps contained by the TestElement
|
|
11
|
+
attr_accessor :steps
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Creates a new TestElement object and, if *parsed_test_element* is provided,
|
|
15
|
+
# populates the object.
|
|
16
|
+
def initialize(parsed_test_element = nil)
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
@steps = []
|
|
20
|
+
|
|
21
|
+
build_test_element(parsed_test_element) if parsed_test_element
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns true if the two elements have equivalent steps and false otherwise.
|
|
25
|
+
def ==(other_element)
|
|
26
|
+
steps == other_element.steps
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Returns the immediate child elements of the element.
|
|
30
|
+
def contains
|
|
31
|
+
@steps
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def process_source(source)
|
|
39
|
+
case
|
|
40
|
+
when source.is_a?(String)
|
|
41
|
+
parse_test_element(source)
|
|
42
|
+
else
|
|
43
|
+
source
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def parse_test_element(source_text)
|
|
48
|
+
base_file_string = "Feature: Fake feature to parse\n"
|
|
49
|
+
source_text = base_file_string + source_text
|
|
50
|
+
|
|
51
|
+
parsed_file = Parsing::parse_text(source_text)
|
|
52
|
+
|
|
53
|
+
parsed_file.first['elements'].first
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def build_test_element(parsed_test_element)
|
|
57
|
+
populate_test_element_steps(parsed_test_element)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def populate_test_element_steps(parsed_test_element)
|
|
61
|
+
if parsed_test_element['steps']
|
|
62
|
+
parsed_test_element['steps'].each do |step|
|
|
63
|
+
@steps << build_child_element(Step, step)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def steps_output_string
|
|
69
|
+
steps.collect { |step| indented_step_text(step) }.join("\n")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def indented_step_text(step)
|
|
73
|
+
step.to_s.split("\n").collect { |line| " #{line}" }.join("\n")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
module CukeModeler
|
|
2
|
+
|
|
3
|
+
# A module providing suite level analysis functionality.
|
|
4
|
+
|
|
5
|
+
module World
|
|
6
|
+
|
|
7
|
+
# A placeholder string used to mark 'dirty' portions of input strings
|
|
8
|
+
SANITARY_STRING = '___SANITIZED_BY_CUCUMBER_ANALYTICS___'
|
|
9
|
+
|
|
10
|
+
# A pattern that matches a Cucumber step keyword
|
|
11
|
+
STEP_DEF_KEYWORD_PATTERN = '(?:Given|When|Then|And|But)'
|
|
12
|
+
|
|
13
|
+
# A pattern that matches a 'clean' regular expression
|
|
14
|
+
REGEX_PATTERN_STRING = '\/[^\/]*\/'
|
|
15
|
+
|
|
16
|
+
# A pattern that matches a step definition declaration line
|
|
17
|
+
STEP_DEF_LINE_PATTERN = /^\s*#{World::STEP_DEF_KEYWORD_PATTERN}\s*\(?\s*#{REGEX_PATTERN_STRING}\s*\)?/
|
|
18
|
+
|
|
19
|
+
# A pattern that captures the regular expression portion of a step definition declaration line
|
|
20
|
+
STEP_DEF_PATTERN_CAPTURE_PATTERN = /^\s*#{World::STEP_DEF_KEYWORD_PATTERN}\s*\(?\s*(#{REGEX_PATTERN_STRING})\s*\)?/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
|
|
25
|
+
# Returns the left delimiter, which is used to mark the beginning of a step
|
|
26
|
+
# argument.
|
|
27
|
+
def left_delimiter
|
|
28
|
+
@left_delimiter
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Sets the left delimiter that will be used by default when determining
|
|
32
|
+
# step arguments.
|
|
33
|
+
def left_delimiter=(new_delimiter)
|
|
34
|
+
@left_delimiter = new_delimiter
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Returns the right delimiter, which is used to mark the end of a step
|
|
38
|
+
# argument.
|
|
39
|
+
def right_delimiter
|
|
40
|
+
@right_delimiter
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Sets the right delimiter that will be used by default when determining
|
|
44
|
+
# step arguments.
|
|
45
|
+
def right_delimiter=(new_delimiter)
|
|
46
|
+
@right_delimiter = new_delimiter
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Sets the delimiter that will be used by default when determining the
|
|
50
|
+
# boundaries of step arguments.
|
|
51
|
+
def delimiter=(new_delimiter)
|
|
52
|
+
self.left_delimiter = new_delimiter
|
|
53
|
+
self.right_delimiter = new_delimiter
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Loads the step patterns contained in the given file into the World.
|
|
57
|
+
def load_step_file(file_path)
|
|
58
|
+
File.open(file_path, 'r') do |file|
|
|
59
|
+
file.readlines.each do |line|
|
|
60
|
+
if step_def_line?(line)
|
|
61
|
+
the_reg_ex = extract_regular_expression(line)
|
|
62
|
+
loaded_step_patterns << the_reg_ex
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Loads the step pattern into the World.
|
|
69
|
+
def load_step_pattern(pattern)
|
|
70
|
+
loaded_step_patterns << pattern
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Returns the step patterns that have been loaded into the World.
|
|
74
|
+
def loaded_step_patterns
|
|
75
|
+
@defined_expressions ||= []
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Clears the step patterns that have been loaded into the World.
|
|
79
|
+
def clear_step_patterns
|
|
80
|
+
@defined_expressions = []
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# Make life easier by ensuring that the only forward slashes in the
|
|
88
|
+
# regular expression are the important ones.
|
|
89
|
+
def sanitize_line(line)
|
|
90
|
+
line.gsub('\/', SANITARY_STRING)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# And be sure to restore the line to its original state.
|
|
94
|
+
def desanitize_line(line)
|
|
95
|
+
line.gsub(SANITARY_STRING, '\/')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Returns whether or not the passed line is a step pattern.
|
|
99
|
+
def step_def_line?(line)
|
|
100
|
+
!!(sanitize_line(line) =~ STEP_DEF_LINE_PATTERN)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Returns the regular expression portion of a step pattern line.
|
|
104
|
+
def extract_regular_expression(line)
|
|
105
|
+
line = desanitize_line(sanitize_line(line).match(STEP_DEF_PATTERN_CAPTURE_PATTERN)[1])
|
|
106
|
+
line = line.slice(1..(line.length - 2))
|
|
107
|
+
|
|
108
|
+
Regexp.new(line)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|