cuke_modeler 2.0.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -2
  3. data/README.md +14 -16
  4. data/cuke_modeler.gemspec +12 -9
  5. data/lib/cuke_modeler.rb +1 -0
  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_14_adapter.rb +12 -0
  11. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +12 -0
  12. data/lib/cuke_modeler/adapters/{gherkin_6_adapter.rb → gherkin_9_adapter.rb} +104 -69
  13. data/lib/cuke_modeler/containing.rb +15 -5
  14. data/lib/cuke_modeler/models/background.rb +1 -1
  15. data/lib/cuke_modeler/models/cell.rb +1 -1
  16. data/lib/cuke_modeler/models/comment.rb +1 -1
  17. data/lib/cuke_modeler/models/directory.rb +2 -2
  18. data/lib/cuke_modeler/models/doc_string.rb +1 -1
  19. data/lib/cuke_modeler/models/example.rb +1 -1
  20. data/lib/cuke_modeler/models/feature.rb +16 -5
  21. data/lib/cuke_modeler/models/feature_file.rb +2 -2
  22. data/lib/cuke_modeler/models/outline.rb +1 -1
  23. data/lib/cuke_modeler/models/row.rb +1 -1
  24. data/lib/cuke_modeler/models/rule.rb +99 -0
  25. data/lib/cuke_modeler/models/scenario.rb +1 -1
  26. data/lib/cuke_modeler/models/step.rb +1 -1
  27. data/lib/cuke_modeler/models/table.rb +1 -1
  28. data/lib/cuke_modeler/models/tag.rb +1 -1
  29. data/lib/cuke_modeler/parsing.rb +89 -110
  30. data/lib/cuke_modeler/version.rb +1 -1
  31. data/testing/cucumber/features/modeling/feature_modeling.feature +28 -7
  32. data/testing/cucumber/features/modeling/feature_output.feature +45 -23
  33. data/testing/cucumber/features/modeling/rule_modeling.feature +108 -0
  34. data/testing/cucumber/features/modeling/rule_output.feature +111 -0
  35. metadata +39 -140
  36. data/.gitignore +0 -18
  37. data/.simplecov +0 -7
  38. data/.travis.yml +0 -63
  39. data/Gemfile +0 -37
  40. data/Rakefile +0 -73
  41. data/appveyor.yml +0 -61
  42. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +0 -274
  43. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +0 -297
  44. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +0 -309
  45. data/testing/cucumber/step_definitions/action_steps.rb +0 -13
  46. data/testing/cucumber/step_definitions/background_steps.rb +0 -1
  47. data/testing/cucumber/step_definitions/directory_steps.rb +0 -6
  48. data/testing/cucumber/step_definitions/doc_string_steps.rb +0 -1
  49. data/testing/cucumber/step_definitions/feature_file_steps.rb +0 -16
  50. data/testing/cucumber/step_definitions/feature_steps.rb +0 -7
  51. data/testing/cucumber/step_definitions/modeling_steps.rb +0 -49
  52. data/testing/cucumber/step_definitions/setup_steps.rb +0 -32
  53. data/testing/cucumber/step_definitions/step_steps.rb +0 -3
  54. data/testing/cucumber/step_definitions/table_steps.rb +0 -1
  55. data/testing/cucumber/step_definitions/tag_steps.rb +0 -3
  56. data/testing/cucumber/step_definitions/verification_steps.rb +0 -181
  57. data/testing/cucumber/support/env.rb +0 -30
  58. data/testing/dialect_helper.rb +0 -48
  59. data/testing/file_helper.rb +0 -47
  60. data/testing/gemfiles/gherkin2.gemfile +0 -33
  61. data/testing/gemfiles/gherkin3.gemfile +0 -26
  62. data/testing/gemfiles/gherkin4.gemfile +0 -27
  63. data/testing/gemfiles/gherkin5.gemfile +0 -27
  64. data/testing/gemfiles/gherkin6.gemfile +0 -10
  65. data/testing/rspec/spec/integration/adapters/gherkin_2_adapter_spec.rb +0 -166
  66. data/testing/rspec/spec/integration/adapters/gherkin_3_adapter_spec.rb +0 -166
  67. data/testing/rspec/spec/integration/adapters/gherkin_4_adapter_spec.rb +0 -165
  68. data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +0 -166
  69. data/testing/rspec/spec/integration/models/background_integration_spec.rb +0 -442
  70. data/testing/rspec/spec/integration/models/cell_integration_spec.rb +0 -335
  71. data/testing/rspec/spec/integration/models/comment_integration_spec.rb +0 -177
  72. data/testing/rspec/spec/integration/models/directory_integration_spec.rb +0 -218
  73. data/testing/rspec/spec/integration/models/doc_string_integration_spec.rb +0 -402
  74. data/testing/rspec/spec/integration/models/example_integration_spec.rb +0 -741
  75. data/testing/rspec/spec/integration/models/feature_file_integration_spec.rb +0 -272
  76. data/testing/rspec/spec/integration/models/feature_integration_spec.rb +0 -650
  77. data/testing/rspec/spec/integration/models/model_integration_spec.rb +0 -15
  78. data/testing/rspec/spec/integration/models/outline_integration_spec.rb +0 -624
  79. data/testing/rspec/spec/integration/models/row_integration_spec.rb +0 -291
  80. data/testing/rspec/spec/integration/models/scenario_integration_spec.rb +0 -479
  81. data/testing/rspec/spec/integration/models/step_integration_spec.rb +0 -569
  82. data/testing/rspec/spec/integration/models/table_integration_spec.rb +0 -337
  83. data/testing/rspec/spec/integration/models/tag_integration_spec.rb +0 -259
  84. data/testing/rspec/spec/integration/nested_integration_spec.rb +0 -91
  85. data/testing/rspec/spec/integration/parsing_integration_spec.rb +0 -122
  86. data/testing/rspec/spec/integration/shared/models_integration_specs.rb +0 -18
  87. data/testing/rspec/spec/spec_helper.rb +0 -136
  88. data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +0 -25
  89. data/testing/rspec/spec/unit/described_unit_spec.rb +0 -23
  90. data/testing/rspec/spec/unit/models/background_unit_spec.rb +0 -83
  91. data/testing/rspec/spec/unit/models/cell_unit_spec.rb +0 -68
  92. data/testing/rspec/spec/unit/models/comment_unit_spec.rb +0 -68
  93. data/testing/rspec/spec/unit/models/directory_unit_spec.rb +0 -127
  94. data/testing/rspec/spec/unit/models/doc_string_unit_spec.rb +0 -100
  95. data/testing/rspec/spec/unit/models/example_unit_spec.rb +0 -133
  96. data/testing/rspec/spec/unit/models/feature_file_unit_spec.rb +0 -125
  97. data/testing/rspec/spec/unit/models/feature_unit_spec.rb +0 -157
  98. data/testing/rspec/spec/unit/models/model_unit_spec.rb +0 -15
  99. data/testing/rspec/spec/unit/models/outline_unit_spec.rb +0 -117
  100. data/testing/rspec/spec/unit/models/row_unit_spec.rb +0 -68
  101. data/testing/rspec/spec/unit/models/scenario_unit_spec.rb +0 -86
  102. data/testing/rspec/spec/unit/models/step_unit_spec.rb +0 -109
  103. data/testing/rspec/spec/unit/models/table_unit_spec.rb +0 -77
  104. data/testing/rspec/spec/unit/models/tag_unit_spec.rb +0 -68
  105. data/testing/rspec/spec/unit/named_unit_spec.rb +0 -23
  106. data/testing/rspec/spec/unit/nested_unit_spec.rb +0 -43
  107. data/testing/rspec/spec/unit/parsed_unit_spec.rb +0 -27
  108. data/testing/rspec/spec/unit/parsing_unit_spec.rb +0 -54
  109. data/testing/rspec/spec/unit/shared/bare_bones_models_unit_specs.rb +0 -14
  110. data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +0 -127
  111. data/testing/rspec/spec/unit/shared/described_models_unit_specs.rb +0 -38
  112. data/testing/rspec/spec/unit/shared/keyworded_models_unit_specs.rb +0 -58
  113. data/testing/rspec/spec/unit/shared/models_unit_specs.rb +0 -15
  114. data/testing/rspec/spec/unit/shared/named_models_unit_specs.rb +0 -39
  115. data/testing/rspec/spec/unit/shared/nested_models_unit_specs.rb +0 -51
  116. data/testing/rspec/spec/unit/shared/parsed_models_unit_specs.rb +0 -39
  117. data/testing/rspec/spec/unit/shared/prepopulated_models_unit_specs.rb +0 -18
  118. data/testing/rspec/spec/unit/shared/sourced_models_unit_specs.rb +0 -39
  119. data/testing/rspec/spec/unit/shared/stepped_models_unit_specs.rb +0 -46
  120. data/testing/rspec/spec/unit/shared/stringifiable_models_unit_specs.rb +0 -18
  121. data/testing/rspec/spec/unit/shared/tagged_models_unit_specs.rb +0 -72
  122. data/testing/rspec/spec/unit/sourceable_unit_spec.rb +0 -27
  123. data/testing/rspec/spec/unit/stepped_unit_spec.rb +0 -23
  124. data/testing/rspec/spec/unit/taggable_unit_spec.rb +0 -69
  125. data/testing/test_languages.json +0 -45
  126. data/todo.txt +0 -25
@@ -1,291 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'Row, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Row }
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 = '| a | row |'
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 = '| a | row |'
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.cells.last.value).to eq('row')
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 = " |bad |row| text| \n @foo "
43
-
44
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_row\.feature'/)
45
- end
46
-
47
- it 'stores the original data generated by the parsing adapter', :gherkin6 => true do
48
- example_row = clazz.new("| a | row |")
49
- data = example_row.parsing_data
50
-
51
- expect(data.keys).to match_array([:location, :cells])
52
- expect(data[:location][:line]).to eq(5)
53
- end
54
-
55
- it 'stores the original data generated by the parsing adapter', :gherkin4_5 => true do
56
- example_row = clazz.new("| a | row |")
57
- data = example_row.parsing_data
58
-
59
- expect(data.keys).to match_array([:type, :location, :cells])
60
- expect(data[:type]).to eq(:TableRow)
61
- end
62
-
63
- it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
64
- example_row = clazz.new("| a | row |")
65
- data = example_row.parsing_data
66
-
67
- expect(data.keys).to match_array([:type, :location, :cells])
68
- expect(data[:type]).to eq('TableRow')
69
- end
70
-
71
- it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
72
- example_row = clazz.new("| a | row |")
73
- data = example_row.parsing_data
74
-
75
- expect(data.keys).to match_array(['cells', 'line'])
76
- expect(data['line']).to eq(5)
77
- end
78
-
79
- it 'properly sets its child models' do
80
- source = '| cell 1 | cell 2 |'
81
-
82
- row = clazz.new(source)
83
- cell_1 = row.cells.first
84
- cell_2 = row.cells.last
85
-
86
- expect(cell_1.parent_model).to equal(row)
87
- expect(cell_2.parent_model).to equal(row)
88
- end
89
-
90
-
91
- describe 'getting ancestors' do
92
-
93
- before(:each) do
94
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'row_test_file', :directory => test_directory)
95
- end
96
-
97
-
98
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
99
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
100
-
101
- #{SCENARIO_KEYWORD}: Test test
102
- #{STEP_KEYWORD} a step:
103
- | a | table |"
104
- }
105
-
106
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
107
- let(:row_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first }
108
-
109
-
110
- it 'can get its directory' do
111
- ancestor = row_model.get_ancestor(:directory)
112
-
113
- expect(ancestor).to equal(directory_model)
114
- end
115
-
116
- it 'can get its feature file' do
117
- ancestor = row_model.get_ancestor(:feature_file)
118
-
119
- expect(ancestor).to equal(directory_model.feature_files.first)
120
- end
121
-
122
- it 'can get its feature' do
123
- ancestor = row_model.get_ancestor(:feature)
124
-
125
- expect(ancestor).to equal(directory_model.feature_files.first.feature)
126
- end
127
-
128
- it 'can get its step' do
129
- ancestor = row_model.get_ancestor(:step)
130
-
131
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first)
132
- end
133
-
134
- it 'can get its table' do
135
- ancestor = row_model.get_ancestor(:table)
136
-
137
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first.block)
138
- end
139
-
140
- context 'a row that is part of a scenario' do
141
-
142
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
143
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
144
-
145
- #{SCENARIO_KEYWORD}: Test test
146
- #{STEP_KEYWORD} a step:
147
- | a | table |"
148
- }
149
-
150
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
151
- let(:row_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block.rows.first }
152
-
153
-
154
- it 'can get its scenario' do
155
- ancestor = row_model.get_ancestor(:scenario)
156
-
157
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
158
- end
159
-
160
- end
161
-
162
-
163
- context 'a row that is part of a background' do
164
-
165
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
166
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
167
-
168
- #{BACKGROUND_KEYWORD}: Test background
169
- #{STEP_KEYWORD} a step:
170
- | a | table |"
171
- }
172
-
173
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
174
- let(:row_model) { directory_model.feature_files.first.feature.background.steps.first.block.rows.first }
175
-
176
-
177
- it 'can get its background' do
178
- ancestor = row_model.get_ancestor(:background)
179
-
180
- expect(ancestor).to equal(directory_model.feature_files.first.feature.background)
181
- end
182
-
183
- end
184
-
185
- context 'a row that is part of an outline' do
186
-
187
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
188
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
189
-
190
- #{OUTLINE_KEYWORD}: Test outline
191
- #{STEP_KEYWORD} a step
192
- #{EXAMPLE_KEYWORD}:
193
- | param |
194
- | value |"
195
- }
196
-
197
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
198
- let(:row_model) { directory_model.feature_files.first.feature.tests.first.examples.first.rows.first }
199
-
200
-
201
- it 'can get its outline' do
202
- ancestor = row_model.get_ancestor(:outline)
203
-
204
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
205
- end
206
-
207
- it 'can get its example' do
208
- ancestor = row_model.get_ancestor(:example)
209
-
210
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.examples.first)
211
- end
212
-
213
- end
214
-
215
- it 'returns nil if it does not have the requested type of ancestor' do
216
- ancestor = row_model.get_ancestor(:outline)
217
-
218
- expect(ancestor).to be_nil
219
- end
220
-
221
- end
222
-
223
-
224
- describe 'model population' do
225
-
226
- context 'from source text' do
227
-
228
- let(:source_text) { '| cell 1 | cell 2 |' }
229
- let(:row) { clazz.new(source_text) }
230
-
231
-
232
- it "models the row's cells" do
233
- cell_values = row.cells.collect { |cell| cell.value }
234
-
235
- expect(cell_values).to match_array(['cell 1', 'cell 2'])
236
- end
237
-
238
- it "models the row's source line" do
239
- source_text = "#{FEATURE_KEYWORD}: Test feature
240
-
241
- #{OUTLINE_KEYWORD}: Test outline
242
- #{STEP_KEYWORD} a step
243
- #{EXAMPLE_KEYWORD}:
244
- | param |
245
- | value |"
246
- row = CukeModeler::Feature.new(source_text).tests.first.examples.first.rows.first
247
-
248
- expect(row.source_line).to eq(6)
249
- end
250
-
251
- end
252
-
253
- end
254
-
255
-
256
- describe 'row output' do
257
-
258
- it 'can be remade from its own output' do
259
- source = "| value1 | value2 |"
260
- row = clazz.new(source)
261
-
262
- row_output = row.to_s
263
- remade_row_output = clazz.new(row_output).to_s
264
-
265
- expect(remade_row_output).to eq(row_output)
266
- end
267
-
268
-
269
- context 'from source text' do
270
-
271
- it 'can output a row' do
272
- source = '| some value |'
273
- row = clazz.new(source)
274
-
275
- expect(row.to_s).to eq('| some value |')
276
- end
277
-
278
- it 'can output a row with multiple cells' do
279
- source = '| some value | some other value |'
280
- row = clazz.new(source)
281
-
282
- expect(row.to_s).to eq('| some value | some other value |')
283
- end
284
-
285
- end
286
-
287
- end
288
-
289
- end
290
-
291
- end
@@ -1,479 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'Scenario, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Scenario }
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 = "#{SCENARIO_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 = 'Awww, look mate: Scenario 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('Scenario 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
- it 'provides a descriptive filename when being parsed from stand alone text' do
41
- source = "bad scenario text \n #{SCENARIO_KEYWORD}:\n And a step\n @foo "
42
-
43
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_scenario\.feature'/)
44
- end
45
-
46
- it 'stores the original data generated by the parsing adapter', :gherkin6 => true do
47
- scenario = clazz.new("@tag\n#{SCENARIO_KEYWORD}: test scenario\ndescription\n#{STEP_KEYWORD} a step")
48
- data = scenario.parsing_data
49
-
50
- expect(data.keys).to match_array([:background, :rule, :scenario])
51
- expect(data[:scenario][:name]).to eq('test scenario')
52
- end
53
-
54
- it 'stores the original data generated by the parsing adapter', :gherkin4_5 => true do
55
- scenario = clazz.new("@tag\n#{SCENARIO_KEYWORD}: test scenario\ndescription\n#{STEP_KEYWORD} a step")
56
- data = scenario.parsing_data
57
-
58
- expect(data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :description])
59
- expect(data[:type]).to eq(:Scenario)
60
- end
61
-
62
- it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
63
- scenario = clazz.new("@tag\n#{SCENARIO_KEYWORD}: test scenario\ndescription\n#{STEP_KEYWORD} a step")
64
- data = scenario.parsing_data
65
-
66
- expect(data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :description])
67
- expect(data[:type]).to eq(:Scenario)
68
- end
69
-
70
- it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
71
- scenario = clazz.new("@tag\n#{SCENARIO_KEYWORD}: test scenario\ndescription\n#{STEP_KEYWORD} a step")
72
- data = scenario.parsing_data
73
-
74
- expect(data.keys).to match_array(['keyword', 'name', 'line', 'description', 'id', 'type', 'steps', 'tags'])
75
- expect(data['keyword']).to eq('Scenario')
76
- end
77
-
78
- it 'properly sets its child models' do
79
- source = "@a_tag
80
- #{SCENARIO_KEYWORD}: Test scenario
81
- #{STEP_KEYWORD} a step"
82
-
83
- scenario = clazz.new(source)
84
- step = scenario.steps.first
85
- tag = scenario.tags.first
86
-
87
- expect(step.parent_model).to equal(scenario)
88
- expect(tag.parent_model).to equal(scenario)
89
- end
90
-
91
- it 'trims whitespace from its source description' do
92
- source = ["#{SCENARIO_KEYWORD}:",
93
- ' ',
94
- ' description line 1',
95
- '',
96
- ' description line 2',
97
- ' description line 3 ',
98
- '',
99
- '',
100
- '',
101
- " #{STEP_KEYWORD} a step"]
102
- source = source.join("\n")
103
-
104
- scenario = clazz.new(source)
105
- description = scenario.description.split("\n", -1)
106
-
107
- expect(description).to eq([' description line 1',
108
- '',
109
- 'description line 2',
110
- ' description line 3'])
111
- end
112
-
113
-
114
- describe 'getting ancestors' do
115
-
116
- before(:each) do
117
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'scenario_test_file', :directory => test_directory)
118
- end
119
-
120
-
121
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
122
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
123
-
124
- #{SCENARIO_KEYWORD}: Test test
125
- #{STEP_KEYWORD} a step"
126
- }
127
-
128
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
129
- let(:scenario_model) { directory_model.feature_files.first.feature.tests.first }
130
-
131
-
132
- it 'can get its directory' do
133
- ancestor = scenario_model.get_ancestor(:directory)
134
-
135
- expect(ancestor).to equal(directory_model)
136
- end
137
-
138
- it 'can get its feature file' do
139
- ancestor = scenario_model.get_ancestor(:feature_file)
140
-
141
- expect(ancestor).to equal(directory_model.feature_files.first)
142
- end
143
-
144
- it 'can get its feature' do
145
- ancestor = scenario_model.get_ancestor(:feature)
146
-
147
- expect(ancestor).to equal(directory_model.feature_files.first.feature)
148
- end
149
-
150
- it 'returns nil if it does not have the requested type of ancestor' do
151
- ancestor = scenario_model.get_ancestor(:test)
152
-
153
- expect(ancestor).to be_nil
154
- end
155
-
156
- end
157
-
158
-
159
- describe 'model population' do
160
-
161
- context 'from source text' do
162
-
163
- let(:source_text) { "#{SCENARIO_KEYWORD}:" }
164
- let(:scenario) { clazz.new(source_text) }
165
-
166
-
167
- it "models the scenario's keyword" do
168
- expect(scenario.keyword).to eq("#{SCENARIO_KEYWORD}")
169
- end
170
-
171
- it "models the scenario's source line" do
172
- source_text = "#{FEATURE_KEYWORD}:
173
-
174
- #{SCENARIO_KEYWORD}: foo
175
- #{STEP_KEYWORD} step"
176
- scenario = CukeModeler::Feature.new(source_text).tests.first
177
-
178
- expect(scenario.source_line).to eq(3)
179
- end
180
-
181
-
182
- context 'a filled scenario' do
183
-
184
- let(:source_text) { "@tag1 @tag2 @tag3
185
- #{SCENARIO_KEYWORD}: Scenario name
186
-
187
- Scenario description.
188
-
189
- Some more.
190
- Even more.
191
-
192
- #{STEP_KEYWORD} a step
193
- #{STEP_KEYWORD} another step" }
194
- let(:scenario) { clazz.new(source_text) }
195
-
196
-
197
- it "models the scenario's name" do
198
- expect(scenario.name).to eq('Scenario name')
199
- end
200
-
201
- it "models the scenario's description" do
202
- description = scenario.description.split("\n", -1)
203
-
204
- expect(description).to eq([' Scenario description.',
205
- '',
206
- 'Some more.',
207
- ' Even more.'])
208
- end
209
-
210
- it "models the scenario's steps" do
211
- step_names = scenario.steps.collect { |step| step.text }
212
-
213
- expect(step_names).to eq(['a step', 'another step'])
214
- end
215
-
216
- it "models the scenario's tags" do
217
- tag_names = scenario.tags.collect { |tag| tag.name }
218
-
219
- expect(tag_names).to eq(['@tag1', '@tag2', '@tag3'])
220
- end
221
-
222
- end
223
-
224
- context 'an empty scenario' do
225
-
226
- let(:source_text) { "#{SCENARIO_KEYWORD}:" }
227
- let(:scenario) { clazz.new(source_text) }
228
-
229
-
230
- it "models the scenario's name" do
231
- expect(scenario.name).to eq('')
232
- end
233
-
234
- it "models the scenario's description" do
235
- expect(scenario.description).to eq('')
236
- end
237
-
238
- it "models the scenario's steps" do
239
- expect(scenario.steps).to eq([])
240
- end
241
-
242
- it "models the scenario's tags" do
243
- expect(scenario.tags).to eq([])
244
- end
245
-
246
- end
247
-
248
- end
249
-
250
- end
251
-
252
-
253
- describe 'comparison' do
254
-
255
- it 'is equal to a background with the same steps' do
256
- source = "#{SCENARIO_KEYWORD}:
257
- #{STEP_KEYWORD} step 1
258
- #{STEP_KEYWORD} step 2"
259
- scenario = clazz.new(source)
260
-
261
- source = "#{BACKGROUND_KEYWORD}:
262
- #{STEP_KEYWORD} step 1
263
- #{STEP_KEYWORD} step 2"
264
- background_1 = CukeModeler::Background.new(source)
265
-
266
- source = "#{BACKGROUND_KEYWORD}:
267
- #{STEP_KEYWORD} step 2
268
- #{STEP_KEYWORD} step 1"
269
- background_2 = CukeModeler::Background.new(source)
270
-
271
-
272
- expect(scenario).to eq(background_1)
273
- expect(scenario).to_not eq(background_2)
274
- end
275
-
276
- it 'is equal to a scenario with the same steps' do
277
- source = "#{SCENARIO_KEYWORD}:
278
- #{STEP_KEYWORD} step 1
279
- #{STEP_KEYWORD} step 2"
280
- scenario_1 = clazz.new(source)
281
-
282
- source = "#{SCENARIO_KEYWORD}:
283
- #{STEP_KEYWORD} step 1
284
- #{STEP_KEYWORD} step 2"
285
- scenario_2 = clazz.new(source)
286
-
287
- source = "#{SCENARIO_KEYWORD}:
288
- #{STEP_KEYWORD} step 2
289
- #{STEP_KEYWORD} step 1"
290
- scenario_3 = clazz.new(source)
291
-
292
-
293
- expect(scenario_1).to eq(scenario_2)
294
- expect(scenario_1).to_not eq(scenario_3)
295
- end
296
-
297
- it 'is equal to an outline with the same steps' do
298
- source = "#{SCENARIO_KEYWORD}:
299
- #{STEP_KEYWORD} step 1
300
- #{STEP_KEYWORD} step 2"
301
- scenario = clazz.new(source)
302
-
303
- source = "#{OUTLINE_KEYWORD}:
304
- #{STEP_KEYWORD} step 1
305
- #{STEP_KEYWORD} step 2
306
- #{EXAMPLE_KEYWORD}:
307
- | param |
308
- | value |"
309
- outline_1 = CukeModeler::Outline.new(source)
310
-
311
- source = "#{OUTLINE_KEYWORD}:
312
- #{STEP_KEYWORD} step 2
313
- #{STEP_KEYWORD} step 1
314
- #{EXAMPLE_KEYWORD}:
315
- | param |
316
- | value |"
317
- outline_2 = CukeModeler::Outline.new(source)
318
-
319
-
320
- expect(scenario).to eq(outline_1)
321
- expect(scenario).to_not eq(outline_2)
322
- end
323
-
324
- end
325
-
326
-
327
- describe 'scenario output' do
328
-
329
- it 'can be remade from its own output' do
330
- source = "@tag1 @tag2 @tag3
331
- #{SCENARIO_KEYWORD}: A scenario with everything it could have
332
-
333
- Including a description
334
- and then some.
335
-
336
- #{STEP_KEYWORD} a step
337
- | value |
338
- #{STEP_KEYWORD} another step
339
- \"\"\"
340
- some string
341
- \"\"\""
342
- scenario = clazz.new(source)
343
-
344
- scenario_output = scenario.to_s
345
- remade_scenario_output = clazz.new(scenario_output).to_s
346
-
347
- expect(remade_scenario_output).to eq(scenario_output)
348
- end
349
-
350
-
351
- context 'from source text' do
352
-
353
- it 'can output an empty scenario' do
354
- source = ["#{SCENARIO_KEYWORD}:"]
355
- source = source.join("\n")
356
- scenario = clazz.new(source)
357
-
358
- scenario_output = scenario.to_s.split("\n", -1)
359
-
360
- expect(scenario_output).to eq(["#{SCENARIO_KEYWORD}:"])
361
- end
362
-
363
- it 'can output a scenario that has a name' do
364
- source = ["#{SCENARIO_KEYWORD}: test scenario"]
365
- source = source.join("\n")
366
- scenario = clazz.new(source)
367
-
368
- scenario_output = scenario.to_s.split("\n", -1)
369
-
370
- expect(scenario_output).to eq(["#{SCENARIO_KEYWORD}: test scenario"])
371
- end
372
-
373
- it 'can output a scenario that has a description' do
374
- source = ["#{SCENARIO_KEYWORD}:",
375
- 'Some description.',
376
- 'Some more description.']
377
- source = source.join("\n")
378
- scenario = clazz.new(source)
379
-
380
- scenario_output = scenario.to_s.split("\n", -1)
381
-
382
- expect(scenario_output).to eq(["#{SCENARIO_KEYWORD}:",
383
- '',
384
- 'Some description.',
385
- 'Some more description.'])
386
- end
387
-
388
- it 'can output a scenario that has steps' do
389
- source = ["#{SCENARIO_KEYWORD}:",
390
- "#{STEP_KEYWORD} a step",
391
- '|value|',
392
- "#{STEP_KEYWORD} another step",
393
- '"""',
394
- 'some string',
395
- '"""']
396
- source = source.join("\n")
397
- scenario = clazz.new(source)
398
-
399
- scenario_output = scenario.to_s.split("\n", -1)
400
-
401
- expect(scenario_output).to eq(["#{SCENARIO_KEYWORD}:",
402
- " #{STEP_KEYWORD} a step",
403
- ' | value |',
404
- " #{STEP_KEYWORD} another step",
405
- ' """',
406
- ' some string',
407
- ' """'])
408
- end
409
-
410
- it 'can output a scenario that has tags' do
411
- source = ['@tag1 @tag2',
412
- '@tag3',
413
- "#{SCENARIO_KEYWORD}:"]
414
- source = source.join("\n")
415
- scenario = clazz.new(source)
416
-
417
- scenario_output = scenario.to_s.split("\n", -1)
418
-
419
- expect(scenario_output).to eq(['@tag1 @tag2 @tag3',
420
- "#{SCENARIO_KEYWORD}:"])
421
- end
422
-
423
- it 'can output a scenario that has everything' do
424
- source = ['@tag1 @tag2 @tag3',
425
- "#{SCENARIO_KEYWORD}: A scenario with everything it could have",
426
- 'Including a description',
427
- 'and then some.',
428
- "#{STEP_KEYWORD} a step",
429
- '|value|',
430
- "#{STEP_KEYWORD} another step",
431
- '"""',
432
- 'some string',
433
- '"""']
434
- source = source.join("\n")
435
- scenario = clazz.new(source)
436
-
437
- scenario_output = scenario.to_s.split("\n", -1)
438
-
439
- expect(scenario_output).to eq(['@tag1 @tag2 @tag3',
440
- "#{SCENARIO_KEYWORD}: A scenario with everything it could have",
441
- '',
442
- 'Including a description',
443
- 'and then some.',
444
- '',
445
- " #{STEP_KEYWORD} a step",
446
- ' | value |',
447
- " #{STEP_KEYWORD} another step",
448
- ' """',
449
- ' some string',
450
- ' """'])
451
- end
452
-
453
- end
454
-
455
-
456
- context 'from abstract instantiation' do
457
-
458
- let(:scenario) { clazz.new }
459
-
460
-
461
- it 'can output a scenario that has only tags' do
462
- scenario.tags = [CukeModeler::Tag.new]
463
-
464
- expect { scenario.to_s }.to_not raise_error
465
- end
466
-
467
- it 'can output a scenario that has only steps' do
468
- scenario.steps = [CukeModeler::Step.new]
469
-
470
- expect { scenario.to_s }.to_not raise_error
471
- end
472
-
473
- end
474
-
475
- end
476
-
477
- end
478
-
479
- end