cuke_modeler 1.4.0 → 3.0.0

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