cuke_modeler 0.4.1 → 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 (252) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/.travis.yml +1 -1
  4. data/Gemfile +4 -0
  5. data/History.rdoc +71 -3
  6. data/LICENSE.txt +22 -22
  7. data/README.md +24 -10
  8. data/Rakefile +2 -12
  9. data/cuke_modeler.gemspec +1 -1
  10. data/features/analysis/test_comparison.feature +37 -122
  11. data/features/modeling/background_modeling.feature +77 -0
  12. data/features/modeling/background_output.feature +42 -0
  13. data/features/modeling/cell_modeling.feature +23 -0
  14. data/features/modeling/cell_output.feature +22 -0
  15. data/features/modeling/directory_modeling.feature +65 -0
  16. data/features/modeling/directory_output.feature +12 -0
  17. data/features/modeling/doc_string_modeling.feature +61 -0
  18. data/features/modeling/doc_string_output.feature +32 -0
  19. data/features/modeling/example_modeling.feature +125 -0
  20. data/features/modeling/example_output.feature +39 -0
  21. data/features/modeling/feature_file_modeling.feature +40 -0
  22. data/features/modeling/feature_file_output.feature +12 -0
  23. data/features/modeling/feature_modeling.feature +109 -0
  24. data/features/modeling/feature_output.feature +104 -0
  25. data/features/modeling/model_output.feature +22 -0
  26. data/features/modeling/model_structure.feature +48 -0
  27. data/features/modeling/outline_modeling.feature +144 -0
  28. data/features/modeling/outline_output.feature +69 -0
  29. data/features/modeling/row_modeling.feature +48 -0
  30. data/features/modeling/row_output.feature +22 -0
  31. data/features/modeling/scenario_modeling.feature +118 -0
  32. data/features/modeling/scenario_output.feature +45 -0
  33. data/features/modeling/step_modeling.feature +84 -0
  34. data/features/modeling/step_output.feature +29 -0
  35. data/features/modeling/table_modeling.feature +50 -0
  36. data/features/modeling/table_output.feature +24 -0
  37. data/features/modeling/tag_modeling.feature +43 -0
  38. data/features/modeling/tag_output.feature +22 -0
  39. data/features/step_definitions/action_steps.rb +11 -1
  40. data/features/step_definitions/background_steps.rb +1 -85
  41. data/features/step_definitions/directory_steps.rb +2 -48
  42. data/features/step_definitions/doc_string_steps.rb +1 -67
  43. data/features/step_definitions/feature_file_steps.rb +2 -37
  44. data/features/step_definitions/feature_steps.rb +4 -100
  45. data/features/step_definitions/modeling_steps.rb +44 -0
  46. data/features/step_definitions/setup_steps.rb +19 -41
  47. data/features/step_definitions/step_steps.rb +2 -166
  48. data/features/step_definitions/table_steps.rb +1 -58
  49. data/features/step_definitions/tag_steps.rb +2 -72
  50. data/features/step_definitions/verification_steps.rb +152 -4
  51. data/features/support/env.rb +4 -6
  52. data/gemfiles/{gherkin.gemfile → gherkin2.gemfile} +4 -0
  53. data/gemfiles/gherkin3.gemfile +4 -0
  54. data/gemfiles/gherkin4.gemfile +4 -0
  55. data/lib/cuke_modeler.rb +24 -22
  56. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +103 -31
  57. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +103 -40
  58. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +111 -50
  59. data/lib/cuke_modeler/containing.rb +255 -4
  60. data/lib/cuke_modeler/described.rb +28 -0
  61. data/lib/cuke_modeler/models/background.rb +66 -0
  62. data/lib/cuke_modeler/models/cell.rb +48 -0
  63. data/lib/cuke_modeler/models/directory.rb +95 -0
  64. data/lib/cuke_modeler/models/doc_string.rb +59 -0
  65. data/lib/cuke_modeler/models/example.rb +167 -0
  66. data/lib/cuke_modeler/models/feature.rb +106 -0
  67. data/lib/cuke_modeler/models/feature_file.rb +64 -0
  68. data/lib/cuke_modeler/models/model.rb +32 -0
  69. data/lib/cuke_modeler/models/outline.rb +79 -0
  70. data/lib/cuke_modeler/models/row.rb +49 -0
  71. data/lib/cuke_modeler/models/scenario.rb +69 -0
  72. data/lib/cuke_modeler/models/step.rb +68 -0
  73. data/lib/cuke_modeler/models/table.rb +67 -0
  74. data/lib/cuke_modeler/models/tag.rb +46 -0
  75. data/lib/cuke_modeler/named.rb +19 -0
  76. data/lib/cuke_modeler/nested.rb +22 -15
  77. data/lib/cuke_modeler/parsed.rb +11 -0
  78. data/lib/cuke_modeler/parsing.rb +66 -83
  79. data/lib/cuke_modeler/sourceable.rb +3 -11
  80. data/lib/cuke_modeler/stepped.rb +24 -0
  81. data/lib/cuke_modeler/taggable.rb +6 -29
  82. data/lib/cuke_modeler/version.rb +2 -1
  83. data/spec/integration/background_integration_spec.rb +332 -7
  84. data/spec/integration/cell_integration_spec.rb +321 -0
  85. data/spec/integration/directory_integration_spec.rb +175 -9
  86. data/spec/integration/doc_string_integration_spec.rb +318 -7
  87. data/spec/integration/example_integration_spec.rb +602 -19
  88. data/spec/integration/feature_file_integration_spec.rb +98 -3
  89. data/spec/integration/feature_integration_spec.rb +445 -27
  90. data/spec/integration/gherkin_2_adapter_spec.rb +122 -0
  91. data/spec/integration/gherkin_3_adapter_spec.rb +125 -0
  92. data/spec/integration/gherkin_4_adapter_spec.rb +123 -0
  93. data/spec/integration/model_integration_spec.rb +15 -0
  94. data/spec/integration/nested_integration_spec.rb +91 -0
  95. data/spec/integration/outline_integration_spec.rb +485 -12
  96. data/spec/integration/parsing_integration_spec.rb +85 -0
  97. data/spec/integration/row_integration_spec.rb +221 -18
  98. data/spec/integration/scenario_integration_spec.rb +368 -14
  99. data/spec/integration/shared/models_integration_specs.rb +18 -0
  100. data/spec/integration/step_integration_spec.rb +328 -77
  101. data/spec/integration/table_integration_spec.rb +242 -20
  102. data/spec/integration/tag_integration_spec.rb +178 -13
  103. data/spec/spec_helper.rb +32 -18
  104. data/spec/unit/background_unit_spec.rb +24 -44
  105. data/spec/unit/cell_unit_spec.rb +73 -0
  106. data/spec/unit/described_unit_spec.rb +23 -0
  107. data/spec/unit/directory_unit_spec.rb +52 -62
  108. data/spec/unit/doc_string_unit_spec.rb +47 -100
  109. data/spec/unit/example_unit_spec.rb +50 -296
  110. data/spec/unit/feature_file_unit_spec.rb +53 -52
  111. data/spec/unit/feature_unit_spec.rb +39 -83
  112. data/spec/unit/model_unit_spec.rb +15 -0
  113. data/spec/unit/named_unit_spec.rb +23 -0
  114. data/spec/unit/nested_unit_spec.rb +24 -21
  115. data/spec/unit/outline_unit_spec.rb +46 -69
  116. data/spec/unit/parsed_unit_spec.rb +27 -0
  117. data/spec/unit/parsing_unit_spec.rb +2 -70
  118. data/spec/unit/row_unit_spec.rb +22 -51
  119. data/spec/unit/scenario_unit_spec.rb +27 -59
  120. data/spec/unit/{bare_bones_unit_specs.rb → shared/bare_bones_models_unit_specs.rb} +2 -2
  121. data/spec/unit/shared/containing_models_unit_specs.rb +18 -0
  122. data/spec/unit/shared/described_models_unit_specs.rb +38 -0
  123. data/spec/unit/shared/models_unit_specs.rb +15 -0
  124. data/spec/unit/shared/named_models_unit_specs.rb +39 -0
  125. data/spec/unit/shared/nested_models_unit_specs.rb +51 -0
  126. data/spec/unit/shared/parsed_models_unit_specs.rb +39 -0
  127. data/spec/unit/shared/prepopulated_models_unit_specs.rb +18 -0
  128. data/spec/unit/shared/sourced_models_unit_specs.rb +39 -0
  129. data/spec/unit/shared/stepped_models_unit_specs.rb +46 -0
  130. data/spec/unit/shared/stringifiable_models_unit_specs.rb +18 -0
  131. data/spec/unit/shared/tagged_models_unit_specs.rb +72 -0
  132. data/spec/unit/sourceable_unit_spec.rb +12 -4
  133. data/spec/unit/step_unit_spec.rb +40 -231
  134. data/spec/unit/stepped_unit_spec.rb +23 -0
  135. data/spec/unit/table_unit_spec.rb +27 -89
  136. data/spec/unit/tag_unit_spec.rb +30 -53
  137. data/spec/unit/taggable_unit_spec.rb +26 -42
  138. data/todo.txt +32 -0
  139. metadata +135 -217
  140. data/features/analysis/test_manipulation.feature +0 -37
  141. data/features/modeling/gherkin/background_modeling.feature +0 -65
  142. data/features/modeling/gherkin/background_output.feature +0 -131
  143. data/features/modeling/gherkin/directory_modeling.feature +0 -110
  144. data/features/modeling/gherkin/directory_output.feature +0 -14
  145. data/features/modeling/gherkin/doc_string_modeling.feature +0 -53
  146. data/features/modeling/gherkin/doc_string_output.feature +0 -72
  147. data/features/modeling/gherkin/example_modeling.feature +0 -101
  148. data/features/modeling/gherkin/example_output.feature +0 -193
  149. data/features/modeling/gherkin/feature_file_modeling.feature +0 -54
  150. data/features/modeling/gherkin/feature_file_output.feature +0 -14
  151. data/features/modeling/gherkin/feature_modeling.feature +0 -154
  152. data/features/modeling/gherkin/feature_output.feature +0 -245
  153. data/features/modeling/gherkin/outline_modeling.feature +0 -90
  154. data/features/modeling/gherkin/outline_output.feature +0 -198
  155. data/features/modeling/gherkin/row_modeling.feature +0 -68
  156. data/features/modeling/gherkin/row_output.feature +0 -28
  157. data/features/modeling/gherkin/scenario_modeling.feature +0 -79
  158. data/features/modeling/gherkin/scenario_output.feature +0 -148
  159. data/features/modeling/gherkin/step_modeling.feature +0 -75
  160. data/features/modeling/gherkin/step_output.feature +0 -53
  161. data/features/modeling/gherkin/table_modeling.feature +0 -42
  162. data/features/modeling/gherkin/table_output.feature +0 -43
  163. data/features/modeling/gherkin/table_row_modeling.feature +0 -57
  164. data/features/modeling/gherkin/table_row_output.feature +0 -28
  165. data/features/modeling/gherkin/tag_modeling.feature +0 -48
  166. data/features/modeling/gherkin/tag_output.feature +0 -17
  167. data/features/modeling/gherkin3/background_modeling.feature +0 -64
  168. data/features/modeling/gherkin3/background_output.feature +0 -131
  169. data/features/modeling/gherkin3/directory_modeling.feature +0 -110
  170. data/features/modeling/gherkin3/directory_output.feature +0 -14
  171. data/features/modeling/gherkin3/doc_string_modeling.feature +0 -53
  172. data/features/modeling/gherkin3/doc_string_output.feature +0 -72
  173. data/features/modeling/gherkin3/example_modeling.feature +0 -100
  174. data/features/modeling/gherkin3/example_output.feature +0 -207
  175. data/features/modeling/gherkin3/feature_file_modeling.feature +0 -54
  176. data/features/modeling/gherkin3/feature_file_output.feature +0 -14
  177. data/features/modeling/gherkin3/feature_modeling.feature +0 -155
  178. data/features/modeling/gherkin3/feature_output.feature +0 -249
  179. data/features/modeling/gherkin3/outline_modeling.feature +0 -89
  180. data/features/modeling/gherkin3/outline_output.feature +0 -255
  181. data/features/modeling/gherkin3/row_modeling.feature +0 -68
  182. data/features/modeling/gherkin3/row_output.feature +0 -28
  183. data/features/modeling/gherkin3/scenario_modeling.feature +0 -78
  184. data/features/modeling/gherkin3/scenario_output.feature +0 -148
  185. data/features/modeling/gherkin3/step_modeling.feature +0 -75
  186. data/features/modeling/gherkin3/step_output.feature +0 -53
  187. data/features/modeling/gherkin3/table_modeling.feature +0 -42
  188. data/features/modeling/gherkin3/table_output.feature +0 -43
  189. data/features/modeling/gherkin3/table_row_modeling.feature +0 -57
  190. data/features/modeling/gherkin3/table_row_output.feature +0 -28
  191. data/features/modeling/gherkin3/tag_modeling.feature +0 -49
  192. data/features/modeling/gherkin3/tag_output.feature +0 -17
  193. data/features/modeling/gherkin4/background_modeling.feature +0 -64
  194. data/features/modeling/gherkin4/background_output.feature +0 -131
  195. data/features/modeling/gherkin4/directory_modeling.feature +0 -110
  196. data/features/modeling/gherkin4/directory_output.feature +0 -14
  197. data/features/modeling/gherkin4/doc_string_modeling.feature +0 -53
  198. data/features/modeling/gherkin4/doc_string_output.feature +0 -72
  199. data/features/modeling/gherkin4/example_modeling.feature +0 -100
  200. data/features/modeling/gherkin4/example_output.feature +0 -193
  201. data/features/modeling/gherkin4/feature_file_modeling.feature +0 -54
  202. data/features/modeling/gherkin4/feature_file_output.feature +0 -14
  203. data/features/modeling/gherkin4/feature_modeling.feature +0 -153
  204. data/features/modeling/gherkin4/feature_output.feature +0 -245
  205. data/features/modeling/gherkin4/outline_modeling.feature +0 -89
  206. data/features/modeling/gherkin4/outline_output.feature +0 -198
  207. data/features/modeling/gherkin4/row_modeling.feature +0 -68
  208. data/features/modeling/gherkin4/row_output.feature +0 -28
  209. data/features/modeling/gherkin4/scenario_modeling.feature +0 -78
  210. data/features/modeling/gherkin4/scenario_output.feature +0 -148
  211. data/features/modeling/gherkin4/step_modeling.feature +0 -75
  212. data/features/modeling/gherkin4/step_output.feature +0 -53
  213. data/features/modeling/gherkin4/table_modeling.feature +0 -42
  214. data/features/modeling/gherkin4/table_output.feature +0 -43
  215. data/features/modeling/gherkin4/table_row_modeling.feature +0 -57
  216. data/features/modeling/gherkin4/table_row_output.feature +0 -28
  217. data/features/modeling/gherkin4/tag_modeling.feature +0 -48
  218. data/features/modeling/gherkin4/tag_output.feature +0 -17
  219. data/features/step_definitions/outline_steps.rb +0 -258
  220. data/features/step_definitions/test_steps.rb +0 -123
  221. data/lib/cuke_modeler/background.rb +0 -38
  222. data/lib/cuke_modeler/directory.rb +0 -83
  223. data/lib/cuke_modeler/doc_string.rb +0 -87
  224. data/lib/cuke_modeler/example.rb +0 -195
  225. data/lib/cuke_modeler/feature.rb +0 -147
  226. data/lib/cuke_modeler/feature_element.rb +0 -73
  227. data/lib/cuke_modeler/feature_file.rb +0 -77
  228. data/lib/cuke_modeler/outline.rb +0 -68
  229. data/lib/cuke_modeler/raw.rb +0 -20
  230. data/lib/cuke_modeler/row.rb +0 -64
  231. data/lib/cuke_modeler/scenario.rb +0 -45
  232. data/lib/cuke_modeler/step.rb +0 -216
  233. data/lib/cuke_modeler/table.rb +0 -90
  234. data/lib/cuke_modeler/table_row.rb +0 -64
  235. data/lib/cuke_modeler/tag.rb +0 -62
  236. data/lib/cuke_modeler/test_element.rb +0 -79
  237. data/lib/cuke_modeler/world.rb +0 -113
  238. data/spec/integration/table_row_integration_spec.rb +0 -76
  239. data/spec/integration/world_integration_spec.rb +0 -14
  240. data/spec/unit/containing_element_unit_specs.rb +0 -18
  241. data/spec/unit/feature_element_unit_spec.rb +0 -19
  242. data/spec/unit/feature_element_unit_specs.rb +0 -52
  243. data/spec/unit/nested_element_unit_specs.rb +0 -39
  244. data/spec/unit/prepopulated_unit_specs.rb +0 -14
  245. data/spec/unit/raw_element_unit_specs.rb +0 -27
  246. data/spec/unit/raw_unit_spec.rb +0 -28
  247. data/spec/unit/sourced_element_unit_specs.rb +0 -18
  248. data/spec/unit/table_row_unit_spec.rb +0 -102
  249. data/spec/unit/tagged_element_unit_specs.rb +0 -67
  250. data/spec/unit/test_element_unit_spec.rb +0 -54
  251. data/spec/unit/test_element_unit_specs.rb +0 -34
  252. data/spec/unit/world_unit_spec.rb +0 -140
@@ -6,17 +6,15 @@ end
6
6
  require 'test/unit/assertions'
7
7
  include Test::Unit::Assertions
8
8
 
9
- require File.dirname(__FILE__) + '/../../lib/cuke_modeler'
9
+ this_dir = File.dirname(__FILE__)
10
+
11
+ require "#{this_dir}/../../lib/cuke_modeler"
10
12
 
11
13
 
12
14
  Before do
13
15
  begin
14
- @default_file_directory = "#{File.dirname(__FILE__)}/../temp_files"
16
+ @default_file_directory = "#{this_dir}/../temp_files"
15
17
  @default_feature_file_name = 'test_feature.feature'
16
- @default_step_file_name = 'test_steps.rb'
17
- @test_file_directory = "#{File.dirname(__FILE__)}/../test_files"
18
- @test_step_file_location = "#{@default_file_directory}/#{@default_step_file_name}"
19
- @spec_directory = "#{File.dirname(__FILE__)}/../../spec"
20
18
 
21
19
  FileUtils.mkdir(@default_file_directory)
22
20
  rescue => e
@@ -13,6 +13,10 @@ elsif RUBY_VERSION =~ /^1\./
13
13
  gem 'cucumber', '>=1.0.0', '<2.0.0'
14
14
  end
15
15
 
16
+ if RUBY_VERSION =~ /^1\./
17
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
18
+ end
19
+
16
20
  if RUBY_VERSION =~ /^2\.[23456789]/
17
21
  gem 'test-unit'
18
22
  end
@@ -11,6 +11,10 @@ if RUBY_VERSION =~ /^1\.8/
11
11
  gem 'rake', '< 11.0' # Rake dropped 1.8.x support after this version
12
12
  end
13
13
 
14
+ if RUBY_VERSION =~ /^1\./
15
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
16
+ end
17
+
14
18
  if RUBY_VERSION =~ /^2\.[23456789]/
15
19
  gem 'test-unit'
16
20
  end
@@ -11,6 +11,10 @@ if RUBY_VERSION =~ /^1\.8/
11
11
  gem 'rake', '< 11.0' # Rake dropped 1.8.x support after this version
12
12
  end
13
13
 
14
+ if RUBY_VERSION =~ /^1\./
15
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
16
+ end
17
+
14
18
  if RUBY_VERSION =~ /^2\.[23456789]/
15
19
  gem 'test-unit'
16
20
  end
data/lib/cuke_modeler.rb CHANGED
@@ -1,29 +1,31 @@
1
+ # The top level namespace used by this gem
2
+
3
+ module CukeModeler
4
+ end
5
+
6
+
1
7
  require "cuke_modeler/version"
2
8
 
3
9
  require 'cuke_modeler/parsing'
4
10
  require 'cuke_modeler/containing'
5
11
  require 'cuke_modeler/taggable'
6
- require 'cuke_modeler/raw'
12
+ require 'cuke_modeler/parsed'
7
13
  require 'cuke_modeler/sourceable'
8
14
  require 'cuke_modeler/nested'
9
- require 'cuke_modeler/feature_file'
10
- require 'cuke_modeler/directory'
11
- require 'cuke_modeler/feature_element.rb'
12
- require 'cuke_modeler/feature'
13
- require 'cuke_modeler/test_element.rb'
14
- require 'cuke_modeler/background'
15
- require 'cuke_modeler/scenario'
16
- require 'cuke_modeler/outline'
17
- require 'cuke_modeler/example'
18
- require 'cuke_modeler/step'
19
- require 'cuke_modeler/doc_string'
20
- require 'cuke_modeler/table'
21
- require 'cuke_modeler/world'
22
- require 'cuke_modeler/row'
23
- require 'cuke_modeler/table_row'
24
- require 'cuke_modeler/tag'
25
-
26
-
27
- module CukeModeler
28
- # Your code goes here...
29
- end
15
+ require 'cuke_modeler/named'
16
+ require 'cuke_modeler/described'
17
+ require 'cuke_modeler/stepped'
18
+ require 'cuke_modeler/models/model'
19
+ require 'cuke_modeler/models/feature_file'
20
+ require 'cuke_modeler/models/directory'
21
+ require 'cuke_modeler/models/feature'
22
+ require 'cuke_modeler/models/background'
23
+ require 'cuke_modeler/models/scenario'
24
+ require 'cuke_modeler/models/outline'
25
+ require 'cuke_modeler/models/example'
26
+ require 'cuke_modeler/models/step'
27
+ require 'cuke_modeler/models/doc_string'
28
+ require 'cuke_modeler/models/table'
29
+ require 'cuke_modeler/models/row'
30
+ require 'cuke_modeler/models/tag'
31
+ require 'cuke_modeler/models/cell'
@@ -1,7 +1,10 @@
1
1
  module CukeModeler
2
- class Gherkin2Adapter
3
2
 
3
+ # An adapter that can convert the output of version 2.x of the *gherkin* gem into input that is consumable by this gem.
4
+
5
+ class Gherkin2Adapter
4
6
 
7
+ # Adapts the given AST into the shape that this gem expects
5
8
  def adapt(parsed_ast)
6
9
  # An AST is just one feature
7
10
  adapt_feature!(parsed_ast.first) if parsed_ast.first
@@ -9,9 +12,15 @@ module CukeModeler
9
12
  parsed_ast
10
13
  end
11
14
 
15
+ # Adapts the AST sub-tree that is rooted at the given feature node.
12
16
  def adapt_feature!(parsed_feature)
13
17
  # Saving off the original data
14
- parsed_feature['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_feature))
18
+ parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature))
19
+
20
+ # Removing parsed data for child elements in order to avoid duplicating data
21
+ parsed_feature['cuke_modeler_parsing_data']['tags'] = nil
22
+ parsed_feature['cuke_modeler_parsing_data']['elements'] = nil
23
+
15
24
 
16
25
  adapt_child_elements!(parsed_feature)
17
26
 
@@ -22,27 +31,13 @@ module CukeModeler
22
31
  end
23
32
  end
24
33
 
25
- def adapt_child_elements!(parsed_feature)
26
- if parsed_feature['elements']
27
- parsed_feature['elements'].each do |element|
28
- case element['keyword']
29
- when 'Background'
30
- adapt_background!(element)
31
- when 'Scenario'
32
- adapt_scenario!(element)
33
- when 'Scenario Outline'
34
- adapt_outline!(element)
35
- else
36
- raise("Unknown element keyword: #{element['keyword']}")
37
- end
38
-
39
- end
40
- end
41
- end
42
-
34
+ # Adapts the AST sub-tree that is rooted at the given background node.
43
35
  def adapt_background!(parsed_background)
44
36
  # Saving off the original data
45
- parsed_background['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_background))
37
+ parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background))
38
+
39
+ # Removing parsed data for child elements in order to avoid duplicating data
40
+ parsed_background['cuke_modeler_parsing_data']['steps'] = nil
46
41
 
47
42
  if parsed_background['steps']
48
43
  parsed_background['steps'].each do |step|
@@ -51,9 +46,15 @@ module CukeModeler
51
46
  end
52
47
  end
53
48
 
49
+ # Adapts the AST sub-tree that is rooted at the given scenario node.
54
50
  def adapt_scenario!(parsed_scenario)
55
51
  # Saving off the original data
56
- parsed_scenario['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_scenario))
52
+ parsed_scenario['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_scenario))
53
+
54
+ # Removing parsed data for child elements in order to avoid duplicating data
55
+ parsed_scenario['cuke_modeler_parsing_data']['tags'] = nil
56
+ parsed_scenario['cuke_modeler_parsing_data']['steps'] = nil
57
+
57
58
 
58
59
  if parsed_scenario['tags']
59
60
  parsed_scenario['tags'].each do |tag|
@@ -68,9 +69,16 @@ module CukeModeler
68
69
  end
69
70
  end
70
71
 
72
+ # Adapts the AST sub-tree that is rooted at the given outline node.
71
73
  def adapt_outline!(parsed_outline)
72
74
  # Saving off the original data
73
- parsed_outline['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_outline))
75
+ parsed_outline['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_outline))
76
+
77
+ # Removing parsed data for child elements in order to avoid duplicating data
78
+ parsed_outline['cuke_modeler_parsing_data']['tags'] = nil
79
+ parsed_outline['cuke_modeler_parsing_data']['steps'] = nil
80
+ parsed_outline['cuke_modeler_parsing_data']['examples'] = nil
81
+
74
82
 
75
83
  if parsed_outline['tags']
76
84
  parsed_outline['tags'].each do |tag|
@@ -91,9 +99,15 @@ module CukeModeler
91
99
  end
92
100
  end
93
101
 
102
+ # Adapts the AST sub-tree that is rooted at the given example node.
94
103
  def adapt_example!(parsed_example)
95
104
  # Saving off the original data
96
- parsed_example['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_example))
105
+ parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example))
106
+
107
+ # Removing parsed data for child elements in order to avoid duplicating data
108
+ parsed_example['cuke_modeler_parsing_data']['tags'] = nil
109
+ parsed_example['cuke_modeler_parsing_data']['rows'] = nil
110
+
97
111
 
98
112
  parsed_example['rows'].each do |row|
99
113
  adapt_table_row!(row)
@@ -106,40 +120,98 @@ module CukeModeler
106
120
  end
107
121
  end
108
122
 
123
+ # Adapts the AST sub-tree that is rooted at the given tag node.
109
124
  def adapt_tag!(parsed_tag)
110
125
  # Saving off the original data
111
- parsed_tag['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_tag))
126
+ parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag))
112
127
  end
113
128
 
129
+ # Adapts the AST sub-tree that is rooted at the given step node.
114
130
  def adapt_step!(parsed_step)
115
131
  # Saving off the original data
116
- parsed_step['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step))
132
+ parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step))
133
+
134
+ # Removing parsed data for child elements in order to avoid duplicating data
135
+ parsed_step['cuke_modeler_parsing_data']['rows'] = nil if parsed_step['cuke_modeler_parsing_data']['rows']
136
+ parsed_step['cuke_modeler_parsing_data']['doc_string'] = nil if parsed_step['cuke_modeler_parsing_data']['doc_string']
137
+
117
138
 
118
139
  adapt_doc_string!(parsed_step['doc_string']) if parsed_step['doc_string']
119
140
 
120
141
  if parsed_step['rows']
121
- parsed_step['rows'] = {'rows' => parsed_step['rows']}
122
- adapt_step_table!(parsed_step['rows'])
142
+ parsed_step['table'] = {'rows' => parsed_step['rows']}
143
+ adapt_step_table!(parsed_step['table'])
123
144
  end
124
145
  end
125
146
 
147
+ # Adapts the AST sub-tree that is rooted at the given doc string node.
126
148
  def adapt_doc_string!(parsed_doc_string)
127
149
  # Saving off the original data
128
- parsed_doc_string['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_doc_string))
150
+ parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string))
129
151
  end
130
152
 
153
+ # Adapts the AST sub-tree that is rooted at the given table node.
131
154
  def adapt_step_table!(parsed_step_table)
132
155
  # Saving off the original data
133
- parsed_step_table['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step_table['rows']))
156
+ parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table['rows']))
157
+
158
+ # Removing parsed data for child elements in order to avoid duplicating data
159
+ parsed_step_table['cuke_modeler_parsing_data'].clear
160
+
161
+
162
+ parsed_step_table['line'] = parsed_step_table['rows'].first['line']
134
163
 
135
164
  parsed_step_table['rows'].each do |row|
136
165
  adapt_table_row!(row)
137
166
  end
138
167
  end
139
168
 
169
+ # Adapts the AST sub-tree that is rooted at the given row node.
140
170
  def adapt_table_row!(parsed_table_row)
141
171
  # Saving off the original data
142
- parsed_table_row['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_table_row))
172
+ parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row))
173
+
174
+ # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include
175
+ parsed_table_row['cuke_modeler_parsing_data']['cells'] = nil
176
+
177
+ parsed_table_row['cells'].collect! do |cell|
178
+ create_cell_for(cell, parsed_table_row['line'])
179
+ end
180
+ end
181
+
182
+ # Adapts the AST sub-tree that is rooted at the given cell node.
183
+ def create_cell_for(parsed_cell, line_number)
184
+ cell = {}
185
+
186
+ # Saving off the original data
187
+ cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell))
188
+
189
+ cell['value'] = parsed_cell
190
+ cell['line'] = line_number
191
+
192
+
193
+ cell
194
+ end
195
+
196
+
197
+ private
198
+
199
+
200
+ def adapt_child_elements!(parsed_feature)
201
+ if parsed_feature['elements']
202
+ parsed_feature['elements'].each do |element|
203
+ case element['keyword']
204
+ when 'Background'
205
+ adapt_background!(element)
206
+ when 'Scenario'
207
+ adapt_scenario!(element)
208
+ when 'Scenario Outline'
209
+ adapt_outline!(element)
210
+ else
211
+ raise("Unknown element keyword: #{element['keyword']}")
212
+ end
213
+ end
214
+ end
143
215
  end
144
216
 
145
217
  end
@@ -1,7 +1,10 @@
1
1
  module CukeModeler
2
- class Gherkin3Adapter
3
2
 
3
+ # An adapter that can convert the output of version 3.x of the *gherkin* gem into input that is consumable by this gem.
4
+
5
+ class Gherkin3Adapter
4
6
 
7
+ # Adapts the given AST into the shape that this gem expects
5
8
  def adapt(parsed_ast)
6
9
  # An AST is just one feature
7
10
  adapt_feature!(parsed_ast)
@@ -9,9 +12,15 @@ module CukeModeler
9
12
  [parsed_ast]
10
13
  end
11
14
 
15
+ # Adapts the AST sub-tree that is rooted at the given feature node.
12
16
  def adapt_feature!(parsed_feature)
13
17
  # Saving off the original data
14
- parsed_feature['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_feature))
18
+ parsed_feature['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_feature))
19
+
20
+ # Removing parsed data for child elements in order to avoid duplicating data
21
+ parsed_feature['cuke_modeler_parsing_data'][:tags] = nil
22
+ parsed_feature['cuke_modeler_parsing_data'][:scenarioDefinitions] = nil
23
+ parsed_feature['cuke_modeler_parsing_data'][:background] = nil
15
24
 
16
25
  parsed_feature['name'] = parsed_feature.delete(:name)
17
26
  parsed_feature['description'] = parsed_feature.delete(:description) || ''
@@ -29,14 +38,13 @@ module CukeModeler
29
38
  parsed_feature['tags'].concat(parsed_feature.delete(:tags))
30
39
  end
31
40
 
32
- def adapt_child_elements!(parsed_feature)
33
- adapt_background!(parsed_feature[:background]) if parsed_feature[:background]
34
- adapt_tests!(parsed_feature)
35
- end
36
-
41
+ # Adapts the AST sub-tree that is rooted at the given background node.
37
42
  def adapt_background!(parsed_background)
38
43
  # Saving off the original data
39
- parsed_background['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_background))
44
+ parsed_background['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_background))
45
+
46
+ # Removing parsed data for child elements in order to avoid duplicating data
47
+ parsed_background['cuke_modeler_parsing_data'][:steps] = nil
40
48
 
41
49
  parsed_background['keyword'] = parsed_background.delete(:type).to_s
42
50
  parsed_background['name'] = parsed_background.delete(:name)
@@ -50,30 +58,13 @@ module CukeModeler
50
58
  parsed_background['steps'].concat(parsed_background.delete(:steps))
51
59
  end
52
60
 
53
- def adapt_tests!(parsed_feature)
54
- parsed_feature[:scenarioDefinitions].each do |test|
55
- adapt_test!(test)
56
- end
57
- end
58
-
59
- def adapt_test!(parsed_test)
60
- # Saving off the original data
61
- parsed_test['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_test))
62
-
63
- parsed_test['keyword'] = parsed_test.delete(:type).to_s
61
+ # Adapts the AST sub-tree that is rooted at the given scenario node.
62
+ def adapt_scenario!(parsed_test)
63
+ # Removing parsed data for child elements in order to avoid duplicating data
64
+ parsed_test['cuke_modeler_parsing_data'][:tags] = nil
65
+ parsed_test['cuke_modeler_parsing_data'][:steps] = nil
64
66
 
65
- case parsed_test['keyword']
66
- when 'Scenario'
67
- adapt_scenario!(parsed_test)
68
- when 'ScenarioOutline'
69
- parsed_test['keyword'] = 'Scenario Outline'
70
- adapt_outline!(parsed_test)
71
- else
72
- raise(ArgumentError, "Unknown test type: #{parsed_test['keyword']}")
73
- end
74
- end
75
67
 
76
- def adapt_scenario!(parsed_test)
77
68
  parsed_test['name'] = parsed_test.delete(:name)
78
69
  parsed_test['description'] = parsed_test.delete(:description) || ''
79
70
  parsed_test['line'] = parsed_test.delete(:location)[:line]
@@ -91,7 +82,13 @@ module CukeModeler
91
82
  parsed_test['steps'].concat(parsed_test.delete(:steps))
92
83
  end
93
84
 
85
+ # Adapts the AST sub-tree that is rooted at the given outline node.
94
86
  def adapt_outline!(parsed_test)
87
+ # Removing parsed data for child elements in order to avoid duplicating data
88
+ parsed_test['cuke_modeler_parsing_data'][:tags] = nil
89
+ parsed_test['cuke_modeler_parsing_data'][:steps] = nil
90
+ parsed_test['cuke_modeler_parsing_data'][:examples] = nil
91
+
95
92
  parsed_test['name'] = parsed_test.delete(:name)
96
93
  parsed_test['description'] = parsed_test.delete(:description) || ''
97
94
  parsed_test['line'] = parsed_test.delete(:location)[:line]
@@ -115,16 +112,23 @@ module CukeModeler
115
112
  parsed_test['examples'].concat(parsed_test.delete(:examples))
116
113
  end
117
114
 
115
+ # Adapts the AST sub-tree that is rooted at the given example node.
118
116
  def adapt_example!(parsed_example)
119
117
  # Saving off the original data
120
- parsed_example['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_example))
118
+ parsed_example['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_example))
119
+
120
+ # Removing parsed data for child elements in order to avoid duplicating data
121
+ parsed_example['cuke_modeler_parsing_data'][:tags] = nil
122
+ parsed_example['cuke_modeler_parsing_data'][:tableHeader] = nil
123
+ parsed_example['cuke_modeler_parsing_data'][:tableBody] = nil
121
124
 
122
125
  parsed_example['name'] = parsed_example.delete(:name)
123
126
  parsed_example['line'] = parsed_example.delete(:location)[:line]
124
127
  parsed_example['description'] = parsed_example.delete(:description) || ''
125
128
 
126
129
  parsed_example['rows'] = []
127
- parsed_example['rows'] << adapt_table_row!(parsed_example.delete(:tableHeader))
130
+ adapt_table_row!(parsed_example[:tableHeader])
131
+ parsed_example['rows'] << parsed_example.delete(:tableHeader)
128
132
 
129
133
  parsed_example[:tableBody].each do |row|
130
134
  adapt_table_row!(row)
@@ -138,17 +142,22 @@ module CukeModeler
138
142
  parsed_example['tags'].concat(parsed_example.delete(:tags))
139
143
  end
140
144
 
145
+ # Adapts the AST sub-tree that is rooted at the given tag node.
141
146
  def adapt_tag!(parsed_tag)
142
147
  # Saving off the original data
143
- parsed_tag['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_tag))
148
+ parsed_tag['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_tag))
144
149
 
145
150
  parsed_tag['name'] = parsed_tag.delete(:name)
146
151
  parsed_tag['line'] = parsed_tag.delete(:location)[:line]
147
152
  end
148
153
 
154
+ # Adapts the AST sub-tree that is rooted at the given step node.
149
155
  def adapt_step!(parsed_step)
150
156
  # Saving off the original data
151
- parsed_step['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step))
157
+ parsed_step['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step))
158
+
159
+ # Removing parsed data for child elements in order to avoid duplicating data
160
+ parsed_step['cuke_modeler_parsing_data'][:argument] = nil
152
161
 
153
162
  parsed_step['keyword'] = parsed_step.delete(:keyword)
154
163
  parsed_step['name'] = parsed_step.delete(:text)
@@ -164,42 +173,96 @@ module CukeModeler
164
173
  parsed_step['doc_string'] = parsed_step.delete(:argument)
165
174
  when :DataTable
166
175
  adapt_step_table!(step_argument)
167
- parsed_step['rows'] = parsed_step.delete(:argument)
176
+ parsed_step['table'] = parsed_step.delete(:argument)
168
177
  else
169
178
  raise(ArgumentError, "Unknown step argument type: #{step_argument[:type]}")
170
179
  end
171
180
  end
172
181
  end
173
182
 
183
+ # Adapts the AST sub-tree that is rooted at the given doc string node.
174
184
  def adapt_doc_string!(parsed_doc_string)
175
185
  # Saving off the original data
176
- parsed_doc_string['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_doc_string))
186
+ parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string))
177
187
 
178
188
  parsed_doc_string['value'] = parsed_doc_string.delete(:content)
179
189
  parsed_doc_string['content_type'] = parsed_doc_string.delete(:contentType)
190
+ parsed_doc_string['line'] = parsed_doc_string.delete(:location)[:line]
180
191
  end
181
192
 
193
+ # Adapts the AST sub-tree that is rooted at the given table node.
182
194
  def adapt_step_table!(parsed_step_table)
183
195
  # Saving off the original data
184
- parsed_step_table['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step_table))
196
+ parsed_step_table['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_step_table))
197
+
198
+ # Removing parsed data for child elements in order to avoid duplicating data
199
+ parsed_step_table['cuke_modeler_parsing_data'][:rows] = nil
185
200
 
186
201
  parsed_step_table['rows'] = []
187
202
  parsed_step_table[:rows].each do |row|
188
203
  adapt_table_row!(row)
189
204
  end
190
205
  parsed_step_table['rows'].concat(parsed_step_table.delete(:rows))
206
+ parsed_step_table['line'] = parsed_step_table.delete(:location)[:line]
191
207
  end
192
208
 
209
+ # Adapts the AST sub-tree that is rooted at the given row node.
193
210
  def adapt_table_row!(parsed_table_row)
194
211
  # Saving off the original data
195
- parsed_table_row['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_table_row))
212
+ parsed_table_row['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_table_row))
213
+
214
+ # Removing parsed data for child elements in order to avoid duplicating data which the child elements will themselves include
215
+ parsed_table_row['cuke_modeler_parsing_data'][:cells] = nil
216
+
196
217
 
197
218
  parsed_table_row['line'] = parsed_table_row.delete(:location)[:line]
198
219
 
199
- parsed_table_row['cells'] = parsed_table_row.delete(:cells).collect { |cell| cell[:value] }
220
+ parsed_table_row['cells'] = []
221
+ parsed_table_row[:cells].each do |row|
222
+ adapt_table_cell!(row)
223
+ end
224
+ parsed_table_row['cells'].concat(parsed_table_row.delete(:cells))
225
+ end
226
+
227
+ # Adapts the AST sub-tree that is rooted at the given cell node.
228
+ def adapt_table_cell!(parsed_cell)
229
+ # Saving off the original data
230
+ parsed_cell['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_cell))
231
+
232
+ parsed_cell['value'] = parsed_cell.delete(:value)
233
+ parsed_cell['line'] = parsed_cell.delete(:location)[:line]
234
+ end
235
+
200
236
 
237
+ private
201
238
 
202
- parsed_table_row
239
+
240
+ def adapt_child_elements!(parsed_feature)
241
+ adapt_background!(parsed_feature[:background]) if parsed_feature[:background]
242
+ adapt_tests!(parsed_feature)
243
+ end
244
+
245
+ def adapt_tests!(parsed_feature)
246
+ parsed_feature[:scenarioDefinitions].each do |test|
247
+ adapt_test!(test)
248
+ end
249
+ end
250
+
251
+ def adapt_test!(parsed_test)
252
+ # Saving off the original data
253
+ parsed_test['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_test))
254
+
255
+ parsed_test['keyword'] = parsed_test.delete(:type).to_s
256
+
257
+ case parsed_test['keyword']
258
+ when 'Scenario'
259
+ adapt_scenario!(parsed_test)
260
+ when 'ScenarioOutline'
261
+ parsed_test['keyword'] = 'Scenario Outline'
262
+ adapt_outline!(parsed_test)
263
+ else
264
+ raise(ArgumentError, "Unknown test type: #{parsed_test['keyword']}")
265
+ end
203
266
  end
204
267
 
205
268
  end