cuke_modeler 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +11 -14
- data/cuke_modeler.gemspec +12 -9
- data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +12 -0
- data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +313 -5
- data/lib/cuke_modeler/models/background.rb +1 -1
- data/lib/cuke_modeler/models/cell.rb +1 -1
- data/lib/cuke_modeler/models/comment.rb +1 -1
- data/lib/cuke_modeler/models/directory.rb +2 -2
- data/lib/cuke_modeler/models/doc_string.rb +1 -1
- data/lib/cuke_modeler/models/example.rb +1 -1
- data/lib/cuke_modeler/models/feature.rb +1 -1
- data/lib/cuke_modeler/models/feature_file.rb +2 -2
- data/lib/cuke_modeler/models/outline.rb +1 -1
- data/lib/cuke_modeler/models/row.rb +1 -1
- data/lib/cuke_modeler/models/scenario.rb +1 -1
- data/lib/cuke_modeler/models/step.rb +1 -1
- data/lib/cuke_modeler/models/table.rb +1 -1
- data/lib/cuke_modeler/models/tag.rb +1 -1
- data/lib/cuke_modeler/parsing.rb +29 -58
- data/lib/cuke_modeler/version.rb +1 -1
- metadata +33 -151
- data/.gitignore +0 -18
- data/.simplecov +0 -7
- data/.travis.yml +0 -81
- data/Gemfile +0 -44
- data/Rakefile +0 -73
- data/appveyor.yml +0 -88
- data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +0 -274
- data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +0 -297
- data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +0 -309
- data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +0 -12
- data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +0 -310
- data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +0 -307
- data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +0 -12
- data/testing/cucumber/step_definitions/action_steps.rb +0 -13
- data/testing/cucumber/step_definitions/background_steps.rb +0 -1
- data/testing/cucumber/step_definitions/directory_steps.rb +0 -6
- data/testing/cucumber/step_definitions/doc_string_steps.rb +0 -1
- data/testing/cucumber/step_definitions/feature_file_steps.rb +0 -16
- data/testing/cucumber/step_definitions/feature_steps.rb +0 -7
- data/testing/cucumber/step_definitions/modeling_steps.rb +0 -49
- data/testing/cucumber/step_definitions/setup_steps.rb +0 -32
- data/testing/cucumber/step_definitions/step_steps.rb +0 -3
- data/testing/cucumber/step_definitions/table_steps.rb +0 -1
- data/testing/cucumber/step_definitions/tag_steps.rb +0 -3
- data/testing/cucumber/step_definitions/verification_steps.rb +0 -181
- data/testing/cucumber/support/env.rb +0 -30
- data/testing/dialect_helper.rb +0 -48
- data/testing/file_helper.rb +0 -47
- data/testing/gemfiles/gherkin2.gemfile +0 -33
- data/testing/gemfiles/gherkin3.gemfile +0 -26
- data/testing/gemfiles/gherkin4.gemfile +0 -27
- data/testing/gemfiles/gherkin5.gemfile +0 -27
- data/testing/gemfiles/gherkin6.gemfile +0 -10
- data/testing/gemfiles/gherkin7.gemfile +0 -9
- data/testing/gemfiles/gherkin8.gemfile +0 -9
- data/testing/gemfiles/gherkin9.gemfile +0 -9
- data/testing/helper_methods.rb +0 -23
- data/testing/rspec/spec/integration/adapters/gherkin_2_adapter_spec.rb +0 -166
- data/testing/rspec/spec/integration/adapters/gherkin_3_adapter_spec.rb +0 -166
- data/testing/rspec/spec/integration/adapters/gherkin_4_adapter_spec.rb +0 -165
- data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +0 -165
- data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +0 -159
- data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +0 -162
- data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +0 -162
- data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +0 -162
- data/testing/rspec/spec/integration/models/background_integration_spec.rb +0 -438
- data/testing/rspec/spec/integration/models/cell_integration_spec.rb +0 -338
- data/testing/rspec/spec/integration/models/comment_integration_spec.rb +0 -180
- data/testing/rspec/spec/integration/models/directory_integration_spec.rb +0 -218
- data/testing/rspec/spec/integration/models/doc_string_integration_spec.rb +0 -398
- data/testing/rspec/spec/integration/models/example_integration_spec.rb +0 -753
- data/testing/rspec/spec/integration/models/feature_file_integration_spec.rb +0 -276
- data/testing/rspec/spec/integration/models/feature_integration_spec.rb +0 -655
- data/testing/rspec/spec/integration/models/model_integration_spec.rb +0 -15
- data/testing/rspec/spec/integration/models/outline_integration_spec.rb +0 -619
- data/testing/rspec/spec/integration/models/row_integration_spec.rb +0 -303
- data/testing/rspec/spec/integration/models/scenario_integration_spec.rb +0 -475
- data/testing/rspec/spec/integration/models/step_integration_spec.rb +0 -573
- data/testing/rspec/spec/integration/models/table_integration_spec.rb +0 -333
- data/testing/rspec/spec/integration/models/tag_integration_spec.rb +0 -271
- data/testing/rspec/spec/integration/nested_integration_spec.rb +0 -91
- data/testing/rspec/spec/integration/parsing_integration_spec.rb +0 -143
- data/testing/rspec/spec/integration/shared/models_integration_specs.rb +0 -18
- data/testing/rspec/spec/spec_helper.rb +0 -129
- data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +0 -25
- data/testing/rspec/spec/unit/described_unit_spec.rb +0 -23
- data/testing/rspec/spec/unit/models/background_unit_spec.rb +0 -83
- data/testing/rspec/spec/unit/models/cell_unit_spec.rb +0 -68
- data/testing/rspec/spec/unit/models/comment_unit_spec.rb +0 -68
- data/testing/rspec/spec/unit/models/directory_unit_spec.rb +0 -127
- data/testing/rspec/spec/unit/models/doc_string_unit_spec.rb +0 -100
- data/testing/rspec/spec/unit/models/example_unit_spec.rb +0 -133
- data/testing/rspec/spec/unit/models/feature_file_unit_spec.rb +0 -125
- data/testing/rspec/spec/unit/models/feature_unit_spec.rb +0 -157
- data/testing/rspec/spec/unit/models/model_unit_spec.rb +0 -15
- data/testing/rspec/spec/unit/models/outline_unit_spec.rb +0 -117
- data/testing/rspec/spec/unit/models/row_unit_spec.rb +0 -68
- data/testing/rspec/spec/unit/models/scenario_unit_spec.rb +0 -86
- data/testing/rspec/spec/unit/models/step_unit_spec.rb +0 -109
- data/testing/rspec/spec/unit/models/table_unit_spec.rb +0 -77
- data/testing/rspec/spec/unit/models/tag_unit_spec.rb +0 -68
- data/testing/rspec/spec/unit/named_unit_spec.rb +0 -23
- data/testing/rspec/spec/unit/nested_unit_spec.rb +0 -43
- data/testing/rspec/spec/unit/parsed_unit_spec.rb +0 -27
- data/testing/rspec/spec/unit/parsing_unit_spec.rb +0 -54
- data/testing/rspec/spec/unit/shared/bare_bones_models_unit_specs.rb +0 -14
- data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +0 -127
- data/testing/rspec/spec/unit/shared/described_models_unit_specs.rb +0 -38
- data/testing/rspec/spec/unit/shared/keyworded_models_unit_specs.rb +0 -58
- data/testing/rspec/spec/unit/shared/models_unit_specs.rb +0 -15
- data/testing/rspec/spec/unit/shared/named_models_unit_specs.rb +0 -39
- data/testing/rspec/spec/unit/shared/nested_models_unit_specs.rb +0 -51
- data/testing/rspec/spec/unit/shared/parsed_models_unit_specs.rb +0 -39
- data/testing/rspec/spec/unit/shared/prepopulated_models_unit_specs.rb +0 -18
- data/testing/rspec/spec/unit/shared/sourced_models_unit_specs.rb +0 -39
- data/testing/rspec/spec/unit/shared/stepped_models_unit_specs.rb +0 -46
- data/testing/rspec/spec/unit/shared/stringifiable_models_unit_specs.rb +0 -18
- data/testing/rspec/spec/unit/shared/tagged_models_unit_specs.rb +0 -72
- data/testing/rspec/spec/unit/sourceable_unit_spec.rb +0 -27
- data/testing/rspec/spec/unit/stepped_unit_spec.rb +0 -23
- data/testing/rspec/spec/unit/taggable_unit_spec.rb +0 -69
- data/testing/test_languages.json +0 -45
- data/todo.txt +0 -25
@@ -1,438 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../../spec_helper"
|
2
|
-
|
3
|
-
|
4
|
-
describe 'Background, Integration' do
|
5
|
-
|
6
|
-
let(:clazz) { CukeModeler::Background }
|
7
|
-
|
8
|
-
|
9
|
-
describe 'common behavior' do
|
10
|
-
|
11
|
-
it_should_behave_like 'a model, integration'
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'unique behavior' do
|
16
|
-
|
17
|
-
it 'can be instantiated with the minimum viable Gherkin' do
|
18
|
-
source = "#{BACKGROUND_KEYWORD}:"
|
19
|
-
|
20
|
-
expect { clazz.new(source) }.to_not raise_error
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'can parse text that uses a non-default dialect' do
|
24
|
-
original_dialect = CukeModeler::Parsing.dialect
|
25
|
-
CukeModeler::Parsing.dialect = 'en-au'
|
26
|
-
|
27
|
-
begin
|
28
|
-
source_text = 'First off: Background name'
|
29
|
-
|
30
|
-
expect { @model = clazz.new(source_text) }.to_not raise_error
|
31
|
-
|
32
|
-
# Sanity check in case modeling failed in a non-explosive manner
|
33
|
-
expect(@model.name).to eq('Background name')
|
34
|
-
ensure
|
35
|
-
# Making sure that our changes don't escape a test and ruin the rest of the suite
|
36
|
-
CukeModeler::Parsing.dialect = original_dialect
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'parsing data' do
|
41
|
-
|
42
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
|
43
|
-
background = clazz.new("#{BACKGROUND_KEYWORD}: test background\ndescription\n#{STEP_KEYWORD} a step")
|
44
|
-
data = background.parsing_data
|
45
|
-
|
46
|
-
expect(data.keys).to match_array([:background, :rule, :scenario])
|
47
|
-
expect(data[:background][:name]).to eq('test background')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(3, 4, 5) do
|
51
|
-
background = clazz.new("#{BACKGROUND_KEYWORD}: test background\ndescription\n#{STEP_KEYWORD} a step")
|
52
|
-
data = background.parsing_data
|
53
|
-
|
54
|
-
expect(data.keys).to match_array([:type, :location, :keyword, :name, :steps, :description])
|
55
|
-
expect(data[:type]).to eq(:Background)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
|
59
|
-
background = clazz.new("#{BACKGROUND_KEYWORD}: test background\ndescription\n#{STEP_KEYWORD} a step")
|
60
|
-
data = background.parsing_data
|
61
|
-
|
62
|
-
expect(data.keys).to match_array(['keyword', 'name', 'line', 'description', 'steps', 'type'])
|
63
|
-
expect(data['keyword']).to eq('Background')
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'provides a descriptive filename when being parsed from stand alone text' do
|
69
|
-
source = "bad background text \n #{BACKGROUND_KEYWORD}:\n #{STEP_KEYWORD} a step\n @foo "
|
70
|
-
|
71
|
-
expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_background\.feature'/)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'properly sets its child models' do
|
75
|
-
source = "#{BACKGROUND_KEYWORD}: Test background
|
76
|
-
#{STEP_KEYWORD} a step"
|
77
|
-
|
78
|
-
background = clazz.new(source)
|
79
|
-
step = background.steps.first
|
80
|
-
|
81
|
-
expect(step.parent_model).to equal(background)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'trims whitespace from its source description' do
|
85
|
-
source = ["#{BACKGROUND_KEYWORD}:",
|
86
|
-
' ',
|
87
|
-
' description line 1',
|
88
|
-
'',
|
89
|
-
' description line 2',
|
90
|
-
' description line 3 ',
|
91
|
-
'',
|
92
|
-
'',
|
93
|
-
'',
|
94
|
-
" #{STEP_KEYWORD} a step"]
|
95
|
-
source = source.join("\n")
|
96
|
-
|
97
|
-
background = clazz.new(source)
|
98
|
-
description = background.description.split("\n", -1)
|
99
|
-
|
100
|
-
expect(description).to eq([' description line 1',
|
101
|
-
'',
|
102
|
-
'description line 2',
|
103
|
-
' description line 3'])
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
describe 'getting ancestors' do
|
108
|
-
|
109
|
-
before(:each) do
|
110
|
-
CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'background_test_file', :directory => test_directory)
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
115
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
116
|
-
|
117
|
-
#{BACKGROUND_KEYWORD}: Test background
|
118
|
-
#{STEP_KEYWORD} a step"
|
119
|
-
}
|
120
|
-
|
121
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
122
|
-
let(:background_model) { directory_model.feature_files.first.feature.background }
|
123
|
-
|
124
|
-
|
125
|
-
it 'can get its directory' do
|
126
|
-
ancestor = background_model.get_ancestor(:directory)
|
127
|
-
|
128
|
-
expect(ancestor).to equal(directory_model)
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'can get its feature file' do
|
132
|
-
ancestor = background_model.get_ancestor(:feature_file)
|
133
|
-
|
134
|
-
expect(ancestor).to equal(directory_model.feature_files.first)
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'can get its feature' do
|
138
|
-
ancestor = background_model.get_ancestor(:feature)
|
139
|
-
|
140
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'returns nil if it does not have the requested type of ancestor' do
|
144
|
-
ancestor = background_model.get_ancestor(:example)
|
145
|
-
|
146
|
-
expect(ancestor).to be_nil
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
describe 'model population' do
|
153
|
-
|
154
|
-
context 'from source text' do
|
155
|
-
|
156
|
-
let(:source_text) { "#{BACKGROUND_KEYWORD}:" }
|
157
|
-
let(:background) { clazz.new(source_text) }
|
158
|
-
|
159
|
-
|
160
|
-
it "models the background's keyword" do
|
161
|
-
expect(background.keyword).to eq("#{BACKGROUND_KEYWORD}")
|
162
|
-
end
|
163
|
-
|
164
|
-
it "models the background's source line" do
|
165
|
-
source_text = "#{FEATURE_KEYWORD}:
|
166
|
-
|
167
|
-
#{BACKGROUND_KEYWORD}: foo
|
168
|
-
#{STEP_KEYWORD} step"
|
169
|
-
background = CukeModeler::Feature.new(source_text).background
|
170
|
-
|
171
|
-
expect(background.source_line).to eq(3)
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'a filled background' do
|
175
|
-
|
176
|
-
let(:source_text) { "#{BACKGROUND_KEYWORD}: Background name
|
177
|
-
|
178
|
-
Background description.
|
179
|
-
|
180
|
-
Some more.
|
181
|
-
Even more.
|
182
|
-
|
183
|
-
#{STEP_KEYWORD} a step
|
184
|
-
#{STEP_KEYWORD} another step" }
|
185
|
-
let(:background) { clazz.new(source_text) }
|
186
|
-
|
187
|
-
|
188
|
-
it "models the background's name" do
|
189
|
-
expect(background.name).to eq('Background name')
|
190
|
-
end
|
191
|
-
|
192
|
-
it "models the background's description" do
|
193
|
-
description = background.description.split("\n", -1)
|
194
|
-
|
195
|
-
expect(description).to eq([' Background description.',
|
196
|
-
'',
|
197
|
-
'Some more.',
|
198
|
-
' Even more.'])
|
199
|
-
end
|
200
|
-
|
201
|
-
it "models the background's steps" do
|
202
|
-
step_names = background.steps.collect { |step| step.text }
|
203
|
-
|
204
|
-
expect(step_names).to eq(['a step', 'another step'])
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'an empty background' do
|
210
|
-
|
211
|
-
let(:source_text) { "#{BACKGROUND_KEYWORD}:" }
|
212
|
-
let(:background) { clazz.new(source_text) }
|
213
|
-
|
214
|
-
|
215
|
-
it "models the background's name" do
|
216
|
-
expect(background.name).to eq('')
|
217
|
-
end
|
218
|
-
|
219
|
-
it "models the background's description" do
|
220
|
-
expect(background.description).to eq('')
|
221
|
-
end
|
222
|
-
|
223
|
-
it "models the background's steps" do
|
224
|
-
expect(background.steps).to eq([])
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
describe 'comparison' do
|
235
|
-
|
236
|
-
it 'is equal to a background with the same steps' do
|
237
|
-
source = "#{BACKGROUND_KEYWORD}:
|
238
|
-
#{STEP_KEYWORD} step 1
|
239
|
-
#{STEP_KEYWORD} step 2"
|
240
|
-
background_1 = clazz.new(source)
|
241
|
-
|
242
|
-
source = "#{BACKGROUND_KEYWORD}:
|
243
|
-
#{STEP_KEYWORD} step 1
|
244
|
-
#{STEP_KEYWORD} step 2"
|
245
|
-
background_2 = clazz.new(source)
|
246
|
-
|
247
|
-
source = "#{BACKGROUND_KEYWORD}:
|
248
|
-
#{STEP_KEYWORD} step 2
|
249
|
-
#{STEP_KEYWORD} step 1"
|
250
|
-
background_3 = clazz.new(source)
|
251
|
-
|
252
|
-
|
253
|
-
expect(background_1).to eq(background_2)
|
254
|
-
expect(background_1).to_not eq(background_3)
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'is equal to a scenario with the same steps' do
|
258
|
-
source = "#{BACKGROUND_KEYWORD}:
|
259
|
-
#{STEP_KEYWORD} step 1
|
260
|
-
#{STEP_KEYWORD} step 2"
|
261
|
-
background = clazz.new(source)
|
262
|
-
|
263
|
-
source = "#{SCENARIO_KEYWORD}:
|
264
|
-
#{STEP_KEYWORD} step 1
|
265
|
-
#{STEP_KEYWORD} step 2"
|
266
|
-
scenario_1 = CukeModeler::Scenario.new(source)
|
267
|
-
|
268
|
-
source = "#{SCENARIO_KEYWORD}:
|
269
|
-
#{STEP_KEYWORD} step 2
|
270
|
-
#{STEP_KEYWORD} step 1"
|
271
|
-
scenario_2 = CukeModeler::Scenario.new(source)
|
272
|
-
|
273
|
-
|
274
|
-
expect(background).to eq(scenario_1)
|
275
|
-
expect(background).to_not eq(scenario_2)
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'is equal to an outline with the same steps' do
|
279
|
-
source = "#{BACKGROUND_KEYWORD}:
|
280
|
-
#{STEP_KEYWORD} step 1
|
281
|
-
#{STEP_KEYWORD} step 2"
|
282
|
-
background = clazz.new(source)
|
283
|
-
|
284
|
-
source = "#{OUTLINE_KEYWORD}:
|
285
|
-
#{STEP_KEYWORD} step 1
|
286
|
-
#{STEP_KEYWORD} step 2
|
287
|
-
#{EXAMPLE_KEYWORD}:
|
288
|
-
| param |
|
289
|
-
| value |"
|
290
|
-
outline_1 = CukeModeler::Outline.new(source)
|
291
|
-
|
292
|
-
source = "#{OUTLINE_KEYWORD}:
|
293
|
-
#{STEP_KEYWORD} step 2
|
294
|
-
#{STEP_KEYWORD} step 1
|
295
|
-
#{EXAMPLE_KEYWORD}:
|
296
|
-
| param |
|
297
|
-
| value |"
|
298
|
-
outline_2 = CukeModeler::Outline.new(source)
|
299
|
-
|
300
|
-
|
301
|
-
expect(background).to eq(outline_1)
|
302
|
-
expect(background).to_not eq(outline_2)
|
303
|
-
end
|
304
|
-
|
305
|
-
end
|
306
|
-
|
307
|
-
|
308
|
-
describe 'background output' do
|
309
|
-
|
310
|
-
it 'can be remade from its own output' do
|
311
|
-
source = "#{BACKGROUND_KEYWORD}: A background with everything it could have
|
312
|
-
|
313
|
-
Including a description
|
314
|
-
and then some.
|
315
|
-
|
316
|
-
#{STEP_KEYWORD} a step
|
317
|
-
| value |
|
318
|
-
#{STEP_KEYWORD} another step
|
319
|
-
\"\"\"
|
320
|
-
some string
|
321
|
-
\"\"\""
|
322
|
-
background = clazz.new(source)
|
323
|
-
|
324
|
-
background_output = background.to_s
|
325
|
-
remade_background_output = clazz.new(background_output).to_s
|
326
|
-
|
327
|
-
expect(remade_background_output).to eq(background_output)
|
328
|
-
end
|
329
|
-
|
330
|
-
|
331
|
-
context 'from source text' do
|
332
|
-
|
333
|
-
it 'can output an empty background' do
|
334
|
-
source = ["#{BACKGROUND_KEYWORD}:"]
|
335
|
-
source = source.join("\n")
|
336
|
-
background = clazz.new(source)
|
337
|
-
|
338
|
-
background_output = background.to_s.split("\n", -1)
|
339
|
-
|
340
|
-
expect(background_output).to eq(["#{BACKGROUND_KEYWORD}:"])
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'can output a background that has a name' do
|
344
|
-
source = ["#{BACKGROUND_KEYWORD}: test background"]
|
345
|
-
source = source.join("\n")
|
346
|
-
background = clazz.new(source)
|
347
|
-
|
348
|
-
background_output = background.to_s.split("\n", -1)
|
349
|
-
|
350
|
-
expect(background_output).to eq(["#{BACKGROUND_KEYWORD}: test background"])
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'can output a background that has a description' do
|
354
|
-
source = ["#{BACKGROUND_KEYWORD}:",
|
355
|
-
'Some description.',
|
356
|
-
'Some more description.']
|
357
|
-
source = source.join("\n")
|
358
|
-
background = clazz.new(source)
|
359
|
-
|
360
|
-
background_output = background.to_s.split("\n", -1)
|
361
|
-
|
362
|
-
expect(background_output).to eq(["#{BACKGROUND_KEYWORD}:",
|
363
|
-
'',
|
364
|
-
'Some description.',
|
365
|
-
'Some more description.'])
|
366
|
-
end
|
367
|
-
|
368
|
-
it 'can output a background that has steps' do
|
369
|
-
source = ["#{BACKGROUND_KEYWORD}:",
|
370
|
-
"#{STEP_KEYWORD} a step",
|
371
|
-
'|value|',
|
372
|
-
"#{STEP_KEYWORD} another step",
|
373
|
-
'"""',
|
374
|
-
'some string',
|
375
|
-
'"""']
|
376
|
-
source = source.join("\n")
|
377
|
-
background = clazz.new(source)
|
378
|
-
|
379
|
-
background_output = background.to_s.split("\n", -1)
|
380
|
-
|
381
|
-
expect(background_output).to eq(["#{BACKGROUND_KEYWORD}:",
|
382
|
-
" #{STEP_KEYWORD} a step",
|
383
|
-
' | value |',
|
384
|
-
" #{STEP_KEYWORD} another step",
|
385
|
-
' """',
|
386
|
-
' some string',
|
387
|
-
' """'])
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'can output a background that has everything' do
|
391
|
-
source = ["#{BACKGROUND_KEYWORD}: A background with everything it could have",
|
392
|
-
'Including a description',
|
393
|
-
'and then some.',
|
394
|
-
"#{STEP_KEYWORD} a step",
|
395
|
-
'|value|',
|
396
|
-
"#{STEP_KEYWORD} another step",
|
397
|
-
'"""',
|
398
|
-
'some string',
|
399
|
-
'"""']
|
400
|
-
source = source.join("\n")
|
401
|
-
background = clazz.new(source)
|
402
|
-
|
403
|
-
background_output = background.to_s.split("\n", -1)
|
404
|
-
|
405
|
-
expect(background_output).to eq(["#{BACKGROUND_KEYWORD}: A background with everything it could have",
|
406
|
-
'',
|
407
|
-
'Including a description',
|
408
|
-
'and then some.',
|
409
|
-
'',
|
410
|
-
" #{STEP_KEYWORD} a step",
|
411
|
-
' | value |',
|
412
|
-
" #{STEP_KEYWORD} another step",
|
413
|
-
' """',
|
414
|
-
' some string',
|
415
|
-
' """'])
|
416
|
-
end
|
417
|
-
|
418
|
-
end
|
419
|
-
|
420
|
-
|
421
|
-
context 'from abstract instantiation' do
|
422
|
-
|
423
|
-
let(:background) { clazz.new }
|
424
|
-
|
425
|
-
|
426
|
-
it 'can output a background that has only steps' do
|
427
|
-
background.steps = [CukeModeler::Step.new]
|
428
|
-
|
429
|
-
expect { background.to_s }.to_not raise_error
|
430
|
-
end
|
431
|
-
|
432
|
-
end
|
433
|
-
|
434
|
-
end
|
435
|
-
|
436
|
-
end
|
437
|
-
|
438
|
-
end
|
@@ -1,338 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../../spec_helper"
|
2
|
-
|
3
|
-
|
4
|
-
describe 'Cell, Integration' do
|
5
|
-
|
6
|
-
let(:clazz) { CukeModeler::Cell }
|
7
|
-
|
8
|
-
|
9
|
-
describe 'common behavior' do
|
10
|
-
|
11
|
-
it_should_behave_like 'a model, integration'
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
describe 'unique behavior' do
|
17
|
-
|
18
|
-
it 'can be instantiated with the minimum viable Gherkin' do
|
19
|
-
source = ''
|
20
|
-
|
21
|
-
expect { clazz.new(source) }.to_not raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'can parse text that uses a non-default dialect' do
|
25
|
-
original_dialect = CukeModeler::Parsing.dialect
|
26
|
-
CukeModeler::Parsing.dialect = 'en-au'
|
27
|
-
|
28
|
-
begin
|
29
|
-
source_text = 'foo'
|
30
|
-
|
31
|
-
expect { @model = clazz.new(source_text) }.to_not raise_error
|
32
|
-
|
33
|
-
# Sanity check in case modeling failed in a non-explosive manner
|
34
|
-
expect(@model.value).to eq('foo')
|
35
|
-
ensure
|
36
|
-
# Making sure that our changes don't escape a test and ruin the rest of the suite
|
37
|
-
CukeModeler::Parsing.dialect = original_dialect
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'provides a descriptive filename when being parsed from stand alone text' do
|
42
|
-
source = "not a \n cell"
|
43
|
-
|
44
|
-
expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_cell\.feature'/)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'parsing data' do
|
48
|
-
|
49
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
|
50
|
-
cell = clazz.new('a cell')
|
51
|
-
data = cell.parsing_data
|
52
|
-
|
53
|
-
expect(data.keys).to match_array([:location, :value])
|
54
|
-
expect(data[:value]).to eq('a cell')
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(4, 5) do
|
58
|
-
cell = clazz.new('a cell')
|
59
|
-
data = cell.parsing_data
|
60
|
-
|
61
|
-
expect(data.keys).to match_array([:type, :location, :value])
|
62
|
-
expect(data[:type]).to eq(:TableCell)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(3) do
|
66
|
-
cell = clazz.new("a cell")
|
67
|
-
data = cell.parsing_data
|
68
|
-
|
69
|
-
expect(data.keys).to match_array([:type, :location, :value])
|
70
|
-
expect(data[:type]).to eq('TableCell')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
|
74
|
-
cell = clazz.new("a cell")
|
75
|
-
data = cell.parsing_data
|
76
|
-
|
77
|
-
# Cells did not exist as full fledged objects in the Gherkin2 parser
|
78
|
-
expect(data).to eq('a cell')
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
describe 'getting ancestors' do
|
84
|
-
|
85
|
-
before(:each) do
|
86
|
-
CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'cell_test_file', :directory => test_directory)
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
91
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
92
|
-
|
93
|
-
#{SCENARIO_KEYWORD}: Test test
|
94
|
-
#{STEP_KEYWORD} a step
|
95
|
-
| a value |"
|
96
|
-
}
|
97
|
-
|
98
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
99
|
-
let(:cell_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
|
100
|
-
|
101
|
-
|
102
|
-
it 'can get its directory' do
|
103
|
-
ancestor = cell_model.get_ancestor(:directory)
|
104
|
-
|
105
|
-
expect(ancestor).to equal(directory_model)
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'can get its feature file' do
|
109
|
-
ancestor = cell_model.get_ancestor(:feature_file)
|
110
|
-
|
111
|
-
expect(ancestor).to equal(directory_model.feature_files.first)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'can get its feature' do
|
115
|
-
ancestor = cell_model.get_ancestor(:feature)
|
116
|
-
|
117
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature)
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'a cell that is part of an outline' do
|
121
|
-
|
122
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
123
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
124
|
-
|
125
|
-
#{OUTLINE_KEYWORD}: Test outline
|
126
|
-
#{STEP_KEYWORD} a step
|
127
|
-
#{EXAMPLE_KEYWORD}:
|
128
|
-
| param |
|
129
|
-
| value |"
|
130
|
-
}
|
131
|
-
|
132
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
133
|
-
let(:cell_model) { directory_model.feature_files.first.feature.tests.first.examples.first.rows.first.cells.first }
|
134
|
-
|
135
|
-
|
136
|
-
it 'can get its outline' do
|
137
|
-
ancestor = cell_model.get_ancestor(:outline)
|
138
|
-
|
139
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'can get its example' do
|
143
|
-
ancestor = cell_model.get_ancestor(:example)
|
144
|
-
|
145
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.examples.first)
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'can get its row' do
|
149
|
-
ancestor = cell_model.get_ancestor(:row)
|
150
|
-
|
151
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.examples.first.rows.first)
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
context 'a cell that is part of a scenario' do
|
158
|
-
|
159
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
160
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
161
|
-
|
162
|
-
#{SCENARIO_KEYWORD}: Test test
|
163
|
-
#{STEP_KEYWORD} a step:
|
164
|
-
| a | table |"
|
165
|
-
}
|
166
|
-
|
167
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
168
|
-
let(:cell_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
|
169
|
-
|
170
|
-
|
171
|
-
it 'can get its scenario' do
|
172
|
-
ancestor = cell_model.get_ancestor(:scenario)
|
173
|
-
|
174
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'a cell that is part of a background' do
|
180
|
-
|
181
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
182
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
183
|
-
|
184
|
-
#{BACKGROUND_KEYWORD}: Test background
|
185
|
-
#{STEP_KEYWORD} a step:
|
186
|
-
| a | table |"
|
187
|
-
}
|
188
|
-
|
189
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
190
|
-
let(:cell_model) { directory_model.feature_files.first.feature.background.steps.first.block.rows.first.cells.first }
|
191
|
-
|
192
|
-
|
193
|
-
it 'can get its background' do
|
194
|
-
ancestor = cell_model.get_ancestor(:background)
|
195
|
-
|
196
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.background)
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'a cell that is part of a step' do
|
202
|
-
|
203
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
204
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
205
|
-
|
206
|
-
#{SCENARIO_KEYWORD}: Test test
|
207
|
-
#{STEP_KEYWORD} a step:
|
208
|
-
| a | table |"
|
209
|
-
}
|
210
|
-
|
211
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
212
|
-
let(:cell_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
|
213
|
-
|
214
|
-
|
215
|
-
it 'can get its step' do
|
216
|
-
ancestor = cell_model.get_ancestor(:step)
|
217
|
-
|
218
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first)
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'can get its table' do
|
222
|
-
ancestor = cell_model.get_ancestor(:table)
|
223
|
-
|
224
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first.block)
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'can get its row' do
|
228
|
-
ancestor = cell_model.get_ancestor(:row)
|
229
|
-
|
230
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first)
|
231
|
-
end
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'returns nil if it does not have the requested type of ancestor' do
|
236
|
-
ancestor = cell_model.get_ancestor(:example)
|
237
|
-
|
238
|
-
expect(ancestor).to be_nil
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
describe 'model population' do
|
245
|
-
|
246
|
-
context 'from source text' do
|
247
|
-
|
248
|
-
let(:source_text) { 'a cell' }
|
249
|
-
let(:cell) { clazz.new(source_text) }
|
250
|
-
|
251
|
-
|
252
|
-
it "models the cell's value" do
|
253
|
-
expect(cell.value).to eq('a cell')
|
254
|
-
end
|
255
|
-
|
256
|
-
it "models the cell's source line" do
|
257
|
-
source_text = "#{FEATURE_KEYWORD}:
|
258
|
-
|
259
|
-
#{SCENARIO_KEYWORD}:
|
260
|
-
#{STEP_KEYWORD} a step
|
261
|
-
| value |"
|
262
|
-
cell = CukeModeler::Feature.new(source_text).tests.first.steps.first.block.rows.first.cells.first
|
263
|
-
|
264
|
-
expect(cell.source_line).to eq(5)
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
end
|
270
|
-
|
271
|
-
|
272
|
-
describe 'cell output' do
|
273
|
-
|
274
|
-
it 'can be remade from its own output' do
|
275
|
-
source = 'a \\\\ complex \| cell'
|
276
|
-
cell = clazz.new(source)
|
277
|
-
|
278
|
-
cell_output = cell.to_s
|
279
|
-
remade_cell_output = clazz.new(cell_output).to_s
|
280
|
-
|
281
|
-
expect(remade_cell_output).to eq(cell_output)
|
282
|
-
end
|
283
|
-
|
284
|
-
|
285
|
-
context 'from source text' do
|
286
|
-
|
287
|
-
it 'can output a cell' do
|
288
|
-
source = 'a cell'
|
289
|
-
cell = clazz.new(source)
|
290
|
-
|
291
|
-
expect(cell.to_s).to eq('a cell')
|
292
|
-
end
|
293
|
-
|
294
|
-
# Because vertical bars mark the beginning and end of a cell, any vertical bars inside
|
295
|
-
# of the cell (which would have had to have been escaped to get inside of the cell in
|
296
|
-
# the first place) will be escaped when outputted so as to retain the quality of being
|
297
|
-
# able to use the output directly as Gherkin.
|
298
|
-
|
299
|
-
it 'can output a cell that has vertical bars in it' do
|
300
|
-
source = 'cell with a \| in it'
|
301
|
-
cell = clazz.new(source)
|
302
|
-
|
303
|
-
cell_output = cell.to_s
|
304
|
-
|
305
|
-
expect(cell_output).to eq('cell with a \| in it')
|
306
|
-
end
|
307
|
-
|
308
|
-
# Because backslashes are used to escape special characters, any backslashes inside
|
309
|
-
# of the cell (which would have had to have been escaped to get inside of the cell in
|
310
|
-
# the first place) will be escaped when outputted so as to retain the quality of being
|
311
|
-
# able to use the output directly as Gherkin.
|
312
|
-
|
313
|
-
it 'can output a cell that has backslashes in it' do
|
314
|
-
source = 'cell with a \\\\ in it'
|
315
|
-
cell = clazz.new(source)
|
316
|
-
|
317
|
-
cell_output = cell.to_s
|
318
|
-
|
319
|
-
expect(cell_output).to eq('cell with a \\\\ in it')
|
320
|
-
end
|
321
|
-
|
322
|
-
# Depending on the order in which special characters are escaped, extra backslashes might occur.
|
323
|
-
it 'can output a cell that has several kinds of special characters in it' do
|
324
|
-
source = 'cell with a \\\\ and \| in it'
|
325
|
-
cell = clazz.new(source)
|
326
|
-
|
327
|
-
cell_output = cell.to_s
|
328
|
-
|
329
|
-
expect(cell_output).to eq('cell with a \\\\ and \| in it')
|
330
|
-
end
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
end
|