cuke_modeler 0.0.2 → 0.1.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 (95) hide show
  1. data/.travis.yml +23 -0
  2. data/Gemfile +22 -4
  3. data/History.rdoc +6 -0
  4. data/Rakefile +26 -26
  5. data/cuke_modeler.gemspec +3 -1
  6. data/features/modeling/{background_modeling.feature → gherkin/background_modeling.feature} +1 -11
  7. data/features/modeling/{background_output.feature → gherkin/background_output.feature} +1 -0
  8. data/features/modeling/{directory_modeling.feature → gherkin/directory_modeling.feature} +1 -11
  9. data/features/modeling/{directory_output.feature → gherkin/directory_output.feature} +1 -0
  10. data/features/modeling/{doc_string_modeling.feature → gherkin/doc_string_modeling.feature} +1 -11
  11. data/features/modeling/{doc_string_output.feature → gherkin/doc_string_output.feature} +1 -0
  12. data/features/modeling/{example_modeling.feature → gherkin/example_modeling.feature} +1 -11
  13. data/features/modeling/{example_output.feature → gherkin/example_output.feature} +1 -0
  14. data/features/modeling/{feature_file_modeling.feature → gherkin/feature_file_modeling.feature} +1 -11
  15. data/features/modeling/{feature_file_output.feature → gherkin/feature_file_output.feature} +1 -0
  16. data/features/modeling/{feature_modeling.feature → gherkin/feature_modeling.feature} +1 -11
  17. data/features/modeling/{feature_output.feature → gherkin/feature_output.feature} +1 -0
  18. data/features/modeling/{outline_modeling.feature → gherkin/outline_modeling.feature} +1 -11
  19. data/features/modeling/{outline_output.feature → gherkin/outline_output.feature} +1 -0
  20. data/features/modeling/{row_modeling.feature → gherkin/row_modeling.feature} +1 -10
  21. data/features/modeling/{row_output.feature → gherkin/row_output.feature} +1 -0
  22. data/features/modeling/{scenario_modeling.feature → gherkin/scenario_modeling.feature} +1 -11
  23. data/features/modeling/{scenario_output.feature → gherkin/scenario_output.feature} +1 -0
  24. data/features/modeling/{step_modeling.feature → gherkin/step_modeling.feature} +1 -11
  25. data/features/modeling/{step_output.feature → gherkin/step_output.feature} +1 -0
  26. data/features/modeling/{table_modeling.feature → gherkin/table_modeling.feature} +1 -11
  27. data/features/modeling/{table_output.feature → gherkin/table_output.feature} +1 -0
  28. data/features/modeling/{table_row_modeling.feature → gherkin/table_row_modeling.feature} +1 -11
  29. data/features/modeling/{table_row_output.feature → gherkin/table_row_output.feature} +1 -0
  30. data/features/modeling/{tag_modeling.feature → gherkin/tag_modeling.feature} +1 -11
  31. data/features/modeling/{tag_output.feature → gherkin/tag_output.feature} +1 -0
  32. data/features/modeling/gherkin3/background_modeling.feature +64 -0
  33. data/features/modeling/gherkin3/background_output.feature +131 -0
  34. data/features/modeling/gherkin3/directory_modeling.feature +110 -0
  35. data/features/modeling/gherkin3/directory_output.feature +14 -0
  36. data/features/modeling/gherkin3/doc_string_modeling.feature +53 -0
  37. data/features/modeling/gherkin3/doc_string_output.feature +72 -0
  38. data/features/modeling/gherkin3/example_modeling.feature +100 -0
  39. data/features/modeling/gherkin3/example_output.feature +207 -0
  40. data/features/modeling/gherkin3/feature_file_modeling.feature +54 -0
  41. data/features/modeling/gherkin3/feature_file_output.feature +14 -0
  42. data/features/modeling/gherkin3/feature_modeling.feature +155 -0
  43. data/features/modeling/gherkin3/feature_output.feature +249 -0
  44. data/features/modeling/gherkin3/outline_modeling.feature +89 -0
  45. data/features/modeling/gherkin3/outline_output.feature +255 -0
  46. data/features/modeling/gherkin3/row_modeling.feature +68 -0
  47. data/features/modeling/gherkin3/row_output.feature +28 -0
  48. data/features/modeling/gherkin3/scenario_modeling.feature +78 -0
  49. data/features/modeling/gherkin3/scenario_output.feature +148 -0
  50. data/features/modeling/gherkin3/step_modeling.feature +75 -0
  51. data/features/modeling/gherkin3/step_output.feature +53 -0
  52. data/features/modeling/gherkin3/table_modeling.feature +42 -0
  53. data/features/modeling/gherkin3/table_output.feature +43 -0
  54. data/features/modeling/gherkin3/table_row_modeling.feature +57 -0
  55. data/features/modeling/gherkin3/table_row_output.feature +28 -0
  56. data/features/modeling/gherkin3/tag_modeling.feature +49 -0
  57. data/features/modeling/gherkin3/tag_output.feature +17 -0
  58. data/features/step_definitions/background_steps.rb +5 -1
  59. data/features/step_definitions/doc_string_steps.rb +5 -1
  60. data/features/step_definitions/feature_steps.rb +5 -1
  61. data/features/step_definitions/outline_steps.rb +10 -4
  62. data/features/step_definitions/step_steps.rb +10 -2
  63. data/features/step_definitions/table_steps.rb +6 -2
  64. data/features/step_definitions/tag_steps.rb +15 -3
  65. data/features/step_definitions/test_steps.rb +7 -2
  66. data/features/support/env.rb +21 -9
  67. data/gemfiles/gherkin.gemfile +17 -0
  68. data/gemfiles/gherkin3.gemfile +15 -0
  69. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +146 -0
  70. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +206 -0
  71. data/lib/cuke_modeler/parsing.rb +61 -20
  72. data/lib/cuke_modeler/raw.rb +1 -1
  73. data/lib/cuke_modeler/row.rb +2 -2
  74. data/lib/cuke_modeler/table.rb +2 -2
  75. data/lib/cuke_modeler/table_row.rb +1 -1
  76. data/lib/cuke_modeler/version.rb +1 -1
  77. data/spec/integration/example_integration_spec.rb +2 -1
  78. data/spec/integration/feature_integration_spec.rb +7 -4
  79. data/spec/integration/outline_integration_spec.rb +4 -2
  80. data/spec/integration/tag_integration_spec.rb +2 -1
  81. data/spec/spec_helper.rb +6 -0
  82. data/spec/unit/background_unit_spec.rb +17 -0
  83. data/spec/unit/doc_string_unit_spec.rb +17 -0
  84. data/spec/unit/example_unit_spec.rb +18 -1
  85. data/spec/unit/feature_file_unit_spec.rb +2 -2
  86. data/spec/unit/feature_unit_spec.rb +16 -0
  87. data/spec/unit/outline_unit_spec.rb +20 -1
  88. data/spec/unit/row_unit_spec.rb +18 -0
  89. data/spec/unit/scenario_unit_spec.rb +17 -0
  90. data/spec/unit/step_unit_spec.rb +17 -0
  91. data/spec/unit/table_row_unit_spec.rb +18 -0
  92. data/spec/unit/table_unit_spec.rb +16 -0
  93. data/spec/unit/tag_unit_spec.rb +17 -0
  94. metadata +147 -60
  95. data/features/step_definitions/spec_steps.rb +0 -18
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../"
4
+ gem "gherkin", "< 3.0.0"
5
+
6
+ # cuke_modeler can play with pretty much any version of these but they all play differently with Ruby
7
+ if RUBY_VERSION =~ /^1\.8/
8
+ gem 'cucumber', '<1.3.0'
9
+ gem 'mime-types', '<2.0.0'
10
+ gem 'rest-client', '<1.7.0'
11
+ elsif RUBY_VERSION =~ /^1\./
12
+ gem 'cucumber', '>=1.0.0', '<2.0.0'
13
+ end
14
+
15
+ if RUBY_VERSION =~ /^2\.[23456789]/
16
+ gem 'test-unit'
17
+ end
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../"
4
+ gem "gherkin", ">= 3.0.0"
5
+
6
+ # cuke_modeler can play with pretty much any version of these but they all play differently with Ruby
7
+ if RUBY_VERSION =~ /^1\.8/
8
+ gem 'cucumber', '<1.3.0'
9
+ gem 'mime-types', '<2.0.0'
10
+ gem 'rest-client', '<1.7.0'
11
+ end
12
+
13
+ if RUBY_VERSION =~ /^2\.[23456789]/
14
+ gem 'test-unit'
15
+ end
@@ -0,0 +1,146 @@
1
+ module CukeModeler
2
+ class Gherkin2Adapter
3
+
4
+
5
+ def adapt(parsed_ast)
6
+ # An AST is just one feature
7
+ adapt_feature!(parsed_ast.first) if parsed_ast.first
8
+
9
+ parsed_ast
10
+ end
11
+
12
+ def adapt_feature!(parsed_feature)
13
+ # Saving off the original data
14
+ parsed_feature['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_feature))
15
+
16
+ adapt_child_elements!(parsed_feature)
17
+
18
+ if parsed_feature['tags']
19
+ parsed_feature['tags'].each do |tag|
20
+ adapt_tag!(tag)
21
+ end
22
+ end
23
+ end
24
+
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
+
43
+ def adapt_background!(parsed_background)
44
+ # Saving off the original data
45
+ parsed_background['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_background))
46
+
47
+ if parsed_background['steps']
48
+ parsed_background['steps'].each do |step|
49
+ adapt_step!(step)
50
+ end
51
+ end
52
+ end
53
+
54
+ def adapt_scenario!(parsed_scenario)
55
+ # Saving off the original data
56
+ parsed_scenario['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_scenario))
57
+
58
+ if parsed_scenario['tags']
59
+ parsed_scenario['tags'].each do |tag|
60
+ adapt_tag!(tag)
61
+ end
62
+ end
63
+
64
+ if parsed_scenario['steps']
65
+ parsed_scenario['steps'].each do |step|
66
+ adapt_step!(step)
67
+ end
68
+ end
69
+ end
70
+
71
+ def adapt_outline!(parsed_outline)
72
+ # Saving off the original data
73
+ parsed_outline['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_outline))
74
+
75
+ if parsed_outline['tags']
76
+ parsed_outline['tags'].each do |tag|
77
+ adapt_tag!(tag)
78
+ end
79
+ end
80
+
81
+ if parsed_outline['steps']
82
+ parsed_outline['steps'].each do |step|
83
+ adapt_step!(step)
84
+ end
85
+ end
86
+
87
+ if parsed_outline['examples']
88
+ parsed_outline['examples'].each do |example|
89
+ adapt_example!(example)
90
+ end
91
+ end
92
+ end
93
+
94
+ def adapt_example!(parsed_example)
95
+ # Saving off the original data
96
+ parsed_example['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_example))
97
+
98
+ parsed_example['rows'].each do |row|
99
+ adapt_table_row!(row)
100
+ end
101
+
102
+ if parsed_example['tags']
103
+ parsed_example['tags'].each do |tag|
104
+ adapt_tag!(tag)
105
+ end
106
+ end
107
+ end
108
+
109
+ def adapt_tag!(parsed_tag)
110
+ # Saving off the original data
111
+ parsed_tag['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_tag))
112
+ end
113
+
114
+ def adapt_step!(parsed_step)
115
+ # Saving off the original data
116
+ parsed_step['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step))
117
+
118
+ adapt_doc_string!(parsed_step['doc_string']) if parsed_step['doc_string']
119
+
120
+ if parsed_step['rows']
121
+ parsed_step['rows'] = {'rows' => parsed_step['rows']}
122
+ adapt_step_table!(parsed_step['rows'])
123
+ end
124
+ end
125
+
126
+ def adapt_doc_string!(parsed_doc_string)
127
+ # Saving off the original data
128
+ parsed_doc_string['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_doc_string))
129
+ end
130
+
131
+ def adapt_step_table!(parsed_step_table)
132
+ # Saving off the original data
133
+ parsed_step_table['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step_table['rows']))
134
+
135
+ parsed_step_table['rows'].each do |row|
136
+ adapt_table_row!(row)
137
+ end
138
+ end
139
+
140
+ def adapt_table_row!(parsed_table_row)
141
+ # Saving off the original data
142
+ parsed_table_row['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_table_row))
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,206 @@
1
+ module CukeModeler
2
+ class Gherkin3Adapter
3
+
4
+
5
+ def adapt(parsed_ast)
6
+ # An AST is just one feature
7
+ adapt_feature!(parsed_ast)
8
+
9
+ [parsed_ast]
10
+ end
11
+
12
+ def adapt_feature!(parsed_feature)
13
+ # Saving off the original data
14
+ parsed_feature['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_feature))
15
+
16
+ parsed_feature['name'] = parsed_feature.delete(:name)
17
+ parsed_feature['description'] = parsed_feature.delete(:description) || ''
18
+ parsed_feature['line'] = parsed_feature.delete(:location)[:line]
19
+
20
+ parsed_feature['elements'] = []
21
+ adapt_child_elements!(parsed_feature)
22
+ parsed_feature['elements'].concat(parsed_feature.delete(:scenarioDefinitions))
23
+ parsed_feature['elements'] << parsed_feature.delete(:background) if parsed_feature[:background]
24
+
25
+ parsed_feature['tags'] = []
26
+ parsed_feature[:tags].each do |tag|
27
+ adapt_tag!(tag)
28
+ end
29
+ parsed_feature['tags'].concat(parsed_feature.delete(:tags))
30
+ end
31
+
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
+
37
+ def adapt_background!(parsed_background)
38
+ # Saving off the original data
39
+ parsed_background['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_background))
40
+
41
+ parsed_background['keyword'] = parsed_background.delete(:type).to_s
42
+ parsed_background['name'] = parsed_background.delete(:name)
43
+ parsed_background['description'] = parsed_background.delete(:description) || ''
44
+ parsed_background['line'] = parsed_background.delete(:location)[:line]
45
+
46
+ parsed_background['steps'] = []
47
+ parsed_background[:steps].each do |step|
48
+ adapt_step!(step)
49
+ end
50
+ parsed_background['steps'].concat(parsed_background.delete(:steps))
51
+ end
52
+
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
64
+
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
+
76
+ def adapt_scenario!(parsed_test)
77
+ parsed_test['name'] = parsed_test.delete(:name)
78
+ parsed_test['description'] = parsed_test.delete(:description) || ''
79
+ parsed_test['line'] = parsed_test.delete(:location)[:line]
80
+
81
+ parsed_test['tags'] = []
82
+ parsed_test[:tags].each do |tag|
83
+ adapt_tag!(tag)
84
+ end
85
+ parsed_test['tags'].concat(parsed_test.delete(:tags))
86
+
87
+ parsed_test['steps'] = []
88
+ parsed_test[:steps].each do |step|
89
+ adapt_step!(step)
90
+ end
91
+ parsed_test['steps'].concat(parsed_test.delete(:steps))
92
+ end
93
+
94
+ def adapt_outline!(parsed_test)
95
+ parsed_test['name'] = parsed_test.delete(:name)
96
+ parsed_test['description'] = parsed_test.delete(:description) || ''
97
+ parsed_test['line'] = parsed_test.delete(:location)[:line]
98
+
99
+ parsed_test['tags'] = []
100
+ parsed_test[:tags].each do |tag|
101
+ adapt_tag!(tag)
102
+ end
103
+ parsed_test['tags'].concat(parsed_test.delete(:tags))
104
+
105
+ parsed_test['steps'] = []
106
+ parsed_test[:steps].each do |step|
107
+ adapt_step!(step)
108
+ end
109
+ parsed_test['steps'].concat(parsed_test.delete(:steps))
110
+
111
+ parsed_test['examples'] = []
112
+ parsed_test[:examples].each do |step|
113
+ adapt_example!(step)
114
+ end
115
+ parsed_test['examples'].concat(parsed_test.delete(:examples))
116
+ end
117
+
118
+ def adapt_example!(parsed_example)
119
+ # Saving off the original data
120
+ parsed_example['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_example))
121
+
122
+ parsed_example['name'] = parsed_example.delete(:name)
123
+ parsed_example['line'] = parsed_example.delete(:location)[:line]
124
+ parsed_example['description'] = parsed_example.delete(:description) || ''
125
+
126
+ parsed_example['rows'] = []
127
+ parsed_example['rows'] << adapt_table_row!(parsed_example.delete(:tableHeader))
128
+
129
+ parsed_example[:tableBody].each do |row|
130
+ adapt_table_row!(row)
131
+ end
132
+ parsed_example['rows'].concat(parsed_example.delete(:tableBody))
133
+
134
+ parsed_example['tags'] = []
135
+ parsed_example[:tags].each do |tag|
136
+ adapt_tag!(tag)
137
+ end
138
+ parsed_example['tags'].concat(parsed_example.delete(:tags))
139
+ end
140
+
141
+ def adapt_tag!(parsed_tag)
142
+ # Saving off the original data
143
+ parsed_tag['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_tag))
144
+
145
+ parsed_tag['name'] = parsed_tag.delete(:name)
146
+ parsed_tag['line'] = parsed_tag.delete(:location)[:line]
147
+ end
148
+
149
+ def adapt_step!(parsed_step)
150
+ # Saving off the original data
151
+ parsed_step['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step))
152
+
153
+ parsed_step['keyword'] = parsed_step.delete(:keyword)
154
+ parsed_step['name'] = parsed_step.delete(:text)
155
+ parsed_step['line'] = parsed_step.delete(:location)[:line]
156
+
157
+
158
+ step_argument = parsed_step[:argument]
159
+
160
+ if step_argument
161
+ case step_argument[:type]
162
+ when :DocString
163
+ adapt_doc_string!(step_argument)
164
+ parsed_step['doc_string'] = parsed_step.delete(:argument)
165
+ when :DataTable
166
+ adapt_step_table!(step_argument)
167
+ parsed_step['rows'] = parsed_step.delete(:argument)
168
+ else
169
+ raise(ArgumentError, "Unknown step argument type: #{step_argument[:type]}")
170
+ end
171
+ end
172
+ end
173
+
174
+ def adapt_doc_string!(parsed_doc_string)
175
+ # Saving off the original data
176
+ parsed_doc_string['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_doc_string))
177
+
178
+ parsed_doc_string['value'] = parsed_doc_string.delete(:content)
179
+ parsed_doc_string['content_type'] = parsed_doc_string.delete(:contentType)
180
+ end
181
+
182
+ def adapt_step_table!(parsed_step_table)
183
+ # Saving off the original data
184
+ parsed_step_table['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_step_table))
185
+
186
+ parsed_step_table['rows'] = []
187
+ parsed_step_table[:rows].each do |row|
188
+ adapt_table_row!(row)
189
+ end
190
+ parsed_step_table['rows'].concat(parsed_step_table.delete(:rows))
191
+ end
192
+
193
+ def adapt_table_row!(parsed_table_row)
194
+ # Saving off the original data
195
+ parsed_table_row['cuke_modeler_raw_adapter_output'] = Marshal::load(Marshal.dump(parsed_table_row))
196
+
197
+ parsed_table_row['line'] = parsed_table_row.delete(:location)[:line]
198
+
199
+ parsed_table_row['cells'] = parsed_table_row.delete(:cells).collect { |cell| cell[:value] }
200
+
201
+
202
+ parsed_table_row
203
+ end
204
+
205
+ end
206
+ end
@@ -1,32 +1,73 @@
1
- require 'stringio'
2
- require 'gherkin/formatter/json_formatter'
3
- require 'gherkin'
4
- require 'json'
5
- require 'multi_json'
1
+ # The 'gherkin' gem loads differently depending across versions. Try the old one first and then the new one
2
+ begin
3
+ require 'gherkin'
4
+ rescue LoadError => e
5
+ require 'gherkin/parser'
6
+ end
6
7
 
7
- module CukeModeler
8
+ # Parsing will be with an 'adapter' appropriate to the version of the 'gherkin' gem that has been activated
9
+ if Gem.loaded_specs['gherkin'].version.version[/^3/]
8
10
 
9
- # A module providing source text parsing functionality.
11
+ require 'gherkin/parser'
12
+ require 'cuke_modeler/adapters/gherkin_3_adapter'
10
13
 
11
- module Parsing
12
14
 
13
- class << self
15
+ module CukeModeler
14
16
 
15
- # Parses the Cucumber feature given in *source_text* and returns an array
16
- # containing the hash representation of its logical structure.
17
- def parse_text(source_text)
18
- raise(ArgumentError, "Cannot parse #{source_text.class} objects. Strings only.") unless source_text.is_a?(String)
17
+ module Parsing
18
+ class << self
19
19
 
20
- io = StringIO.new
21
- formatter = Gherkin::Formatter::JSONFormatter.new(io)
22
- parser = Gherkin::Parser::Parser.new(formatter)
23
- parser.parse(source_text, 'fake_file.txt', 0)
24
- formatter.done
20
+ def parse_text(source_text)
21
+ raise(ArgumentError, "Cannot parse #{source_text.class} objects. Strings only.") unless source_text.is_a?(String)
25
22
 
26
- MultiJson.load(io.string)
27
- end
23
+ parsed_result = Gherkin::Parser.new.parse(source_text)
24
+ adapted_result = CukeModeler::Gherkin3Adapter.new.adapt(parsed_result)
28
25
 
26
+ adapted_result
27
+ end
28
+ end
29
29
  end
30
+ end
31
+
32
+ else
33
+
34
+ require 'stringio'
35
+ require 'gherkin/formatter/json_formatter'
36
+ require 'gherkin'
37
+ require 'json'
38
+ require 'multi_json'
39
+ require 'cuke_modeler/adapters/gherkin_2_adapter'
40
+
41
+
42
+ module CukeModeler
43
+
44
+ # A module providing source text parsing functionality.
45
+
46
+ module Parsing
30
47
 
48
+ class << self
49
+
50
+ # Parses the Cucumber feature given in *source_text* and returns an array
51
+ # containing the hash representation of its logical structure.
52
+ def parse_text(source_text)
53
+ raise(ArgumentError, "Cannot parse #{source_text.class} objects. Strings only.") unless source_text.is_a?(String)
54
+
55
+ io = StringIO.new
56
+ formatter = Gherkin::Formatter::JSONFormatter.new(io)
57
+ parser = Gherkin::Parser::Parser.new(formatter)
58
+ parser.parse(source_text, 'fake_file.txt', 0)
59
+ formatter.done
60
+
61
+
62
+ parsed_result = MultiJson.load(io.string)
63
+ adapted_result = CukeModeler::Gherkin2Adapter.new.adapt(parsed_result)
64
+
65
+ adapted_result
66
+ end
67
+
68
+ end
69
+
70
+ end
31
71
  end
72
+
32
73
  end