cucumber_analytics 0.0.9 → 1.0.0
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 +15 -0
- data/History.rdoc +16 -0
- data/README.rdoc +5 -3
- data/Rakefile +7 -2
- data/cucumber_analytics.gemspec +7 -5
- data/features/analysis/step_collection.feature +44 -45
- data/features/modeling/background_modeling.feature +14 -144
- data/features/modeling/directory_modeling.feature +3 -2
- data/features/modeling/doc_string_modeling.feature +46 -0
- data/features/modeling/example_modeling.feature +13 -34
- data/features/modeling/feature_file_modeling.feature +3 -2
- data/features/modeling/feature_modeling.feature +18 -80
- data/features/modeling/outline_modeling.feature +25 -164
- data/features/modeling/scenario_modeling.feature +17 -144
- data/features/modeling/step_modeling.feature +68 -0
- data/features/modeling/table_modeling.feature +41 -0
- data/features/step_definitions/background_steps.rb +12 -11
- data/features/step_definitions/directory_steps.rb +6 -3
- data/features/step_definitions/doc_string_steps.rb +50 -0
- data/features/step_definitions/{file_steps.rb → feature_file_steps.rb} +8 -2
- data/features/step_definitions/feature_steps.rb +8 -4
- data/features/step_definitions/outline_steps.rb +12 -6
- data/features/step_definitions/setup_steps.rb +2 -2
- data/features/step_definitions/spec_steps.rb +6 -3
- data/features/step_definitions/step_steps.rb +91 -0
- data/features/step_definitions/table_steps.rb +10 -0
- data/features/step_definitions/test_steps.rb +6 -10
- data/features/step_definitions/world_steps.rb +28 -19
- data/features/support/env.rb +0 -2
- data/lib/cucumber_analytics/background.rb +16 -0
- data/lib/cucumber_analytics/containing.rb +18 -0
- data/lib/cucumber_analytics/directory.rb +83 -0
- data/lib/cucumber_analytics/doc_string.rb +55 -0
- data/lib/cucumber_analytics/example.rb +100 -0
- data/lib/cucumber_analytics/feature.rb +120 -0
- data/lib/cucumber_analytics/feature_element.rb +22 -40
- data/lib/cucumber_analytics/feature_file.rb +74 -0
- data/lib/cucumber_analytics/outline.rb +49 -0
- data/lib/cucumber_analytics/parsing.rb +30 -0
- data/lib/cucumber_analytics/scenario.rb +31 -0
- data/lib/cucumber_analytics/step.rb +142 -32
- data/lib/cucumber_analytics/table.rb +51 -0
- data/lib/cucumber_analytics/taggable.rb +35 -0
- data/lib/cucumber_analytics/test_element.rb +36 -91
- data/lib/cucumber_analytics/version.rb +1 -1
- data/lib/cucumber_analytics/world.rb +109 -153
- data/lib/cucumber_analytics.rb +12 -8
- data/spec/integration/background_integration_spec.rb +18 -0
- data/spec/integration/directory_integration_spec.rb +24 -0
- data/spec/{feature_spec.rb → integration/feature_file_integration_spec.rb} +5 -5
- data/spec/integration/feature_integration_spec.rb +86 -0
- data/spec/integration/outline_integration_spec.rb +22 -0
- data/spec/integration/scenario_integration_spec.rb +18 -0
- data/spec/integration/step_integration_spec.rb +116 -0
- data/spec/integration/world_integration_spec.rb +40 -0
- data/spec/spec_helper.rb +7 -3
- data/spec/unit/background_unit_spec.rb +22 -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 +91 -0
- data/spec/unit/doc_string_unit_spec.rb +65 -0
- data/spec/unit/example_unit_spec.rb +171 -0
- data/spec/unit/feature_element_unit_spec.rb +19 -0
- data/spec/unit/feature_element_unit_specs.rb +39 -0
- data/spec/unit/feature_file_unit_spec.rb +82 -0
- data/spec/unit/feature_unit_spec.rb +81 -0
- data/spec/unit/nested_element_unit_specs.rb +24 -0
- data/spec/unit/outline_unit_spec.rb +56 -0
- data/spec/unit/parsing_unit_spec.rb +21 -0
- data/spec/unit/prepopulated_unit_specs.rb +13 -0
- data/spec/unit/scenario_unit_spec.rb +36 -0
- data/spec/unit/step_unit_spec.rb +231 -0
- data/spec/unit/table_unit_spec.rb +52 -0
- data/spec/unit/taggable_unit_spec.rb +63 -0
- data/spec/unit/tagged_element_unit_specs.rb +48 -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 +167 -0
- metadata +106 -41
- data/lib/cucumber_analytics/logging.rb +0 -28
- data/lib/cucumber_analytics/outline_example.rb +0 -110
- data/lib/cucumber_analytics/parsed_background.rb +0 -45
- data/lib/cucumber_analytics/parsed_directory.rb +0 -78
- data/lib/cucumber_analytics/parsed_feature.rb +0 -97
- data/lib/cucumber_analytics/parsed_file.rb +0 -199
- data/lib/cucumber_analytics/parsed_scenario.rb +0 -67
- data/lib/cucumber_analytics/parsed_scenario_outline.rb +0 -122
- data/spec/background_spec.rb +0 -23
- data/spec/directory_spec.rb +0 -18
- data/spec/example_spec.rb +0 -37
- data/spec/file_spec.rb +0 -20
- data/spec/outline_spec.rb +0 -32
- data/spec/scenario_spec.rb +0 -33
- data/spec/step_spec.rb +0 -24
|
@@ -1,207 +1,163 @@
|
|
|
1
1
|
module CucumberAnalytics
|
|
2
|
-
module World
|
|
3
2
|
|
|
3
|
+
# A module providing suite level analysis functionality.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
STEP_KEYWORD_PATTERN = '\s*(?:Given|When|Then|And|But|\*)\s*'
|
|
7
|
-
TEST_ELEMENT_START_PATTERN = '^\s*(?:@|Background:|Scenario:|(?:Scenario Outline:))'
|
|
5
|
+
module World
|
|
8
6
|
|
|
7
|
+
# A placeholder string used to mark 'dirty' portions of input strings
|
|
8
|
+
SANITARY_STRING = '___SANITIZED_BY_CUCUMBER_ANALYTICS___'
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
def self.left_delimiter
|
|
13
|
-
@left_delimiter || @right_delimiter
|
|
14
|
-
end
|
|
10
|
+
# A pattern that matches a Cucumber step keyword
|
|
11
|
+
STEP_DEF_KEYWORD_PATTERN = '(?:Given|When|Then|And|But)'
|
|
15
12
|
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
def self.left_delimiter=(new_delimiter)
|
|
19
|
-
@left_delimiter = new_delimiter
|
|
20
|
-
end
|
|
13
|
+
# A pattern that matches a 'clean' regular expression
|
|
14
|
+
REGEX_PATTERN_STRING = '\/[^\/]*\/'
|
|
21
15
|
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
def self.right_delimiter
|
|
25
|
-
@right_delimiter || @left_delimiter
|
|
26
|
-
end
|
|
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*\)?/
|
|
27
18
|
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
def self.right_delimiter=(new_delimiter)
|
|
31
|
-
@right_delimiter = new_delimiter
|
|
32
|
-
end
|
|
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*\)?/
|
|
33
21
|
|
|
34
|
-
# Loads the step patterns contained in the given file into the World.
|
|
35
|
-
def self.load_step_file(file_path)
|
|
36
|
-
@@defined_expressions ||= []
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
file.readlines.each do |line|
|
|
40
|
-
if step_def_line?(line)
|
|
41
|
-
the_reg_ex = extract_regular_expression(line)
|
|
42
|
-
@@defined_expressions << the_reg_ex
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
23
|
+
class << self
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# Returns all tags found in the passed container.
|
|
54
|
-
def self.tags_in(container)
|
|
55
|
-
Array.new.tap do |accumulated_tags|
|
|
56
|
-
collect_tags(accumulated_tags, container)
|
|
25
|
+
# Returns the left delimiter, which is used to mark the beginning of a step
|
|
26
|
+
# argument.
|
|
27
|
+
def left_delimiter
|
|
28
|
+
@left_delimiter
|
|
57
29
|
end
|
|
58
|
-
end
|
|
59
30
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
64
35
|
end
|
|
65
|
-
end
|
|
66
36
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
37
|
+
# Returns the right delimiter, which is used to mark the end of a step
|
|
38
|
+
# argument.
|
|
39
|
+
def right_delimiter
|
|
40
|
+
@right_delimiter
|
|
71
41
|
end
|
|
72
|
-
end
|
|
73
42
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
78
47
|
end
|
|
79
|
-
end
|
|
80
48
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
85
54
|
end
|
|
86
|
-
end
|
|
87
55
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
92
66
|
end
|
|
93
|
-
end
|
|
94
67
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
all_steps.select { |step| !World.defined_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
|
|
100
|
-
end
|
|
68
|
+
# Loads the step pattern into the World.
|
|
69
|
+
def load_step_pattern(pattern)
|
|
70
|
+
loaded_step_patterns << pattern
|
|
71
|
+
end
|
|
101
72
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
73
|
+
# Returns the step patterns that have been loaded into the World.
|
|
74
|
+
def loaded_step_patterns
|
|
75
|
+
@defined_expressions ||= []
|
|
76
|
+
end
|
|
105
77
|
|
|
106
|
-
|
|
107
|
-
|
|
78
|
+
# Returns all tags found in the passed container.
|
|
79
|
+
def tags_in(container)
|
|
80
|
+
Array.new.tap { |accumulated_tags| collect_all_in(:tags, container, accumulated_tags) }
|
|
81
|
+
end
|
|
108
82
|
|
|
83
|
+
# Returns all directories found in the passed container.
|
|
84
|
+
def directories_in(container)
|
|
85
|
+
Array.new.tap { |accumulated_directories| collect_all_in(:directories, container, accumulated_directories) }
|
|
86
|
+
end
|
|
109
87
|
|
|
110
|
-
|
|
88
|
+
# Returns all feature files found in the passed container.
|
|
89
|
+
def feature_files_in(container)
|
|
90
|
+
Array.new.tap { |accumulated_files| collect_all_in(:feature_files, container, accumulated_files) }
|
|
91
|
+
end
|
|
111
92
|
|
|
93
|
+
# Returns all features found in the passed container.
|
|
94
|
+
def features_in(container)
|
|
95
|
+
Array.new.tap { |accumulated_features| collect_all_in(:features, container, accumulated_features) }
|
|
96
|
+
end
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
end
|
|
98
|
+
# Returns all tests found in the passed container.
|
|
99
|
+
def tests_in(container)
|
|
100
|
+
Array.new.tap { |accumulated_tests| collect_all_in(:tests, container, accumulated_tests) }
|
|
101
|
+
end
|
|
118
102
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
# Returns all steps found in the passed container.
|
|
104
|
+
def steps_in(container)
|
|
105
|
+
Array.new.tap { |accumulated_steps| collect_all_in(:steps, container, accumulated_steps) }
|
|
106
|
+
end
|
|
123
107
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
end
|
|
108
|
+
# Returns all undefined steps found in the passed container.
|
|
109
|
+
def undefined_steps_in(container)
|
|
110
|
+
all_steps = steps_in(container)
|
|
128
111
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
desanitize_line(sanitize_line(line).match(/^#{World::STEP_KEYWORD_PATTERN}\/([^\/]*)\//)[1])
|
|
132
|
-
end
|
|
112
|
+
all_steps.select { |step| !World.loaded_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
|
|
113
|
+
end
|
|
133
114
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
115
|
+
# Returns all defined steps found in the passed container.
|
|
116
|
+
def defined_steps_in(container)
|
|
117
|
+
all_steps = steps_in(container)
|
|
137
118
|
|
|
138
|
-
|
|
139
|
-
container.contains.each do |child_container|
|
|
140
|
-
collect_tags(accumulated_tags, child_container)
|
|
141
|
-
end
|
|
119
|
+
all_steps.select { |step| World.loaded_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
|
|
142
120
|
end
|
|
143
|
-
end
|
|
144
121
|
|
|
145
|
-
# Recursively gathers all directories found in the passed container.
|
|
146
|
-
def self.collect_directories(accumulated_directories, container)
|
|
147
|
-
accumulated_directories.concat container.feature_directories if container.respond_to?(:feature_directories)
|
|
148
122
|
|
|
149
|
-
|
|
150
|
-
container.contains.each do |child_container|
|
|
151
|
-
collect_directories(accumulated_directories, child_container)
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
123
|
+
private
|
|
155
124
|
|
|
156
|
-
# Recursively gathers all feature files found in the passed container.
|
|
157
|
-
def self.collect_files(accumulated_files, container)
|
|
158
|
-
accumulated_files.concat container.feature_files if container.respond_to?(:feature_files)
|
|
159
125
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
126
|
+
# Make life easier by ensuring that the only forward slashes in the
|
|
127
|
+
# regular expression are the important ones.
|
|
128
|
+
def sanitize_line(line)
|
|
129
|
+
line.gsub('\/', SANITARY_STRING)
|
|
164
130
|
end
|
|
165
|
-
end
|
|
166
131
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
132
|
+
# And be sure to restore the line to its original state.
|
|
133
|
+
def desanitize_line(line)
|
|
134
|
+
line.gsub(SANITARY_STRING, '\/')
|
|
135
|
+
end
|
|
170
136
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
end
|
|
137
|
+
# Returns whether or not the passed line is a step pattern.
|
|
138
|
+
def step_def_line?(line)
|
|
139
|
+
!!(sanitize_line(line) =~ STEP_DEF_LINE_PATTERN)
|
|
175
140
|
end
|
|
176
|
-
end
|
|
177
141
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
142
|
+
# Returns the regular expression portion of a step pattern line.
|
|
143
|
+
def extract_regular_expression(line)
|
|
144
|
+
line = desanitize_line(sanitize_line(line).match(STEP_DEF_PATTERN_CAPTURE_PATTERN)[1])
|
|
145
|
+
line = line.slice(1..(line.length - 2))
|
|
181
146
|
|
|
182
|
-
|
|
183
|
-
container.contains.each do |child_container|
|
|
184
|
-
collect_tests(accumulated_tests, child_container)
|
|
185
|
-
end
|
|
147
|
+
Regexp.new(line)
|
|
186
148
|
end
|
|
187
|
-
end
|
|
188
149
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
150
|
+
# Recursively gathers all things of the given type found in the passed container.
|
|
151
|
+
def collect_all_in(type_of_thing, container, accumulated_things)
|
|
152
|
+
accumulated_things.concat container.send(type_of_thing) if container.respond_to?(type_of_thing)
|
|
192
153
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
154
|
+
if container.respond_to?(:contains)
|
|
155
|
+
container.contains.each do |child_container|
|
|
156
|
+
collect_all_in(type_of_thing, child_container, accumulated_things)
|
|
157
|
+
end
|
|
196
158
|
end
|
|
197
159
|
end
|
|
198
|
-
end
|
|
199
160
|
|
|
200
|
-
# Returns true if the line is ignored when reading source code, false
|
|
201
|
-
# otherwise.
|
|
202
|
-
def self.ignored_line?(line)
|
|
203
|
-
line =~ /^\s*#/ or !(line =~ /\S/)
|
|
204
161
|
end
|
|
205
|
-
|
|
206
162
|
end
|
|
207
163
|
end
|
data/lib/cucumber_analytics.rb
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
require 'cucumber_analytics/version'
|
|
2
|
-
require 'cucumber_analytics/
|
|
3
|
-
require 'cucumber_analytics/
|
|
4
|
-
require 'cucumber_analytics/
|
|
2
|
+
require 'cucumber_analytics/parsing'
|
|
3
|
+
require 'cucumber_analytics/containing'
|
|
4
|
+
require 'cucumber_analytics/taggable'
|
|
5
|
+
require 'cucumber_analytics/feature_file'
|
|
6
|
+
require 'cucumber_analytics/directory'
|
|
5
7
|
require 'cucumber_analytics/feature_element.rb'
|
|
6
|
-
require 'cucumber_analytics/
|
|
8
|
+
require 'cucumber_analytics/feature'
|
|
7
9
|
require 'cucumber_analytics/test_element.rb'
|
|
8
|
-
require 'cucumber_analytics/
|
|
9
|
-
require 'cucumber_analytics/
|
|
10
|
-
require 'cucumber_analytics/
|
|
11
|
-
require 'cucumber_analytics/
|
|
10
|
+
require 'cucumber_analytics/background'
|
|
11
|
+
require 'cucumber_analytics/scenario'
|
|
12
|
+
require 'cucumber_analytics/outline'
|
|
13
|
+
require 'cucumber_analytics/example'
|
|
12
14
|
require 'cucumber_analytics/step'
|
|
15
|
+
require 'cucumber_analytics/doc_string'
|
|
16
|
+
require 'cucumber_analytics/table'
|
|
13
17
|
require 'cucumber_analytics/world'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Background') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Background, Integration' do
|
|
6
|
+
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
|
+
source = [' Background: Test background',
|
|
9
|
+
' * a step']
|
|
10
|
+
source = source.join("\n")
|
|
11
|
+
|
|
12
|
+
background = CucumberAnalytics::Background.new(source)
|
|
13
|
+
step = background.steps.first
|
|
14
|
+
|
|
15
|
+
step.parent_element.should equal background
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Directory') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Directory, Integration' do
|
|
6
|
+
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
|
+
nested_directory = "#{@default_file_directory}/nested_directory"
|
|
9
|
+
file_path = "#{@default_file_directory}/#{@default_feature_file_name}"
|
|
10
|
+
|
|
11
|
+
FileUtils.mkdir(nested_directory)
|
|
12
|
+
File.open(file_path, "w") { |file|
|
|
13
|
+
file.puts('Feature: Test feature')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
directory = CucumberAnalytics::Directory.new(@default_file_directory)
|
|
17
|
+
nested_directory = directory.directories.first
|
|
18
|
+
file = directory.feature_files.first
|
|
19
|
+
|
|
20
|
+
nested_directory.parent_element.should equal directory
|
|
21
|
+
file.parent_element.should equal directory
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
SimpleCov.command_name('
|
|
3
|
+
SimpleCov.command_name('FeatureFile') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
4
|
|
|
5
|
-
describe
|
|
5
|
+
describe 'FeatureFile, Integration' do
|
|
6
6
|
|
|
7
|
-
it '
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
8
|
file_path = "#{@default_file_directory}/#{@default_feature_file_name}"
|
|
9
9
|
|
|
10
10
|
File.open(file_path, "w") { |file|
|
|
11
11
|
file.puts('Feature: Test feature')
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
file = CucumberAnalytics::
|
|
14
|
+
file = CucumberAnalytics::FeatureFile.new(file_path)
|
|
15
15
|
feature = file.feature
|
|
16
16
|
|
|
17
17
|
feature.parent_element.should equal file
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Feature') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Feature, Integration' do
|
|
6
|
+
|
|
7
|
+
clazz = CucumberAnalytics::Feature
|
|
8
|
+
|
|
9
|
+
before(:each) do
|
|
10
|
+
@feature = clazz.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'properly sets its child elements' do
|
|
14
|
+
source = ['Feature: Test feature',
|
|
15
|
+
' Background: Test background',
|
|
16
|
+
' Scenario: Test scenario',
|
|
17
|
+
' Scenario Outline: Test outline']
|
|
18
|
+
source = source.join("\n")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
feature = CucumberAnalytics::Feature.new(source)
|
|
22
|
+
background = feature.background
|
|
23
|
+
scenario = feature.tests[0]
|
|
24
|
+
outline = feature.tests[1]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
outline.parent_element.should equal feature
|
|
28
|
+
scenario.parent_element.should equal feature
|
|
29
|
+
background.parent_element.should equal feature
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'can distinguish scenarios from outlines - #scenarios, #outlines' do
|
|
33
|
+
scenarios = [CucumberAnalytics::Scenario.new('Scenario: 1'), CucumberAnalytics::Scenario.new('Scenario: 2')]
|
|
34
|
+
outlines = [CucumberAnalytics::Outline.new('Scenario Outline: 1'), CucumberAnalytics::Outline.new('Scenario Outline: 2')]
|
|
35
|
+
|
|
36
|
+
@feature.tests = scenarios + outlines
|
|
37
|
+
|
|
38
|
+
@feature.scenarios.should =~ scenarios
|
|
39
|
+
@feature.outlines.should =~ outlines
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'knows how many scenarios it has - #scenario_count' do
|
|
43
|
+
scenarios = [CucumberAnalytics::Scenario.new('Scenario: 1'), CucumberAnalytics::Scenario.new('Scenario: 2')]
|
|
44
|
+
outlines = [CucumberAnalytics::Outline.new('Scenario Outline: 1')]
|
|
45
|
+
|
|
46
|
+
@feature.tests = []
|
|
47
|
+
@feature.scenario_count.should == 0
|
|
48
|
+
|
|
49
|
+
@feature.tests = scenarios + outlines
|
|
50
|
+
@feature.scenario_count.should == 2
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'knows how many outlines it has - #outline_count' do
|
|
54
|
+
scenarios = [CucumberAnalytics::Scenario.new('Scenario: 1')]
|
|
55
|
+
outlines = [CucumberAnalytics::Outline.new('Scenario Outline: 1'), CucumberAnalytics::Outline.new('Scenario Outline: 2')]
|
|
56
|
+
|
|
57
|
+
@feature.tests = []
|
|
58
|
+
@feature.outline_count.should == 0
|
|
59
|
+
|
|
60
|
+
@feature.tests = scenarios + outlines
|
|
61
|
+
@feature.outline_count.should == 2
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'knows how many test cases it has - #test_case_count' do
|
|
65
|
+
source_1 = ['Feature: Test feature']
|
|
66
|
+
source_1 = source_1.join("\n")
|
|
67
|
+
|
|
68
|
+
source_2 = ['Feature: Test feature',
|
|
69
|
+
' Scenario: Test scenario',
|
|
70
|
+
' Scenario Outline: Test outline',
|
|
71
|
+
' * a step',
|
|
72
|
+
' Examples: Test examples',
|
|
73
|
+
' |param|',
|
|
74
|
+
' |value_1|',
|
|
75
|
+
' |value_2|']
|
|
76
|
+
source_2 = source_2.join("\n")
|
|
77
|
+
|
|
78
|
+
feature_1 = CucumberAnalytics::Feature.new(source_1)
|
|
79
|
+
feature_2 = CucumberAnalytics::Feature.new(source_2)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
feature_1.test_case_count.should == 0
|
|
83
|
+
feature_2.test_case_count.should == 3
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Outline') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Outline, Integration' do
|
|
6
|
+
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
|
+
source = [' Scenario Outline:',
|
|
9
|
+
' * a step',
|
|
10
|
+
' Examples:',
|
|
11
|
+
' | param |']
|
|
12
|
+
source = source.join("\n")
|
|
13
|
+
|
|
14
|
+
outline = CucumberAnalytics::Outline.new(source)
|
|
15
|
+
example = outline.examples.first
|
|
16
|
+
step = outline.steps.first
|
|
17
|
+
|
|
18
|
+
example.parent_element.should equal outline
|
|
19
|
+
step.parent_element.should equal outline
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Scenario') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Scenario, Integration' do
|
|
6
|
+
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
|
+
source = ['Scenario: Test scenario',
|
|
9
|
+
' * a step']
|
|
10
|
+
source = source.join("\n")
|
|
11
|
+
|
|
12
|
+
scenario = CucumberAnalytics::Scenario.new(source)
|
|
13
|
+
step = scenario.steps.first
|
|
14
|
+
|
|
15
|
+
step.parent_element.should equal scenario
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
SimpleCov.command_name('Step') unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
|
+
|
|
5
|
+
describe 'Step, Integration' do
|
|
6
|
+
|
|
7
|
+
it 'properly sets its child elements' do
|
|
8
|
+
source_1 = ['* a step',
|
|
9
|
+
'"""',
|
|
10
|
+
'a doc string',
|
|
11
|
+
'"""']
|
|
12
|
+
source_2 = ['* a step',
|
|
13
|
+
'| a block|']
|
|
14
|
+
|
|
15
|
+
step_1 = CucumberAnalytics::Step.new(source_1.join("\n"))
|
|
16
|
+
step_2 = CucumberAnalytics::Step.new(source_2.join("\n"))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
doc_string = step_1.block
|
|
20
|
+
table = step_2.block
|
|
21
|
+
|
|
22
|
+
doc_string.parent_element.should equal step_1
|
|
23
|
+
table.parent_element.should equal step_2
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'defaults to the World delimiters if its own are not set' do
|
|
27
|
+
world = CucumberAnalytics::World
|
|
28
|
+
world.left_delimiter = '"'
|
|
29
|
+
world.right_delimiter = '"'
|
|
30
|
+
|
|
31
|
+
step = CucumberAnalytics::Step.new
|
|
32
|
+
step.right_delimiter = nil
|
|
33
|
+
step.left_delimiter = nil
|
|
34
|
+
|
|
35
|
+
step.right_delimiter.should == '"'
|
|
36
|
+
step.left_delimiter.should == '"'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'attempts to determine its arguments during creation' do
|
|
40
|
+
source = 'Given a test step with *parameter 1* and "parameter 2" and *parameter 3*'
|
|
41
|
+
|
|
42
|
+
world = CucumberAnalytics::World
|
|
43
|
+
world.left_delimiter = '"'
|
|
44
|
+
world.right_delimiter = '"'
|
|
45
|
+
|
|
46
|
+
step = CucumberAnalytics::Step.new(source)
|
|
47
|
+
|
|
48
|
+
step.arguments.should == ['parameter 2']
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'finds nothing when no regular expression or delimiters are available' do
|
|
52
|
+
world = CucumberAnalytics::World
|
|
53
|
+
world.left_delimiter = nil
|
|
54
|
+
world.right_delimiter = nil
|
|
55
|
+
|
|
56
|
+
source = 'Given a test step with *parameter 1* and "parameter 2" and *parameter 3*'
|
|
57
|
+
step = CucumberAnalytics::Step.new(source)
|
|
58
|
+
|
|
59
|
+
step.scan_arguments
|
|
60
|
+
|
|
61
|
+
step.arguments.should == []
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'can determine its equality with another Step' do
|
|
65
|
+
source_1 = "Given a test step with *parameter 1* and *parameter 2*\n|a block|"
|
|
66
|
+
source_2 = "Given a test step with *parameter 3* and *parameter 4*\n|another block|"
|
|
67
|
+
source_3 = 'Given a different *parameterized* step'
|
|
68
|
+
|
|
69
|
+
step_1 = CucumberAnalytics::Step.new(source_1)
|
|
70
|
+
step_2 = CucumberAnalytics::Step.new(source_2)
|
|
71
|
+
step_3 = CucumberAnalytics::Step.new(source_3)
|
|
72
|
+
|
|
73
|
+
step_1.delimiter = '*'
|
|
74
|
+
step_2.delimiter = '*'
|
|
75
|
+
step_3.delimiter = '*'
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
(step_1 == step_2).should be_true
|
|
79
|
+
(step_1 == step_3).should be_false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context '#step_text ' do
|
|
83
|
+
|
|
84
|
+
before(:each) do
|
|
85
|
+
source = "Given a test step with -parameter 1- ^and@ *parameter 2!!\n|a block|"
|
|
86
|
+
@step = CucumberAnalytics::Step.new(source)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
it 'returns the step\'s entire text by default' do
|
|
91
|
+
source = "Given a test step with -parameter 1- ^and@ *parameter 2!!\n|a block|"
|
|
92
|
+
step_with_block = CucumberAnalytics::Step.new(source)
|
|
93
|
+
|
|
94
|
+
expected_output = ['Given a test step with -parameter 1- ^and@ *parameter 2!!',
|
|
95
|
+
'|a block|']
|
|
96
|
+
|
|
97
|
+
step_with_block.step_text.should == expected_output
|
|
98
|
+
|
|
99
|
+
source = 'Given a test step with -parameter 1- ^and@ *parameter 2!!'
|
|
100
|
+
step_without_block = CucumberAnalytics::Step.new(source)
|
|
101
|
+
|
|
102
|
+
expected_output = ['Given a test step with -parameter 1- ^and@ *parameter 2!!']
|
|
103
|
+
|
|
104
|
+
step_without_block.step_text.should == expected_output
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'can provide the step\'s text without the keyword' do
|
|
108
|
+
expected_output = ['a test step with -parameter 1- ^and@ *parameter 2!!',
|
|
109
|
+
'|a block|']
|
|
110
|
+
|
|
111
|
+
@step.step_text(with_keywords: false).should == expected_output
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|