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.
Files changed (94) hide show
  1. checksums.yaml +15 -0
  2. data/History.rdoc +16 -0
  3. data/README.rdoc +5 -3
  4. data/Rakefile +7 -2
  5. data/cucumber_analytics.gemspec +7 -5
  6. data/features/analysis/step_collection.feature +44 -45
  7. data/features/modeling/background_modeling.feature +14 -144
  8. data/features/modeling/directory_modeling.feature +3 -2
  9. data/features/modeling/doc_string_modeling.feature +46 -0
  10. data/features/modeling/example_modeling.feature +13 -34
  11. data/features/modeling/feature_file_modeling.feature +3 -2
  12. data/features/modeling/feature_modeling.feature +18 -80
  13. data/features/modeling/outline_modeling.feature +25 -164
  14. data/features/modeling/scenario_modeling.feature +17 -144
  15. data/features/modeling/step_modeling.feature +68 -0
  16. data/features/modeling/table_modeling.feature +41 -0
  17. data/features/step_definitions/background_steps.rb +12 -11
  18. data/features/step_definitions/directory_steps.rb +6 -3
  19. data/features/step_definitions/doc_string_steps.rb +50 -0
  20. data/features/step_definitions/{file_steps.rb → feature_file_steps.rb} +8 -2
  21. data/features/step_definitions/feature_steps.rb +8 -4
  22. data/features/step_definitions/outline_steps.rb +12 -6
  23. data/features/step_definitions/setup_steps.rb +2 -2
  24. data/features/step_definitions/spec_steps.rb +6 -3
  25. data/features/step_definitions/step_steps.rb +91 -0
  26. data/features/step_definitions/table_steps.rb +10 -0
  27. data/features/step_definitions/test_steps.rb +6 -10
  28. data/features/step_definitions/world_steps.rb +28 -19
  29. data/features/support/env.rb +0 -2
  30. data/lib/cucumber_analytics/background.rb +16 -0
  31. data/lib/cucumber_analytics/containing.rb +18 -0
  32. data/lib/cucumber_analytics/directory.rb +83 -0
  33. data/lib/cucumber_analytics/doc_string.rb +55 -0
  34. data/lib/cucumber_analytics/example.rb +100 -0
  35. data/lib/cucumber_analytics/feature.rb +120 -0
  36. data/lib/cucumber_analytics/feature_element.rb +22 -40
  37. data/lib/cucumber_analytics/feature_file.rb +74 -0
  38. data/lib/cucumber_analytics/outline.rb +49 -0
  39. data/lib/cucumber_analytics/parsing.rb +30 -0
  40. data/lib/cucumber_analytics/scenario.rb +31 -0
  41. data/lib/cucumber_analytics/step.rb +142 -32
  42. data/lib/cucumber_analytics/table.rb +51 -0
  43. data/lib/cucumber_analytics/taggable.rb +35 -0
  44. data/lib/cucumber_analytics/test_element.rb +36 -91
  45. data/lib/cucumber_analytics/version.rb +1 -1
  46. data/lib/cucumber_analytics/world.rb +109 -153
  47. data/lib/cucumber_analytics.rb +12 -8
  48. data/spec/integration/background_integration_spec.rb +18 -0
  49. data/spec/integration/directory_integration_spec.rb +24 -0
  50. data/spec/{feature_spec.rb → integration/feature_file_integration_spec.rb} +5 -5
  51. data/spec/integration/feature_integration_spec.rb +86 -0
  52. data/spec/integration/outline_integration_spec.rb +22 -0
  53. data/spec/integration/scenario_integration_spec.rb +18 -0
  54. data/spec/integration/step_integration_spec.rb +116 -0
  55. data/spec/integration/world_integration_spec.rb +40 -0
  56. data/spec/spec_helper.rb +7 -3
  57. data/spec/unit/background_unit_spec.rb +22 -0
  58. data/spec/unit/bare_bones_unit_specs.rb +13 -0
  59. data/spec/unit/containing_element_unit_specs.rb +17 -0
  60. data/spec/unit/directory_unit_spec.rb +91 -0
  61. data/spec/unit/doc_string_unit_spec.rb +65 -0
  62. data/spec/unit/example_unit_spec.rb +171 -0
  63. data/spec/unit/feature_element_unit_spec.rb +19 -0
  64. data/spec/unit/feature_element_unit_specs.rb +39 -0
  65. data/spec/unit/feature_file_unit_spec.rb +82 -0
  66. data/spec/unit/feature_unit_spec.rb +81 -0
  67. data/spec/unit/nested_element_unit_specs.rb +24 -0
  68. data/spec/unit/outline_unit_spec.rb +56 -0
  69. data/spec/unit/parsing_unit_spec.rb +21 -0
  70. data/spec/unit/prepopulated_unit_specs.rb +13 -0
  71. data/spec/unit/scenario_unit_spec.rb +36 -0
  72. data/spec/unit/step_unit_spec.rb +231 -0
  73. data/spec/unit/table_unit_spec.rb +52 -0
  74. data/spec/unit/taggable_unit_spec.rb +63 -0
  75. data/spec/unit/tagged_element_unit_specs.rb +48 -0
  76. data/spec/unit/test_element_unit_spec.rb +40 -0
  77. data/spec/unit/test_element_unit_specs.rb +31 -0
  78. data/spec/unit/world_unit_spec.rb +167 -0
  79. metadata +106 -41
  80. data/lib/cucumber_analytics/logging.rb +0 -28
  81. data/lib/cucumber_analytics/outline_example.rb +0 -110
  82. data/lib/cucumber_analytics/parsed_background.rb +0 -45
  83. data/lib/cucumber_analytics/parsed_directory.rb +0 -78
  84. data/lib/cucumber_analytics/parsed_feature.rb +0 -97
  85. data/lib/cucumber_analytics/parsed_file.rb +0 -199
  86. data/lib/cucumber_analytics/parsed_scenario.rb +0 -67
  87. data/lib/cucumber_analytics/parsed_scenario_outline.rb +0 -122
  88. data/spec/background_spec.rb +0 -23
  89. data/spec/directory_spec.rb +0 -18
  90. data/spec/example_spec.rb +0 -37
  91. data/spec/file_spec.rb +0 -20
  92. data/spec/outline_spec.rb +0 -32
  93. data/spec/scenario_spec.rb +0 -33
  94. 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
- SANITARY_STRING = '___!!!___'
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
- # Returns the left delimiter, which is used to mark the beginning of a step
11
- # argument.
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
- # Sets the left delimiter that will be used by default when determining
17
- # step arguments.
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
- # Returns the right delimiter, which is used to mark the end of a step
23
- # argument.
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
- # Sets the right delimiter that will be used by default when determining
29
- # step arguments.
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
- File.open(file_path, 'r') do |file|
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
- # Returns the step patterns that have been loaded into the World.
49
- def self.defined_step_patterns
50
- @@defined_expressions
51
- end
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
- # Returns all directories found in the passed container.
61
- def self.directories_in(container)
62
- Array.new.tap do |accumulated_directories|
63
- collect_directories(accumulated_directories, container)
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
- # Returns all feature files found in the passed container.
68
- def self.files_in(container)
69
- Array.new.tap do |accumulated_files|
70
- collect_files(accumulated_files, container)
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
- # Returns all features found in the passed container.
75
- def self.features_in(container)
76
- Array.new.tap do |accumulated_features|
77
- collect_features(accumulated_features, container)
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
- # Returns all tests found in the passed container.
82
- def self.tests_in(container)
83
- Array.new.tap do |accumulated_tests|
84
- collect_tests(accumulated_tests, container)
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
- # Returns all steps found in the passed container.
89
- def self.steps_in(container)
90
- Array.new.tap do |accumulated_steps|
91
- collect_steps(accumulated_steps, container)
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
- # Returns all undefined steps found in the passed container.
96
- def self.undefined_steps_in(container)
97
- all_steps = steps_in(container)
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
- # Returns all defined steps found in the passed container.
103
- def self.defined_steps_in(container)
104
- all_steps = steps_in(container)
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
- all_steps.select { |step| World.defined_step_patterns.any? { |pattern| step.base =~ Regexp.new(pattern) } }
107
- end
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
- private
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
- # Make life easier by ensuring that the only forward slashes in the
114
- # regular expression are the important ones.
115
- def self.sanitize_line(line)
116
- line.gsub('\/', SANITARY_STRING)
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
- # And be sure to restore the line to its original state.
120
- def self.desanitize_line(line)
121
- line.gsub(SANITARY_STRING, '\/')
122
- end
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
- # Returns whether or not the passed line is a step pattern.
125
- def self.step_def_line?(line)
126
- !!(sanitize_line(line) =~ /^#{World::STEP_KEYWORD_PATTERN}\/[^\/]*\//)
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
- # Returns the regular expression portion of a step pattern line.
130
- def self.extract_regular_expression(line)
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
- # Recursively gathers all tags found in the passed container.
135
- def self.collect_tags(accumulated_tags, container)
136
- accumulated_tags.concat container.tags if container.respond_to?(:tags)
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
- if container.respond_to?(:contains)
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
- if container.respond_to?(:contains)
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
- if container.respond_to?(:contains)
161
- container.contains.each do |child_container|
162
- collect_files(accumulated_files, child_container)
163
- end
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
- # Recursively gathers all features found in the passed container.
168
- def self.collect_features(accumulated_features, container)
169
- accumulated_features << container.feature if container.respond_to?(:feature) && container.feature
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
- if container.respond_to?(:contains)
172
- container.contains.each do |child_container|
173
- collect_features(accumulated_features, child_container)
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
- # Recursively gathers all tests found in the passed container.
179
- def self.collect_tests(accumulated_tests, container)
180
- accumulated_tests.concat container.tests if container.respond_to?(:tests)
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
- if container.respond_to?(:contains)
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
- # Recursively gathers all steps found in the passed container.
190
- def self.collect_steps(accumulated_steps, container)
191
- accumulated_steps.concat container.steps if container.respond_to?(:steps)
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
- if container.respond_to?(:contains)
194
- container.contains.each do |child_container|
195
- collect_steps(accumulated_steps, child_container)
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
@@ -1,13 +1,17 @@
1
1
  require 'cucumber_analytics/version'
2
- require 'cucumber_analytics/logging'
3
- require 'cucumber_analytics/parsed_file'
4
- require 'cucumber_analytics/parsed_directory'
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/parsed_feature'
8
+ require 'cucumber_analytics/feature'
7
9
  require 'cucumber_analytics/test_element.rb'
8
- require 'cucumber_analytics/parsed_background'
9
- require 'cucumber_analytics/parsed_scenario'
10
- require 'cucumber_analytics/parsed_scenario_outline'
11
- require 'cucumber_analytics/outline_example'
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('ParsedFeature') unless RUBY_VERSION.to_s < '1.9.0'
3
+ SimpleCov.command_name('FeatureFile') unless RUBY_VERSION.to_s < '1.9.0'
4
4
 
5
- describe "ParsedFeature" do
5
+ describe 'FeatureFile, Integration' do
6
6
 
7
- it 'knows its parent element' do
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::ParsedFile.new(file_path)
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