cuke_modeler 1.3.0 → 2.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 (90) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +60 -17
  3. data/CHANGELOG.md +312 -0
  4. data/Gemfile +19 -3
  5. data/LICENSE.txt +1 -1
  6. data/README.md +17 -7
  7. data/Rakefile +45 -28
  8. data/appveyor.yml +57 -17
  9. data/cuke_modeler.gemspec +6 -3
  10. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +1 -0
  11. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +1 -0
  12. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +2 -1
  13. data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +12 -0
  14. data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +310 -0
  15. data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +307 -0
  16. data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +12 -0
  17. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +12 -0
  18. data/lib/cuke_modeler/containing.rb +16 -0
  19. data/lib/cuke_modeler/described.rb +1 -0
  20. data/lib/cuke_modeler/models/step.rb +31 -2
  21. data/lib/cuke_modeler/named.rb +1 -0
  22. data/lib/cuke_modeler/nested.rb +1 -0
  23. data/lib/cuke_modeler/parsed.rb +1 -0
  24. data/lib/cuke_modeler/parsing.rb +116 -68
  25. data/lib/cuke_modeler/sourceable.rb +1 -0
  26. data/lib/cuke_modeler/stepped.rb +1 -0
  27. data/lib/cuke_modeler/taggable.rb +1 -0
  28. data/lib/cuke_modeler/version.rb +1 -1
  29. data/testing/cucumber/features/analysis/step_comparison.feature +25 -0
  30. data/testing/cucumber/features/analysis/test_comparison.feature +1 -1
  31. data/testing/cucumber/step_definitions/feature_file_steps.rb +1 -1
  32. data/testing/cucumber/step_definitions/modeling_steps.rb +7 -2
  33. data/testing/cucumber/step_definitions/verification_steps.rb +11 -2
  34. data/testing/file_helper.rb +3 -0
  35. data/testing/gemfiles/gherkin2.gemfile +8 -0
  36. data/testing/gemfiles/gherkin3.gemfile +6 -0
  37. data/testing/gemfiles/gherkin4.gemfile +7 -0
  38. data/testing/gemfiles/gherkin5.gemfile +7 -0
  39. data/testing/gemfiles/gherkin6.gemfile +10 -0
  40. data/testing/gemfiles/gherkin7.gemfile +9 -0
  41. data/testing/gemfiles/gherkin8.gemfile +9 -0
  42. data/testing/gemfiles/gherkin9.gemfile +9 -0
  43. data/testing/helper_methods.rb +23 -0
  44. data/testing/rspec/spec/integration/{gherkin_2_adapter_spec.rb → adapters/gherkin_2_adapter_spec.rb} +13 -13
  45. data/testing/rspec/spec/integration/{gherkin_3_adapter_spec.rb → adapters/gherkin_3_adapter_spec.rb} +13 -13
  46. data/testing/rspec/spec/integration/{gherkin_4_adapter_spec.rb → adapters/gherkin_4_adapter_spec.rb} +13 -13
  47. data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +165 -0
  48. data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +159 -0
  49. data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +162 -0
  50. data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +162 -0
  51. data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +162 -0
  52. data/testing/rspec/spec/integration/{background_integration_spec.rb → models/background_integration_spec.rb} +90 -86
  53. data/testing/rspec/spec/integration/{cell_integration_spec.rb → models/cell_integration_spec.rb} +49 -38
  54. data/testing/rspec/spec/integration/{comment_integration_spec.rb → models/comment_integration_spec.rb} +31 -20
  55. data/testing/rspec/spec/integration/{directory_integration_spec.rb → models/directory_integration_spec.rb} +3 -3
  56. data/testing/rspec/spec/integration/{doc_string_integration_spec.rb → models/doc_string_integration_spec.rb} +39 -35
  57. data/testing/rspec/spec/integration/{example_integration_spec.rb → models/example_integration_spec.rb} +109 -83
  58. data/testing/rspec/spec/integration/{feature_file_integration_spec.rb → models/feature_file_integration_spec.rb} +52 -38
  59. data/testing/rspec/spec/integration/{feature_integration_spec.rb → models/feature_integration_spec.rb} +125 -112
  60. data/testing/rspec/spec/integration/{model_integration_spec.rb → models/model_integration_spec.rb} +1 -1
  61. data/testing/rspec/spec/integration/{outline_integration_spec.rb → models/outline_integration_spec.rb} +138 -129
  62. data/testing/rspec/spec/integration/{row_integration_spec.rb → models/row_integration_spec.rb} +55 -35
  63. data/testing/rspec/spec/integration/{scenario_integration_spec.rb → models/scenario_integration_spec.rb} +92 -88
  64. data/testing/rspec/spec/integration/models/step_integration_spec.rb +573 -0
  65. data/testing/rspec/spec/integration/{table_integration_spec.rb → models/table_integration_spec.rb} +38 -34
  66. data/testing/rspec/spec/integration/{tag_integration_spec.rb → models/tag_integration_spec.rb} +56 -36
  67. data/testing/rspec/spec/integration/parsing_integration_spec.rb +45 -7
  68. data/testing/rspec/spec/spec_helper.rb +79 -43
  69. data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +25 -0
  70. data/testing/rspec/spec/unit/{background_unit_spec.rb → models/background_unit_spec.rb} +1 -1
  71. data/testing/rspec/spec/unit/{cell_unit_spec.rb → models/cell_unit_spec.rb} +1 -1
  72. data/testing/rspec/spec/unit/{comment_unit_spec.rb → models/comment_unit_spec.rb} +1 -1
  73. data/testing/rspec/spec/unit/{directory_unit_spec.rb → models/directory_unit_spec.rb} +1 -1
  74. data/testing/rspec/spec/unit/{doc_string_unit_spec.rb → models/doc_string_unit_spec.rb} +1 -1
  75. data/testing/rspec/spec/unit/{example_unit_spec.rb → models/example_unit_spec.rb} +1 -1
  76. data/testing/rspec/spec/unit/{feature_file_unit_spec.rb → models/feature_file_unit_spec.rb} +1 -1
  77. data/testing/rspec/spec/unit/{feature_unit_spec.rb → models/feature_unit_spec.rb} +1 -1
  78. data/testing/rspec/spec/unit/{model_unit_spec.rb → models/model_unit_spec.rb} +1 -1
  79. data/testing/rspec/spec/unit/{outline_unit_spec.rb → models/outline_unit_spec.rb} +1 -1
  80. data/testing/rspec/spec/unit/{row_unit_spec.rb → models/row_unit_spec.rb} +1 -1
  81. data/testing/rspec/spec/unit/{scenario_unit_spec.rb → models/scenario_unit_spec.rb} +1 -1
  82. data/testing/rspec/spec/unit/{step_unit_spec.rb → models/step_unit_spec.rb} +2 -2
  83. data/testing/rspec/spec/unit/{table_unit_spec.rb → models/table_unit_spec.rb} +1 -1
  84. data/testing/rspec/spec/unit/{tag_unit_spec.rb → models/tag_unit_spec.rb} +1 -1
  85. data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +102 -0
  86. data/todo.txt +5 -2
  87. metadata +80 -47
  88. data/History.md +0 -186
  89. data/testing/cucumber/support/transforms.rb +0 -3
  90. data/testing/rspec/spec/integration/step_integration_spec.rb +0 -459
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require "#{File.dirname(__FILE__)}/../../spec_helper"
2
2
 
3
3
 
4
4
  describe 'Table, Integration' do
@@ -21,28 +21,32 @@ describe 'Table, Integration' do
21
21
  expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_table\.feature'/)
22
22
  end
23
23
 
24
- it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
25
- table = clazz.new("| a table |")
26
- data = table.parsing_data
24
+ describe 'parsing data' do
27
25
 
28
- expect(data.keys).to match_array([:type, :location, :rows])
29
- expect(data[:type]).to eq(:DataTable)
30
- end
26
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
27
+ table = clazz.new("| a table |")
28
+ data = table.parsing_data
31
29
 
32
- it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
33
- table = clazz.new("| a table |")
34
- data = table.parsing_data
30
+ expect(data.keys).to match_array([:location, :rows])
31
+ expect(data[:location][:line]).to eq(5)
32
+ end
35
33
 
36
- expect(data.keys).to match_array([:type, :location, :rows])
37
- expect(data[:type]).to eq(:DataTable)
38
- end
34
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(3, 4, 5) do
35
+ table = clazz.new("| a table |")
36
+ data = table.parsing_data
39
37
 
40
- it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
41
- table = clazz.new("| a table |")
42
- data = table.parsing_data
38
+ expect(data.keys).to match_array([:type, :location, :rows])
39
+ expect(data[:type]).to eq(:DataTable)
40
+ end
41
+
42
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
43
+ table = clazz.new("| a table |")
44
+ data = table.parsing_data
45
+
46
+ # There is no parsing data for the table itself, only its rows
47
+ expect(data).to match_array([])
48
+ end
43
49
 
44
- # There is no parsing data for the table itself, only its rows
45
- expect(data).to match_array([])
46
50
  end
47
51
 
48
52
  it 'can be instantiated with the minimum viable Gherkin' do
@@ -74,10 +78,10 @@ describe 'Table, Integration' do
74
78
  context 'from source text' do
75
79
 
76
80
  it "models the table's source line" do
77
- source_text = "#{@feature_keyword}:
81
+ source_text = "#{FEATURE_KEYWORD}:
78
82
 
79
- #{@scenario_keyword}:
80
- #{@step_keyword} step
83
+ #{SCENARIO_KEYWORD}:
84
+ #{STEP_KEYWORD} step
81
85
  | value |"
82
86
  table = CukeModeler::Feature.new(source_text).tests.first.steps.first.block
83
87
 
@@ -125,10 +129,10 @@ describe 'Table, Integration' do
125
129
 
126
130
 
127
131
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
128
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
132
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
129
133
 
130
- #{@scenario_keyword}: Test test
131
- #{@step_keyword} a step:
134
+ #{SCENARIO_KEYWORD}: Test test
135
+ #{STEP_KEYWORD} a step:
132
136
  | a | table |"
133
137
  }
134
138
 
@@ -157,10 +161,10 @@ describe 'Table, Integration' do
157
161
  context 'a table that is part of a scenario' do
158
162
 
159
163
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
160
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
164
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
161
165
 
162
- #{@scenario_keyword}: Test test
163
- #{@step_keyword} a step:
166
+ #{SCENARIO_KEYWORD}: Test test
167
+ #{STEP_KEYWORD} a step:
164
168
  | a | table |"
165
169
  }
166
170
 
@@ -179,12 +183,12 @@ describe 'Table, Integration' do
179
183
  context 'a table that is part of an outline' do
180
184
 
181
185
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
182
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
186
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
183
187
 
184
- #{@outline_keyword}: Test outline
185
- #{@step_keyword} a step:
188
+ #{OUTLINE_KEYWORD}: Test outline
189
+ #{STEP_KEYWORD} a step:
186
190
  | a | table |
187
- #{@example_keyword}:
191
+ #{EXAMPLE_KEYWORD}:
188
192
  | param |
189
193
  | value |"
190
194
  }
@@ -204,10 +208,10 @@ describe 'Table, Integration' do
204
208
  context 'a table that is part of a background' do
205
209
 
206
210
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
207
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
211
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
208
212
 
209
- #{@background_keyword}: Test background
210
- #{@step_keyword} a step:
213
+ #{BACKGROUND_KEYWORD}: Test background
214
+ #{STEP_KEYWORD} a step:
211
215
  | a | table |"
212
216
  }
213
217
 
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require "#{File.dirname(__FILE__)}/../../spec_helper"
2
2
 
3
3
 
4
4
  describe 'Tag, Integration' do
@@ -43,28 +43,48 @@ describe 'Tag, Integration' do
43
43
  expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_tag\.feature'/)
44
44
  end
45
45
 
46
- it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
47
- tag = clazz.new('@a_tag')
48
- data = tag.parsing_data
46
+ describe 'parsing data' do
49
47
 
50
- expect(data.keys).to match_array([:type, :location, :name])
51
- expect(data[:type]).to eq(:Tag)
52
- end
48
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(8, 9) do
49
+ tag = clazz.new('@a_tag')
50
+ data = tag.parsing_data
53
51
 
54
- it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
55
- tag = clazz.new('@a_tag')
56
- data = tag.parsing_data
52
+ expect(data.keys).to match_array([:location, :name, :id])
53
+ expect(data[:name]).to eq('@a_tag')
54
+ end
57
55
 
58
- expect(data.keys).to match_array([:type, :location, :name])
59
- expect(data[:type]).to eq('Tag')
60
- end
56
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7) do
57
+ tag = clazz.new('@a_tag')
58
+ data = tag.parsing_data
61
59
 
62
- it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
63
- tag = clazz.new('@a_tag')
64
- data = tag.parsing_data
60
+ expect(data.keys).to match_array([:location, :name])
61
+ expect(data[:name]).to eq('@a_tag')
62
+ end
63
+
64
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(4, 5) do
65
+ tag = clazz.new('@a_tag')
66
+ data = tag.parsing_data
67
+
68
+ expect(data.keys).to match_array([:type, :location, :name])
69
+ expect(data[:type]).to eq(:Tag)
70
+ end
71
+
72
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(3) do
73
+ tag = clazz.new('@a_tag')
74
+ data = tag.parsing_data
75
+
76
+ expect(data.keys).to match_array([:type, :location, :name])
77
+ expect(data[:type]).to eq('Tag')
78
+ end
79
+
80
+ it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
81
+ tag = clazz.new('@a_tag')
82
+ data = tag.parsing_data
83
+
84
+ expect(data.keys).to match_array(['name', 'line'])
85
+ expect(data['name']).to eq('@a_tag')
86
+ end
65
87
 
66
- expect(data.keys).to match_array(['name', 'line'])
67
- expect(data['name']).to eq('@a_tag')
68
88
  end
69
89
 
70
90
 
@@ -77,13 +97,13 @@ describe 'Tag, Integration' do
77
97
 
78
98
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
79
99
  let(:source_gherkin) { "@feature_tag
80
- #{@feature_keyword}: Test feature
100
+ #{FEATURE_KEYWORD}: Test feature
81
101
 
82
- #{@outline_keyword}: Test test
83
- #{@step_keyword} a step
102
+ #{OUTLINE_KEYWORD}: Test test
103
+ #{STEP_KEYWORD} a step
84
104
 
85
105
  @example_tag
86
- #{@example_keyword}: Test example
106
+ #{EXAMPLE_KEYWORD}: Test example
87
107
  | a param |
88
108
  | a value |"
89
109
  }
@@ -114,11 +134,11 @@ describe 'Tag, Integration' do
114
134
  context 'a tag that is part of a scenario' do
115
135
 
116
136
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
117
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
137
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
118
138
 
119
139
  @a_tag
120
- #{@scenario_keyword}: Test scenario
121
- #{@step_keyword} a step"
140
+ #{SCENARIO_KEYWORD}: Test scenario
141
+ #{STEP_KEYWORD} a step"
122
142
  }
123
143
 
124
144
  let(:directory_model) { CukeModeler::Directory.new(test_directory) }
@@ -136,12 +156,12 @@ describe 'Tag, Integration' do
136
156
  context 'a tag that is part of an outline' do
137
157
 
138
158
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
139
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
159
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
140
160
 
141
161
  @a_tag
142
- #{@outline_keyword}: Test outline
143
- #{@step_keyword} a step
144
- #{@example_keyword}:
162
+ #{OUTLINE_KEYWORD}: Test outline
163
+ #{STEP_KEYWORD} a step
164
+ #{EXAMPLE_KEYWORD}:
145
165
  | param |
146
166
  | value |"
147
167
  }
@@ -161,12 +181,12 @@ describe 'Tag, Integration' do
161
181
  context 'a tag that is part of an example' do
162
182
 
163
183
  let(:test_directory) { CukeModeler::FileHelper.create_directory }
164
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
184
+ let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
165
185
 
166
- #{@outline_keyword}: Test outline
167
- #{@step_keyword} a step
186
+ #{OUTLINE_KEYWORD}: Test outline
187
+ #{STEP_KEYWORD} a step
168
188
  @a_tag
169
- #{@example_keyword}:
189
+ #{EXAMPLE_KEYWORD}:
170
190
  | param |
171
191
  | value |"
172
192
  }
@@ -205,11 +225,11 @@ describe 'Tag, Integration' do
205
225
  end
206
226
 
207
227
  it "models the tag's source line" do
208
- source_text = "#{@feature_keyword}:
228
+ source_text = "#{FEATURE_KEYWORD}:
209
229
 
210
230
  @a_tag
211
- #{@scenario_keyword}:
212
- #{@step_keyword} step"
231
+ #{SCENARIO_KEYWORD}:
232
+ #{STEP_KEYWORD} step"
213
233
  tag = CukeModeler::Feature.new(source_text).tests.first.tags.first
214
234
 
215
235
  expect(tag.source_line).to eq(3)
@@ -8,11 +8,24 @@ describe 'Parsing, Integration' do
8
8
 
9
9
  describe 'unique behavior' do
10
10
 
11
- it 'loads the correct dialects based on the version of Gherkin used', :gherkin3 => true, :gherkin4 => true do
11
+ it 'will complain if using an unknown version of `gherkin`' do
12
+ original_version = Gem.loaded_specs['gherkin'].version
13
+ unknown_version = Gem::Version.new('0.0.0')
14
+
15
+ begin
16
+ Gem.loaded_specs['gherkin'].instance_variable_set(:@version, unknown_version)
17
+
18
+ expect { load "#{File.dirname(__FILE__)}/../../../../lib/cuke_modeler/parsing.rb" }.to raise_error("Unknown Gherkin version: '0.0.0'")
19
+ ensure
20
+ Gem.loaded_specs['gherkin'].instance_variable_set(:@version, original_version)
21
+ end
22
+ end
23
+
24
+ it 'loads the correct dialects based on the version of Gherkin used', :unless => gherkin?(2) do
12
25
  expect(nodule.dialects).to equal(Gherkin::DIALECTS)
13
26
  end
14
27
 
15
- it 'loads the correct dialects based on the version of Gherkin used', :gherkin2 => true do
28
+ it 'loads the correct dialects based on the version of Gherkin used', :if => gherkin?(2) do
16
29
  expect(nodule.dialects).to equal(Gherkin::I18n::LANGUAGES)
17
30
  end
18
31
 
@@ -39,7 +52,7 @@ describe 'Parsing, Integration' do
39
52
 
40
53
  it 'raises and error if given something to parse besides a string' do
41
54
  expect { nodule.parse_text(5) }.to raise_error(ArgumentError, /Text to parse must be a String but got/)
42
- expect { nodule.parse_text("#{@feature_keyword}:") }.to_not raise_error
55
+ expect { nodule.parse_text("#{FEATURE_KEYWORD}:") }.to_not raise_error
43
56
  end
44
57
 
45
58
  it 'includes the type of object provided when raising an non-string exception' do
@@ -48,11 +61,11 @@ describe 'Parsing, Integration' do
48
61
 
49
62
  # todo - Stop doing this. Just return a feature file rooted AST. (Will require major version number change)
50
63
  it 'returns an Array' do
51
- result = nodule.parse_text("#{@feature_keyword}:")
64
+ result = nodule.parse_text("#{FEATURE_KEYWORD}:")
52
65
  expect(result).to be_a(Array)
53
66
  end
54
67
 
55
- it 'raises and error if an error is encountered while parsing text' do
68
+ it 'raises an error if an error is encountered while parsing text' do
56
69
  expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /Error encountered while parsing '.*'/)
57
70
  end
58
71
 
@@ -60,6 +73,10 @@ describe 'Parsing, Integration' do
60
73
  expect { nodule.parse_text('bad file', 'file foo.txt') }.to raise_error(/'file foo\.txt'/)
61
74
  end
62
75
 
76
+ it 'has a default file name used while parsing if one is not provided' do
77
+ expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /'cuke_modeler_fake_file\.feature'/)
78
+ end
79
+
63
80
  it 'includes the underlying error message in the error that it raises' do
64
81
  begin
65
82
  $old_method = CukeModeler::Parsing.method(:parsing_method)
@@ -96,8 +113,29 @@ describe 'Parsing, Integration' do
96
113
 
97
114
  end
98
115
 
99
- it 'has a default file name if one is not provided' do
100
- expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /'cuke_modeler_fake_file\.feature'/)
116
+ describe 'parsing invalid Gherkin' do
117
+
118
+ it 'correctly bubbles up parsing errors', :if => gherkin?(6, 7, 8, 9) do
119
+ expect { nodule.parse_text('bad file') }.to raise_error(/RuntimeError.*#EOF/)
120
+ end
121
+
122
+ it 'correctly bubbles up parsing errors', :if => gherkin?(4, 5) do
123
+ expect { nodule.parse_text('bad file') }.to raise_error(/Gherkin::CompositeParserException.*#EOF/m)
124
+ end
125
+
126
+ it 'correctly bubbles up parsing errors', :if => gherkin?(3) do
127
+ expect { nodule.parse_text('bad file') }.to raise_error(/Gherkin::CompositeParserException.*unexpected end of file/m)
128
+ end
129
+
130
+ it 'correctly bubbles up parsing errors', :if => gherkin?(2) do
131
+ # A different error is thrown on JRuby
132
+ if RUBY_PLATFORM == "java"
133
+ expect { nodule.parse_text('bad file') }.to raise_error(/Java::GherkinLexer.*_FEATURE_END_/m)
134
+ else
135
+ expect { nodule.parse_text('bad file') }.to raise_error(/Gherkin::Lexer::LexingError.*error on line 1/)
136
+ end
137
+ end
138
+
101
139
  end
102
140
 
103
141
  end
@@ -25,66 +25,102 @@ require "#{this_dir}/unit/shared/keyworded_models_unit_specs"
25
25
 
26
26
  require "#{this_dir}/../../dialect_helper"
27
27
  require "#{this_dir}/../../file_helper"
28
+ require "#{this_dir}/../../helper_methods"
28
29
 
29
- # Use a fake dialect for testing in order to avoid hard coded language assumptions in the
30
- # implementation. Only possible with newer versions of Gherkin.
31
- if Gem.loaded_specs['gherkin'].version.version[/^2\./]
32
- CukeModeler::DialectHelper.set_dialect(Gherkin::I18n::LANGUAGES['en'])
33
- CukeModeler::Parsing.dialect = 'en'
34
- else
35
- dialect_file_path = "#{this_dir}/../../test_languages.json"
36
- test_dialects = JSON.parse File.open(dialect_file_path, 'r:UTF-8').read
30
+ require 'rubygems/mock_gem_ui'
37
31
 
38
- Gherkin::DIALECTS.merge!(test_dialects)
39
32
 
33
+ # Use a random dialect for testing in order to avoid hard coded language assumptions in the
34
+ # implementation and making the test dialect the default dialect so that language headers
35
+ # aren't needed for all of the test code. Only possible with some versions of Gherkin.
40
36
 
41
- # Making the test dialect the default dialect so that language headers aren't
42
- # needed for all of the test code.
43
- module Gherkin
44
- class Parser
37
+ gherkin_major_version = Gem.loaded_specs['gherkin'].version.version.match(/^(\d+)\./)[1].to_i
45
38
 
46
- alias_method :original_parse, :parse
39
+ case gherkin_major_version
40
+ when 8, 9
41
+ # TODO: choose randomly from Gherkin::DIALECTS once I figure out how to handle encodings...
42
+ test_dialect = ['en', 'en-lol', 'en-pirate', 'en-Scouse'].sample
43
+ puts "Testing with dialect '#{test_dialect}'..."
47
44
 
48
- def parse(token_scanner, token_matcher = TokenMatcher.new('cm-test'))
49
- original_parse(token_scanner, token_matcher)
45
+ CukeModeler::DialectHelper.set_dialect(Gherkin::DIALECTS[test_dialect])
46
+ CukeModeler::Parsing.dialect = test_dialect
47
+
48
+ module Gherkin
49
+ class << self
50
+ alias_method :original_from_source, :from_source
51
+
52
+ def from_source(uri, data, options = {})
53
+ options[:default_dialect] ||= CukeModeler::Parsing.dialect
54
+ original_from_source(uri, data, options)
55
+ end
56
+ end
57
+ end
58
+ when 6, 7
59
+ # TODO: choose randomly from Gherkin::DIALECTS once I figure out how to handle encodings...
60
+ test_dialect = ['en', 'en-lol', 'en-pirate', 'en-Scouse'].sample
61
+ puts "Testing with dialect '#{test_dialect}'..."
62
+
63
+ CukeModeler::DialectHelper.set_dialect(Gherkin::DIALECTS[test_dialect])
64
+ CukeModeler::Parsing.dialect = test_dialect
65
+
66
+ module Gherkin
67
+ class Gherkin
68
+ class << self
69
+ alias_method :original_from_source, :from_source
70
+
71
+ def from_source(uri, data, options = {})
72
+ options[:default_dialect] ||= CukeModeler::Parsing.dialect
73
+ original_from_source(uri, data, options)
74
+ end
75
+ end
50
76
  end
77
+ end
78
+ when 3, 4, 5
79
+ # TODO: stop using test dialect and just randomize for all version of `gherkin`
80
+ dialect_file_path = "#{this_dir}/../../test_languages.json"
81
+ test_dialects = JSON.parse File.open(dialect_file_path, 'r:UTF-8').read
82
+
83
+ Gherkin::DIALECTS.merge!(test_dialects)
84
+
51
85
 
86
+ module Gherkin
87
+ class Parser
88
+
89
+ alias_method :original_parse, :parse
90
+
91
+ def parse(token_scanner, token_matcher = TokenMatcher.new('cm-test'))
92
+ original_parse(token_scanner, token_matcher)
93
+ end
94
+
95
+ end
52
96
  end
53
- end
54
97
 
55
- CukeModeler::DialectHelper.set_dialect(test_dialects['cm-test'])
56
- CukeModeler::Parsing.dialect = 'cm-test'
98
+ CukeModeler::DialectHelper.set_dialect(test_dialects['cm-test'])
99
+ CukeModeler::Parsing.dialect = 'cm-test'
100
+ when 2
101
+ CukeModeler::DialectHelper.set_dialect(Gherkin::I18n::LANGUAGES['en'])
102
+ CukeModeler::Parsing.dialect = 'en'
103
+ else
104
+ raise("Unknown Gherkin major version: '#{gherkin_major_version}'")
57
105
  end
58
106
 
59
107
 
60
108
  RSpec.configure do |config|
61
- case Gem.loaded_specs['gherkin'].version.version
62
- when /^[54]\./
63
- config.filter_run_excluding :gherkin2 => true,
64
- :gherkin3 => true,
65
- :gherkin4 => false
66
- when /^3\./
67
- config.filter_run_excluding :gherkin2 => true,
68
- :gherkin3 => false,
69
- :gherkin4 => true
70
- else
71
- config.filter_run_excluding :gherkin2 => false,
72
- :gherkin3 => true,
73
- :gherkin4 => true
74
- end
75
109
 
76
- config.before(:all) do
77
- @feature_keyword = CukeModeler::DialectHelper.feature_keyword
78
- @background_keyword = CukeModeler::DialectHelper.background_keyword
79
- @scenario_keyword = CukeModeler::DialectHelper.scenario_keyword
80
- @outline_keyword = CukeModeler::DialectHelper.outline_keyword
81
- @example_keyword = CukeModeler::DialectHelper.example_keyword
82
- @step_keyword = CukeModeler::DialectHelper.step_keyword
83
- @given_keyword = CukeModeler::DialectHelper.given_keyword
84
- @then_keyword = CukeModeler::DialectHelper.then_keyword
110
+ include CukeModeler::HelperMethods
111
+
112
+ config.before(:suite) do
113
+ FEATURE_KEYWORD = CukeModeler::DialectHelper.feature_keyword
114
+ BACKGROUND_KEYWORD = CukeModeler::DialectHelper.background_keyword
115
+ SCENARIO_KEYWORD = CukeModeler::DialectHelper.scenario_keyword
116
+ OUTLINE_KEYWORD = CukeModeler::DialectHelper.outline_keyword
117
+ EXAMPLE_KEYWORD = CukeModeler::DialectHelper.example_keyword
118
+ STEP_KEYWORD = CukeModeler::DialectHelper.step_keyword
119
+ GIVEN_KEYWORD = CukeModeler::DialectHelper.given_keyword
120
+ THEN_KEYWORD = CukeModeler::DialectHelper.then_keyword
85
121
  end
86
122
 
87
- config.after(:all) do
123
+ config.after(:suite) do
88
124
  CukeModeler::FileHelper.created_directories.each do |dir_path|
89
125
  FileUtils.remove_entry(dir_path, true)
90
126
  end