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,753 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../../spec_helper"
|
2
|
-
|
3
|
-
|
4
|
-
describe 'Example, Integration' do
|
5
|
-
|
6
|
-
let(:clazz) { CukeModeler::Example }
|
7
|
-
let(:example) { clazz.new }
|
8
|
-
|
9
|
-
|
10
|
-
describe 'common behavior' do
|
11
|
-
|
12
|
-
it_should_behave_like 'a model, integration'
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'unique behavior' do
|
17
|
-
|
18
|
-
it 'can be instantiated with the minimum viable Gherkin', :if => gherkin?(4, 5, 6, 7, 8, 9) do
|
19
|
-
source = "#{EXAMPLE_KEYWORD}:"
|
20
|
-
|
21
|
-
expect { @model = clazz.new(source) }.to_not raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'can be instantiated with the minimum viable Gherkin', :if => gherkin?(3) do
|
25
|
-
source = "#{EXAMPLE_KEYWORD}:
|
26
|
-
|param|
|
27
|
-
|value|"
|
28
|
-
|
29
|
-
expect { @model = clazz.new(source) }.to_not raise_error
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'can be instantiated with the minimum viable Gherkin', :if => gherkin?(2) do
|
33
|
-
source = "#{EXAMPLE_KEYWORD}:
|
34
|
-
|param|"
|
35
|
-
|
36
|
-
expect { @model = clazz.new(source) }.to_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'can parse text that uses a non-default dialect' do
|
40
|
-
original_dialect = CukeModeler::Parsing.dialect
|
41
|
-
CukeModeler::Parsing.dialect = 'en-au'
|
42
|
-
|
43
|
-
begin
|
44
|
-
source_text = "You'll wanna:
|
45
|
-
| param |
|
46
|
-
| value |"
|
47
|
-
|
48
|
-
expect { @model = clazz.new(source_text) }.to_not raise_error
|
49
|
-
|
50
|
-
# Sanity check in case modeling failed in a non-explosive manner
|
51
|
-
expect(@model.rows.first.cells.first.value).to eq('param')
|
52
|
-
ensure
|
53
|
-
# Making sure that our changes don't escape a test and ruin the rest of the suite
|
54
|
-
CukeModeler::Parsing.dialect = original_dialect
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'parsing data' do
|
59
|
-
|
60
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
|
61
|
-
example = clazz.new("@tag\n#{EXAMPLE_KEYWORD}: test example\ndescription\n|param|\n|value|")
|
62
|
-
data = example.parsing_data
|
63
|
-
|
64
|
-
expect(data.keys).to match_array([:tags, :location, :keyword, :name, :table_header, :table_body, :description])
|
65
|
-
expect(data[:name]).to eq('test example')
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(3, 4, 5) do
|
69
|
-
example = clazz.new("@tag\n#{EXAMPLE_KEYWORD}: test example\ndescription\n|param|\n|value|")
|
70
|
-
data = example.parsing_data
|
71
|
-
|
72
|
-
expect(data.keys).to match_array([:type, :tags, :location, :keyword, :name, :tableHeader, :tableBody, :description])
|
73
|
-
expect(data[:type]).to eq(:Examples)
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
|
77
|
-
example = clazz.new("@tag\n#{EXAMPLE_KEYWORD}: test example\ndescription\n|param|\n|value|")
|
78
|
-
data = example.parsing_data
|
79
|
-
|
80
|
-
expect(data.keys).to match_array(['keyword', 'name', 'line', 'description', 'id', 'rows', 'tags'])
|
81
|
-
expect(data['keyword']).to eq('Examples')
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'provides a descriptive filename when being parsed from stand alone text' do
|
87
|
-
source = 'bad example text'
|
88
|
-
|
89
|
-
expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_example\.feature'/)
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'trims whitespace from its source description' do
|
93
|
-
source = ["#{EXAMPLE_KEYWORD}:",
|
94
|
-
' ',
|
95
|
-
' description line 1',
|
96
|
-
'',
|
97
|
-
' description line 2',
|
98
|
-
' description line 3 ',
|
99
|
-
'',
|
100
|
-
'',
|
101
|
-
'',
|
102
|
-
'|param|',
|
103
|
-
'|value|']
|
104
|
-
source = source.join("\n")
|
105
|
-
|
106
|
-
example = clazz.new(source)
|
107
|
-
description = example.description.split("\n", -1)
|
108
|
-
|
109
|
-
expect(description).to eq([' description line 1',
|
110
|
-
'',
|
111
|
-
'description line 2',
|
112
|
-
' description line 3'])
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
describe 'model population' do
|
117
|
-
|
118
|
-
context 'from source text' do
|
119
|
-
|
120
|
-
let(:source_text) { "#{EXAMPLE_KEYWORD}:" }
|
121
|
-
let(:example) { clazz.new(source_text) }
|
122
|
-
|
123
|
-
|
124
|
-
# gherkin 2.x/3.x does not accept incomplete examples
|
125
|
-
it "models the example's keyword", :unless => gherkin?(2, 3) do
|
126
|
-
expect(example.keyword).to eq("#{EXAMPLE_KEYWORD}")
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'using gherkin 2.x', :if => gherkin?(2) do
|
130
|
-
|
131
|
-
let(:source_text) { "#{EXAMPLE_KEYWORD}:\n|param|" }
|
132
|
-
let(:example) { clazz.new(source_text) }
|
133
|
-
|
134
|
-
it "models the example's keyword" do
|
135
|
-
expect(example.keyword).to eq(EXAMPLE_KEYWORD)
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
context 'using gherkin 3.x', :if => gherkin?(3) do
|
141
|
-
|
142
|
-
let(:source_text) { "#{EXAMPLE_KEYWORD}:\n|param|\n|value|" }
|
143
|
-
let(:example) { clazz.new(source_text) }
|
144
|
-
|
145
|
-
it "models the example's keyword" do
|
146
|
-
expect(example.keyword).to eq(EXAMPLE_KEYWORD)
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
it "models the example's source line" do
|
152
|
-
source_text = "#{FEATURE_KEYWORD}:
|
153
|
-
|
154
|
-
#{OUTLINE_KEYWORD}:
|
155
|
-
#{STEP_KEYWORD} step
|
156
|
-
#{EXAMPLE_KEYWORD}:
|
157
|
-
| param |
|
158
|
-
| value |"
|
159
|
-
example = CukeModeler::Feature.new(source_text).tests.first.examples.first
|
160
|
-
|
161
|
-
expect(example.source_line).to eq(5)
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
context 'a filled example' do
|
166
|
-
|
167
|
-
let(:source_text) { "@tag1 @tag2 @tag3
|
168
|
-
#{EXAMPLE_KEYWORD}: test example
|
169
|
-
|
170
|
-
Some example description.
|
171
|
-
|
172
|
-
Some more.
|
173
|
-
Even more.
|
174
|
-
|
175
|
-
| param |
|
176
|
-
| value |" }
|
177
|
-
let(:example) { clazz.new(source_text) }
|
178
|
-
|
179
|
-
|
180
|
-
it "models the example's name" do
|
181
|
-
expect(example.name).to eq('test example')
|
182
|
-
end
|
183
|
-
|
184
|
-
it "models the example's description" do
|
185
|
-
description = example.description.split("\n", -1)
|
186
|
-
|
187
|
-
expect(description).to eq([' Some example description.',
|
188
|
-
'',
|
189
|
-
'Some more.',
|
190
|
-
' Even more.'])
|
191
|
-
end
|
192
|
-
|
193
|
-
it "models the example's rows" do
|
194
|
-
row_cell_values = example.rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
195
|
-
|
196
|
-
expect(row_cell_values).to eq([['param'], ['value']])
|
197
|
-
end
|
198
|
-
|
199
|
-
it "models the example's tags" do
|
200
|
-
tag_names = example.tags.collect { |tag| tag.name }
|
201
|
-
|
202
|
-
expect(tag_names).to eq(['@tag1', '@tag2', '@tag3'])
|
203
|
-
end
|
204
|
-
|
205
|
-
it "models the example's parameters" do
|
206
|
-
expect(example.parameters).to eq(['param'])
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
# gherkin 2.x/3.x does not accept incomplete examples
|
212
|
-
context 'an empty example', :unless => gherkin?(2, 3) do
|
213
|
-
|
214
|
-
let(:source_text) { "#{EXAMPLE_KEYWORD}:" }
|
215
|
-
let(:example) { clazz.new(source_text) }
|
216
|
-
|
217
|
-
|
218
|
-
it "models the example's name" do
|
219
|
-
expect(example.name).to eq('')
|
220
|
-
end
|
221
|
-
|
222
|
-
it "models the example's description" do
|
223
|
-
expect(example.description).to eq('')
|
224
|
-
end
|
225
|
-
|
226
|
-
it "models the example's rows" do
|
227
|
-
expect(example.rows).to eq([])
|
228
|
-
end
|
229
|
-
|
230
|
-
it "models the example's tags" do
|
231
|
-
expect(example.tags).to eq([])
|
232
|
-
end
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
end
|
239
|
-
|
240
|
-
|
241
|
-
it 'properly sets its child models' do
|
242
|
-
source = "@a_tag
|
243
|
-
#{EXAMPLE_KEYWORD}:
|
244
|
-
| param |
|
245
|
-
| value 1 |"
|
246
|
-
|
247
|
-
example = clazz.new(source)
|
248
|
-
rows = example.rows
|
249
|
-
tag = example.tags.first
|
250
|
-
|
251
|
-
expect(rows[0].parent_model).to equal(example)
|
252
|
-
expect(rows[1].parent_model).to equal(example)
|
253
|
-
expect(tag.parent_model).to equal(example)
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'does not include the parameter row when accessing argument rows' do
|
257
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
|
258
|
-
example = clazz.new(source)
|
259
|
-
|
260
|
-
rows = example.argument_rows
|
261
|
-
row_cell_values = rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
262
|
-
|
263
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', 'value4']])
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'does not include argument rows when accessing the parameter row' do
|
267
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
|
268
|
-
example = clazz.new(source)
|
269
|
-
|
270
|
-
row = example.parameter_row
|
271
|
-
row_cell_values = row.cells.collect { |cell| cell.value }
|
272
|
-
|
273
|
-
expect(row_cell_values).to eq(['param1', 'param2'])
|
274
|
-
end
|
275
|
-
|
276
|
-
|
277
|
-
describe 'adding rows' do
|
278
|
-
|
279
|
-
it 'can add a new row as a hash, string values' do
|
280
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
281
|
-
example = clazz.new(source)
|
282
|
-
|
283
|
-
new_row = {'param1' => 'value3', 'param2' => 'value4'}
|
284
|
-
example.add_row(new_row)
|
285
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
286
|
-
|
287
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', 'value4']])
|
288
|
-
end
|
289
|
-
|
290
|
-
it 'can add a new row as a hash, non-string values' do
|
291
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
292
|
-
example = clazz.new(source)
|
293
|
-
|
294
|
-
new_row = {:param1 => 'value3', 'param2' => 4}
|
295
|
-
example.add_row(new_row)
|
296
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
297
|
-
|
298
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', '4']])
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'can add a new row as a hash, random key order' do
|
302
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
303
|
-
example = clazz.new(source)
|
304
|
-
|
305
|
-
new_row = {'param2' => 'value4', 'param1' => 'value3'}
|
306
|
-
example.add_row(new_row)
|
307
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
308
|
-
|
309
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', 'value4']])
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'can add a new row as an array, string values' do
|
313
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
314
|
-
example = clazz.new(source)
|
315
|
-
|
316
|
-
new_row = ['value3', 'value4']
|
317
|
-
example.add_row(new_row)
|
318
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
319
|
-
|
320
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', 'value4']])
|
321
|
-
end
|
322
|
-
|
323
|
-
it 'can add a new row as an array, non-string values' do
|
324
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|param3|\n|value1|value2|value3|"
|
325
|
-
example = clazz.new(source)
|
326
|
-
|
327
|
-
new_row = [:value4, 5, 'value6']
|
328
|
-
example.add_row(new_row)
|
329
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
330
|
-
|
331
|
-
expect(row_cell_values).to eq([['value1', 'value2', 'value3'], ['value4', '5', 'value6']])
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'can only use a Hash or an Array to add a new row' do
|
335
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param|\n|value|"
|
336
|
-
example = clazz.new(source)
|
337
|
-
|
338
|
-
expect { example.add_row({}) }.to_not raise_error
|
339
|
-
expect { example.add_row([]) }.to_not raise_error
|
340
|
-
expect { example.add_row(:a_row) }.to raise_error(ArgumentError)
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'trims whitespace from added rows' do
|
344
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
345
|
-
example = clazz.new(source)
|
346
|
-
|
347
|
-
hash_row = {'param1' => 'value3 ', 'param2' => ' value4'}
|
348
|
-
array_row = ['value5', ' value6 ']
|
349
|
-
example.add_row(hash_row)
|
350
|
-
example.add_row(array_row)
|
351
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
352
|
-
|
353
|
-
expect(row_cell_values).to eq([['value1', 'value2'], ['value3', 'value4'], ['value5', 'value6']])
|
354
|
-
end
|
355
|
-
|
356
|
-
it 'will complain if a row is added and no parameters have been set' do
|
357
|
-
example = clazz.new
|
358
|
-
example.rows = []
|
359
|
-
|
360
|
-
new_row = ['value1', 'value2']
|
361
|
-
expect { example.add_row(new_row) }.to raise_error('Cannot add a row. No parameters have been set.')
|
362
|
-
|
363
|
-
new_row = {'param1' => 'value1', 'param2' => 'value2'}
|
364
|
-
expect { example.add_row(new_row) }.to raise_error('Cannot add a row. No parameters have been set.')
|
365
|
-
end
|
366
|
-
|
367
|
-
it 'does not modify its row input' do
|
368
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
369
|
-
example = clazz.new(source)
|
370
|
-
|
371
|
-
array_row = ['value1'.freeze, 'value2'.freeze].freeze
|
372
|
-
expect { example.add_row(array_row) }.to_not raise_error
|
373
|
-
|
374
|
-
hash_row = {'param1'.freeze => 'value1'.freeze, 'param2'.freeze => 'value2'.freeze}.freeze
|
375
|
-
expect { example.add_row(hash_row) }.to_not raise_error
|
376
|
-
end
|
377
|
-
|
378
|
-
end
|
379
|
-
|
380
|
-
|
381
|
-
describe 'removing rows' do
|
382
|
-
|
383
|
-
it 'can remove an existing row as a hash' do
|
384
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
|
385
|
-
example = clazz.new(source)
|
386
|
-
|
387
|
-
old_row = {'param1' => 'value3', 'param2' => 'value4'}
|
388
|
-
example.remove_row(old_row)
|
389
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
390
|
-
|
391
|
-
expect(row_cell_values).to eq([['value1', 'value2']])
|
392
|
-
end
|
393
|
-
|
394
|
-
it 'can remove an existing row as a hash, random key order' do
|
395
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
|
396
|
-
example = clazz.new(source)
|
397
|
-
|
398
|
-
old_row = {'param2' => 'value4', 'param1' => 'value3'}
|
399
|
-
example.remove_row(old_row)
|
400
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
401
|
-
|
402
|
-
expect(row_cell_values).to eq([['value1', 'value2']])
|
403
|
-
end
|
404
|
-
|
405
|
-
it 'can remove an existing row as an array' do
|
406
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
|
407
|
-
example = clazz.new(source)
|
408
|
-
|
409
|
-
old_row = ['value3', 'value4']
|
410
|
-
example.remove_row(old_row)
|
411
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
412
|
-
|
413
|
-
expect(row_cell_values).to eq([['value1', 'value2']])
|
414
|
-
end
|
415
|
-
|
416
|
-
it 'can only use a Hash or an Array to remove an existing row' do
|
417
|
-
expect { example.remove_row({}) }.to_not raise_error
|
418
|
-
expect { example.remove_row([]) }.to_not raise_error
|
419
|
-
expect { example.remove_row(:a_row) }.to raise_error(ArgumentError)
|
420
|
-
end
|
421
|
-
|
422
|
-
it 'trims whitespace from removed rows' do
|
423
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|value3|value4|\n|value5|value6|"
|
424
|
-
example = clazz.new(source)
|
425
|
-
|
426
|
-
# These will affect different rows
|
427
|
-
hash_row = {'param1' => 'value3 ', 'param2' => ' value4'}
|
428
|
-
array_row = ['value5', ' value6 ']
|
429
|
-
|
430
|
-
example.remove_row(hash_row)
|
431
|
-
example.remove_row(array_row)
|
432
|
-
row_cell_values = example.argument_rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
433
|
-
|
434
|
-
expect(row_cell_values).to eq([['value1', 'value2']])
|
435
|
-
end
|
436
|
-
|
437
|
-
it 'can gracefully remove a row from an example that has no rows' do
|
438
|
-
example = clazz.new
|
439
|
-
example.rows = []
|
440
|
-
|
441
|
-
expect { example.remove_row({}) }.to_not raise_error
|
442
|
-
expect { example.remove_row([]) }.to_not raise_error
|
443
|
-
end
|
444
|
-
|
445
|
-
it 'will not remove the parameter row' do
|
446
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|"
|
447
|
-
example = clazz.new(source)
|
448
|
-
|
449
|
-
hash_row = {'param1' => 'param1', 'param2' => 'param2'}
|
450
|
-
array_row = ['param1', 'param2']
|
451
|
-
|
452
|
-
example.remove_row(hash_row)
|
453
|
-
row_cell_values = example.rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
454
|
-
|
455
|
-
expect(row_cell_values).to eq([['param1', 'param2'], ['value1', 'value2']])
|
456
|
-
|
457
|
-
example.remove_row(array_row)
|
458
|
-
row_cell_values = example.rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
459
|
-
|
460
|
-
expect(row_cell_values).to eq([['param1', 'param2'], ['value1', 'value2']])
|
461
|
-
end
|
462
|
-
|
463
|
-
it 'will remove an argument row that is the same as the parameter row' do
|
464
|
-
source = "#{EXAMPLE_KEYWORD}:\n|param1|param2|\n|value1|value2|\n|param1|param2|"
|
465
|
-
example = clazz.new(source)
|
466
|
-
|
467
|
-
hash_row = {'param1' => 'param1', 'param2' => 'param2'}
|
468
|
-
array_row = ['param1', 'param2']
|
469
|
-
|
470
|
-
example.remove_row(hash_row)
|
471
|
-
row_cell_values = example.rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
472
|
-
|
473
|
-
expect(row_cell_values).to eq([['param1', 'param2'], ['value1', 'value2']])
|
474
|
-
|
475
|
-
example.remove_row(array_row)
|
476
|
-
row_cell_values = example.rows.collect { |row| row.cells.collect { |cell| cell.value } }
|
477
|
-
|
478
|
-
expect(row_cell_values).to eq([['param1', 'param2'], ['value1', 'value2']])
|
479
|
-
end
|
480
|
-
|
481
|
-
end
|
482
|
-
|
483
|
-
|
484
|
-
describe 'getting ancestors' do
|
485
|
-
|
486
|
-
before(:each) do
|
487
|
-
CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'example_test_file', :directory => test_directory)
|
488
|
-
end
|
489
|
-
|
490
|
-
|
491
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
492
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
493
|
-
|
494
|
-
#{OUTLINE_KEYWORD}: Test test
|
495
|
-
#{STEP_KEYWORD} a step
|
496
|
-
#{EXAMPLE_KEYWORD}: Test example
|
497
|
-
| a param |
|
498
|
-
| a value |"
|
499
|
-
}
|
500
|
-
|
501
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
502
|
-
let(:example_model) { directory_model.feature_files.first.feature.tests.first.examples.first }
|
503
|
-
|
504
|
-
|
505
|
-
it 'can get its directory' do
|
506
|
-
ancestor = example_model.get_ancestor(:directory)
|
507
|
-
|
508
|
-
expect(ancestor).to equal(directory_model)
|
509
|
-
end
|
510
|
-
|
511
|
-
it 'can get its feature file' do
|
512
|
-
ancestor = example_model.get_ancestor(:feature_file)
|
513
|
-
|
514
|
-
expect(ancestor).to equal(directory_model.feature_files.first)
|
515
|
-
end
|
516
|
-
|
517
|
-
it 'can get its feature' do
|
518
|
-
ancestor = example_model.get_ancestor(:feature)
|
519
|
-
|
520
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature)
|
521
|
-
end
|
522
|
-
|
523
|
-
context 'an example that is part of an outline' do
|
524
|
-
|
525
|
-
let(:test_directory) { CukeModeler::FileHelper.create_directory }
|
526
|
-
let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
|
527
|
-
|
528
|
-
#{OUTLINE_KEYWORD}: Test outline
|
529
|
-
#{STEP_KEYWORD} a step
|
530
|
-
#{EXAMPLE_KEYWORD}:
|
531
|
-
| param |
|
532
|
-
| value |"
|
533
|
-
}
|
534
|
-
|
535
|
-
let(:directory_model) { CukeModeler::Directory.new(test_directory) }
|
536
|
-
let(:example_model) { directory_model.feature_files.first.feature.tests.first.examples.first }
|
537
|
-
|
538
|
-
|
539
|
-
it 'can get its outline' do
|
540
|
-
ancestor = example_model.get_ancestor(:outline)
|
541
|
-
|
542
|
-
expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
|
543
|
-
end
|
544
|
-
|
545
|
-
end
|
546
|
-
|
547
|
-
it 'returns nil if it does not have the requested type of ancestor' do
|
548
|
-
ancestor = example_model.get_ancestor(:example)
|
549
|
-
|
550
|
-
expect(ancestor).to be_nil
|
551
|
-
end
|
552
|
-
|
553
|
-
end
|
554
|
-
|
555
|
-
|
556
|
-
describe 'example output' do
|
557
|
-
|
558
|
-
it 'can be remade from its own output' do
|
559
|
-
source = "@tag1 @tag2 @tag3
|
560
|
-
#{EXAMPLE_KEYWORD}: with everything it could have
|
561
|
-
|
562
|
-
Some description.
|
563
|
-
Some more description.
|
564
|
-
|
565
|
-
| param1 | param2 |
|
566
|
-
| value1 | value2 |
|
567
|
-
| value3 | value4 |"
|
568
|
-
example = clazz.new(source)
|
569
|
-
|
570
|
-
example_output = example.to_s
|
571
|
-
remade_example_output = clazz.new(example_output).to_s
|
572
|
-
|
573
|
-
expect(remade_example_output).to eq(example_output)
|
574
|
-
end
|
575
|
-
|
576
|
-
|
577
|
-
# This behavior should already be taken care of by the cell object's output method, but
|
578
|
-
# the example object has to adjust that output in order to properly buffer column width
|
579
|
-
# and it is possible that during that process it messes up the cell's output.
|
580
|
-
|
581
|
-
it 'can correctly output a row that has special characters in it' do
|
582
|
-
source = ["#{EXAMPLE_KEYWORD}:",
|
583
|
-
' | param with \| |',
|
584
|
-
' | a value with \| and \\\\ |',
|
585
|
-
' | a value with \\\\ |']
|
586
|
-
source = source.join("\n")
|
587
|
-
example = clazz.new(source)
|
588
|
-
|
589
|
-
example_output = example.to_s.split("\n", -1)
|
590
|
-
|
591
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:",
|
592
|
-
' | param with \| |',
|
593
|
-
' | a value with \| and \\\\ |',
|
594
|
-
' | a value with \\\\ |'])
|
595
|
-
end
|
596
|
-
|
597
|
-
|
598
|
-
context 'from source text' do
|
599
|
-
|
600
|
-
# gherkin 2.x/3.x does not accept incomplete examples
|
601
|
-
it 'can output an empty example', :unless => gherkin?(2, 3) do
|
602
|
-
source = ["#{EXAMPLE_KEYWORD}:"]
|
603
|
-
source = source.join("\n")
|
604
|
-
example = clazz.new(source)
|
605
|
-
|
606
|
-
example_output = example.to_s.split("\n", -1)
|
607
|
-
|
608
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:"])
|
609
|
-
end
|
610
|
-
|
611
|
-
# gherkin 2.x/3.x does not accept incomplete examples
|
612
|
-
it 'can output an example that has a name', :unless => gherkin?(2, 3) do
|
613
|
-
source = ["#{EXAMPLE_KEYWORD}: test example"]
|
614
|
-
source = source.join("\n")
|
615
|
-
example = clazz.new(source)
|
616
|
-
|
617
|
-
example_output = example.to_s.split("\n", -1)
|
618
|
-
|
619
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}: test example"])
|
620
|
-
end
|
621
|
-
|
622
|
-
# gherkin 2.x/3.x does not accept incomplete examples
|
623
|
-
it 'can output an example that has a description', :unless => gherkin?(2, 3) do
|
624
|
-
source = ["#{EXAMPLE_KEYWORD}:",
|
625
|
-
'Some description.',
|
626
|
-
'Some more description.']
|
627
|
-
source = source.join("\n")
|
628
|
-
example = clazz.new(source)
|
629
|
-
|
630
|
-
example_output = example.to_s.split("\n", -1)
|
631
|
-
|
632
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:",
|
633
|
-
'',
|
634
|
-
'Some description.',
|
635
|
-
'Some more description.'])
|
636
|
-
end
|
637
|
-
|
638
|
-
|
639
|
-
# gherkin 3.x does not accept incomplete examples
|
640
|
-
it 'can output an example that has a single row', :unless => gherkin?(3) do
|
641
|
-
source = ["#{EXAMPLE_KEYWORD}:",
|
642
|
-
'|param1|param2|']
|
643
|
-
source = source.join("\n")
|
644
|
-
example = clazz.new(source)
|
645
|
-
|
646
|
-
example_output = example.to_s.split("\n", -1)
|
647
|
-
|
648
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:",
|
649
|
-
' | param1 | param2 |'])
|
650
|
-
end
|
651
|
-
|
652
|
-
it 'can output an example that has multiple rows' do
|
653
|
-
source = ["#{EXAMPLE_KEYWORD}:",
|
654
|
-
'|param1|param2|',
|
655
|
-
'|value1|value2|',
|
656
|
-
'|value3|value4|']
|
657
|
-
source = source.join("\n")
|
658
|
-
example = clazz.new(source)
|
659
|
-
|
660
|
-
example_output = example.to_s.split("\n", -1)
|
661
|
-
|
662
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:",
|
663
|
-
' | param1 | param2 |',
|
664
|
-
' | value1 | value2 |',
|
665
|
-
' | value3 | value4 |'])
|
666
|
-
end
|
667
|
-
|
668
|
-
it 'can output an example that has tags' do
|
669
|
-
source = ['@tag1',
|
670
|
-
'@tag2 @tag3',
|
671
|
-
"#{EXAMPLE_KEYWORD}:",
|
672
|
-
'|param1|param2|',
|
673
|
-
'|value1|value2|',
|
674
|
-
'|value3|value4|']
|
675
|
-
source = source.join("\n")
|
676
|
-
example = clazz.new(source)
|
677
|
-
|
678
|
-
example_output = example.to_s.split("\n", -1)
|
679
|
-
|
680
|
-
expect(example_output).to eq(['@tag1 @tag2 @tag3',
|
681
|
-
"#{EXAMPLE_KEYWORD}:",
|
682
|
-
' | param1 | param2 |',
|
683
|
-
' | value1 | value2 |',
|
684
|
-
' | value3 | value4 |'])
|
685
|
-
end
|
686
|
-
|
687
|
-
it 'can output an example that has everything' do
|
688
|
-
source = ['@tag1',
|
689
|
-
'@tag2 @tag3',
|
690
|
-
"#{EXAMPLE_KEYWORD}: with everything it could have",
|
691
|
-
'Some description.',
|
692
|
-
'Some more description.',
|
693
|
-
'|param1|param2|',
|
694
|
-
'|value1|value2|',
|
695
|
-
'|value3|value4|']
|
696
|
-
source = source.join("\n")
|
697
|
-
example = clazz.new(source)
|
698
|
-
|
699
|
-
example_output = example.to_s.split("\n", -1)
|
700
|
-
|
701
|
-
expect(example_output).to eq(['@tag1 @tag2 @tag3',
|
702
|
-
"#{EXAMPLE_KEYWORD}: with everything it could have",
|
703
|
-
'',
|
704
|
-
'Some description.',
|
705
|
-
'Some more description.',
|
706
|
-
'',
|
707
|
-
' | param1 | param2 |',
|
708
|
-
' | value1 | value2 |',
|
709
|
-
' | value3 | value4 |'])
|
710
|
-
end
|
711
|
-
|
712
|
-
it 'buffers row cells based on the longest value in a column' do
|
713
|
-
source = "#{EXAMPLE_KEYWORD}:
|
714
|
-
|parameter 1| x|
|
715
|
-
|y|value 1|
|
716
|
-
|a|b|"
|
717
|
-
example = clazz.new(source)
|
718
|
-
|
719
|
-
example_output = example.to_s.split("\n", -1)
|
720
|
-
|
721
|
-
expect(example_output).to eq(["#{EXAMPLE_KEYWORD}:",
|
722
|
-
' | parameter 1 | x |',
|
723
|
-
' | y | value 1 |',
|
724
|
-
' | a | b |'])
|
725
|
-
end
|
726
|
-
|
727
|
-
end
|
728
|
-
|
729
|
-
|
730
|
-
context 'from abstract instantiation' do
|
731
|
-
|
732
|
-
let(:example) { clazz.new }
|
733
|
-
|
734
|
-
|
735
|
-
it 'can output an example that has only tags' do
|
736
|
-
example.tags = [CukeModeler::Tag.new]
|
737
|
-
|
738
|
-
expect { example.to_s }.to_not raise_error
|
739
|
-
end
|
740
|
-
|
741
|
-
it 'can output an example that has only rows' do
|
742
|
-
example.rows = [CukeModeler::Row.new]
|
743
|
-
|
744
|
-
expect { example.to_s }.to_not raise_error
|
745
|
-
end
|
746
|
-
|
747
|
-
end
|
748
|
-
|
749
|
-
end
|
750
|
-
|
751
|
-
end
|
752
|
-
|
753
|
-
end
|