cuke_modeler 1.3.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +60 -17
- data/CHANGELOG.md +312 -0
- data/Gemfile +19 -3
- data/LICENSE.txt +1 -1
- data/README.md +17 -7
- data/Rakefile +45 -28
- data/appveyor.yml +57 -17
- data/cuke_modeler.gemspec +6 -3
- data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +1 -0
- data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +1 -0
- data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +2 -1
- data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +310 -0
- data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +307 -0
- data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +12 -0
- data/lib/cuke_modeler/containing.rb +16 -0
- data/lib/cuke_modeler/described.rb +1 -0
- data/lib/cuke_modeler/models/step.rb +31 -2
- data/lib/cuke_modeler/named.rb +1 -0
- data/lib/cuke_modeler/nested.rb +1 -0
- data/lib/cuke_modeler/parsed.rb +1 -0
- data/lib/cuke_modeler/parsing.rb +116 -68
- data/lib/cuke_modeler/sourceable.rb +1 -0
- data/lib/cuke_modeler/stepped.rb +1 -0
- data/lib/cuke_modeler/taggable.rb +1 -0
- data/lib/cuke_modeler/version.rb +1 -1
- data/testing/cucumber/features/analysis/step_comparison.feature +25 -0
- data/testing/cucumber/features/analysis/test_comparison.feature +1 -1
- data/testing/cucumber/step_definitions/feature_file_steps.rb +1 -1
- data/testing/cucumber/step_definitions/modeling_steps.rb +7 -2
- data/testing/cucumber/step_definitions/verification_steps.rb +11 -2
- data/testing/file_helper.rb +3 -0
- data/testing/gemfiles/gherkin2.gemfile +8 -0
- data/testing/gemfiles/gherkin3.gemfile +6 -0
- data/testing/gemfiles/gherkin4.gemfile +7 -0
- data/testing/gemfiles/gherkin5.gemfile +7 -0
- data/testing/gemfiles/gherkin6.gemfile +10 -0
- data/testing/gemfiles/gherkin7.gemfile +9 -0
- data/testing/gemfiles/gherkin8.gemfile +9 -0
- data/testing/gemfiles/gherkin9.gemfile +9 -0
- data/testing/helper_methods.rb +23 -0
- data/testing/rspec/spec/integration/{gherkin_2_adapter_spec.rb → adapters/gherkin_2_adapter_spec.rb} +13 -13
- data/testing/rspec/spec/integration/{gherkin_3_adapter_spec.rb → adapters/gherkin_3_adapter_spec.rb} +13 -13
- data/testing/rspec/spec/integration/{gherkin_4_adapter_spec.rb → adapters/gherkin_4_adapter_spec.rb} +13 -13
- data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +165 -0
- data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +159 -0
- data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +162 -0
- data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +162 -0
- data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +162 -0
- data/testing/rspec/spec/integration/{background_integration_spec.rb → models/background_integration_spec.rb} +90 -86
- data/testing/rspec/spec/integration/{cell_integration_spec.rb → models/cell_integration_spec.rb} +49 -38
- data/testing/rspec/spec/integration/{comment_integration_spec.rb → models/comment_integration_spec.rb} +31 -20
- data/testing/rspec/spec/integration/{directory_integration_spec.rb → models/directory_integration_spec.rb} +3 -3
- data/testing/rspec/spec/integration/{doc_string_integration_spec.rb → models/doc_string_integration_spec.rb} +39 -35
- data/testing/rspec/spec/integration/{example_integration_spec.rb → models/example_integration_spec.rb} +109 -83
- data/testing/rspec/spec/integration/{feature_file_integration_spec.rb → models/feature_file_integration_spec.rb} +52 -38
- data/testing/rspec/spec/integration/{feature_integration_spec.rb → models/feature_integration_spec.rb} +125 -112
- data/testing/rspec/spec/integration/{model_integration_spec.rb → models/model_integration_spec.rb} +1 -1
- data/testing/rspec/spec/integration/{outline_integration_spec.rb → models/outline_integration_spec.rb} +138 -129
- data/testing/rspec/spec/integration/{row_integration_spec.rb → models/row_integration_spec.rb} +55 -35
- data/testing/rspec/spec/integration/{scenario_integration_spec.rb → models/scenario_integration_spec.rb} +92 -88
- data/testing/rspec/spec/integration/models/step_integration_spec.rb +573 -0
- data/testing/rspec/spec/integration/{table_integration_spec.rb → models/table_integration_spec.rb} +38 -34
- data/testing/rspec/spec/integration/{tag_integration_spec.rb → models/tag_integration_spec.rb} +56 -36
- data/testing/rspec/spec/integration/parsing_integration_spec.rb +45 -7
- data/testing/rspec/spec/spec_helper.rb +79 -43
- data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +25 -0
- data/testing/rspec/spec/unit/{background_unit_spec.rb → models/background_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{cell_unit_spec.rb → models/cell_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{comment_unit_spec.rb → models/comment_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{directory_unit_spec.rb → models/directory_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{doc_string_unit_spec.rb → models/doc_string_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{example_unit_spec.rb → models/example_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{feature_file_unit_spec.rb → models/feature_file_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{feature_unit_spec.rb → models/feature_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{model_unit_spec.rb → models/model_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{outline_unit_spec.rb → models/outline_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{row_unit_spec.rb → models/row_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{scenario_unit_spec.rb → models/scenario_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{step_unit_spec.rb → models/step_unit_spec.rb} +2 -2
- data/testing/rspec/spec/unit/{table_unit_spec.rb → models/table_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/{tag_unit_spec.rb → models/tag_unit_spec.rb} +1 -1
- data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +102 -0
- data/todo.txt +5 -2
- metadata +80 -47
- data/History.md +0 -186
- data/testing/cucumber/support/transforms.rb +0 -3
- data/testing/rspec/spec/integration/step_integration_spec.rb +0 -459
data/testing/rspec/spec/integration/{table_integration_spec.rb → models/table_integration_spec.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}
|
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
|
-
|
25
|
-
table = clazz.new("| a table |")
|
26
|
-
data = table.parsing_data
|
24
|
+
describe 'parsing data' do
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
30
|
+
expect(data.keys).to match_array([:location, :rows])
|
31
|
+
expect(data[:location][:line]).to eq(5)
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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 = "#{
|
81
|
+
source_text = "#{FEATURE_KEYWORD}:
|
78
82
|
|
79
|
-
#{
|
80
|
-
#{
|
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) { "#{
|
132
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
129
133
|
|
130
|
-
#{
|
131
|
-
#{
|
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) { "#{
|
164
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
161
165
|
|
162
|
-
#{
|
163
|
-
#{
|
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) { "#{
|
186
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
183
187
|
|
184
|
-
#{
|
185
|
-
#{
|
188
|
+
#{OUTLINE_KEYWORD}: Test outline
|
189
|
+
#{STEP_KEYWORD} a step:
|
186
190
|
| a | table |
|
187
|
-
#{
|
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) { "#{
|
211
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
208
212
|
|
209
|
-
#{
|
210
|
-
#{
|
213
|
+
#{BACKGROUND_KEYWORD}: Test background
|
214
|
+
#{STEP_KEYWORD} a step:
|
211
215
|
| a | table |"
|
212
216
|
}
|
213
217
|
|
data/testing/rspec/spec/integration/{tag_integration_spec.rb → models/tag_integration_spec.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}
|
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
|
-
|
47
|
-
tag = clazz.new('@a_tag')
|
48
|
-
data = tag.parsing_data
|
46
|
+
describe 'parsing data' do
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
52
|
+
expect(data.keys).to match_array([:location, :name, :id])
|
53
|
+
expect(data[:name]).to eq('@a_tag')
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
#{
|
100
|
+
#{FEATURE_KEYWORD}: Test feature
|
81
101
|
|
82
|
-
#{
|
83
|
-
#{
|
102
|
+
#{OUTLINE_KEYWORD}: Test test
|
103
|
+
#{STEP_KEYWORD} a step
|
84
104
|
|
85
105
|
@example_tag
|
86
|
-
#{
|
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) { "#{
|
137
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
118
138
|
|
119
139
|
@a_tag
|
120
|
-
#{
|
121
|
-
#{
|
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) { "#{
|
159
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
140
160
|
|
141
161
|
@a_tag
|
142
|
-
#{
|
143
|
-
#{
|
144
|
-
#{
|
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) { "#{
|
184
|
+
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
165
185
|
|
166
|
-
#{
|
167
|
-
#{
|
186
|
+
#{OUTLINE_KEYWORD}: Test outline
|
187
|
+
#{STEP_KEYWORD} a step
|
168
188
|
@a_tag
|
169
|
-
#{
|
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 = "#{
|
228
|
+
source_text = "#{FEATURE_KEYWORD}:
|
209
229
|
|
210
230
|
@a_tag
|
211
|
-
#{
|
212
|
-
#{
|
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 '
|
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', :
|
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("#{
|
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("#{
|
64
|
+
result = nodule.parse_text("#{FEATURE_KEYWORD}:")
|
52
65
|
expect(result).to be_a(Array)
|
53
66
|
end
|
54
67
|
|
55
|
-
it 'raises
|
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
|
-
|
100
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
49
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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(:
|
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
|