cuke_modeler 2.1.0 → 3.4.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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -1
  3. data/README.md +14 -16
  4. data/cuke_modeler.gemspec +33 -21
  5. data/lib/cuke_modeler.rb +2 -1
  6. data/lib/cuke_modeler/adapters/gherkin_10_adapter.rb +13 -0
  7. data/lib/cuke_modeler/adapters/gherkin_11_adapter.rb +13 -0
  8. data/lib/cuke_modeler/adapters/gherkin_12_adapter.rb +13 -0
  9. data/lib/cuke_modeler/adapters/gherkin_13_adapter.rb +13 -0
  10. data/lib/cuke_modeler/adapters/gherkin_14_adapter.rb +13 -0
  11. data/lib/cuke_modeler/adapters/gherkin_15_adapter.rb +13 -0
  12. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +356 -4
  13. data/lib/cuke_modeler/containing.rb +41 -89
  14. data/lib/cuke_modeler/described.rb +40 -1
  15. data/lib/cuke_modeler/models/background.rb +12 -12
  16. data/lib/cuke_modeler/models/cell.rb +14 -8
  17. data/lib/cuke_modeler/models/comment.rb +6 -6
  18. data/lib/cuke_modeler/models/directory.rb +14 -18
  19. data/lib/cuke_modeler/models/doc_string.rb +11 -8
  20. data/lib/cuke_modeler/models/example.rb +64 -46
  21. data/lib/cuke_modeler/models/feature.rb +38 -20
  22. data/lib/cuke_modeler/models/feature_file.rb +6 -8
  23. data/lib/cuke_modeler/models/model.rb +2 -1
  24. data/lib/cuke_modeler/models/outline.rb +20 -15
  25. data/lib/cuke_modeler/models/row.rb +11 -8
  26. data/lib/cuke_modeler/models/rule.rb +101 -0
  27. data/lib/cuke_modeler/models/scenario.rb +18 -13
  28. data/lib/cuke_modeler/models/step.rb +41 -19
  29. data/lib/cuke_modeler/models/table.rb +10 -7
  30. data/lib/cuke_modeler/models/tag.rb +10 -6
  31. data/lib/cuke_modeler/named.rb +5 -1
  32. data/lib/cuke_modeler/nested.rb +22 -18
  33. data/lib/cuke_modeler/parsed.rb +8 -0
  34. data/lib/cuke_modeler/parsing.rb +55 -74
  35. data/lib/cuke_modeler/sourceable.rb +8 -0
  36. data/lib/cuke_modeler/stepped.rb +8 -0
  37. data/lib/cuke_modeler/taggable.rb +9 -1
  38. data/lib/cuke_modeler/version.rb +1 -1
  39. data/testing/cucumber/features/modeling/feature_modeling.feature +28 -7
  40. data/testing/cucumber/features/modeling/feature_output.feature +45 -23
  41. data/testing/cucumber/features/modeling/rule_modeling.feature +108 -0
  42. data/testing/cucumber/features/modeling/rule_output.feature +111 -0
  43. metadata +68 -161
  44. data/.gitignore +0 -18
  45. data/.simplecov +0 -7
  46. data/.travis.yml +0 -81
  47. data/Gemfile +0 -44
  48. data/Rakefile +0 -73
  49. data/appveyor.yml +0 -88
  50. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +0 -274
  51. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +0 -297
  52. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +0 -309
  53. data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +0 -12
  54. data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +0 -310
  55. data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +0 -307
  56. data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +0 -12
  57. data/testing/cucumber/step_definitions/action_steps.rb +0 -13
  58. data/testing/cucumber/step_definitions/background_steps.rb +0 -1
  59. data/testing/cucumber/step_definitions/directory_steps.rb +0 -6
  60. data/testing/cucumber/step_definitions/doc_string_steps.rb +0 -1
  61. data/testing/cucumber/step_definitions/feature_file_steps.rb +0 -16
  62. data/testing/cucumber/step_definitions/feature_steps.rb +0 -7
  63. data/testing/cucumber/step_definitions/modeling_steps.rb +0 -49
  64. data/testing/cucumber/step_definitions/setup_steps.rb +0 -32
  65. data/testing/cucumber/step_definitions/step_steps.rb +0 -3
  66. data/testing/cucumber/step_definitions/table_steps.rb +0 -1
  67. data/testing/cucumber/step_definitions/tag_steps.rb +0 -3
  68. data/testing/cucumber/step_definitions/verification_steps.rb +0 -181
  69. data/testing/cucumber/support/env.rb +0 -30
  70. data/testing/dialect_helper.rb +0 -48
  71. data/testing/file_helper.rb +0 -47
  72. data/testing/gemfiles/gherkin2.gemfile +0 -33
  73. data/testing/gemfiles/gherkin3.gemfile +0 -26
  74. data/testing/gemfiles/gherkin4.gemfile +0 -27
  75. data/testing/gemfiles/gherkin5.gemfile +0 -27
  76. data/testing/gemfiles/gherkin6.gemfile +0 -10
  77. data/testing/gemfiles/gherkin7.gemfile +0 -9
  78. data/testing/gemfiles/gherkin8.gemfile +0 -9
  79. data/testing/gemfiles/gherkin9.gemfile +0 -9
  80. data/testing/helper_methods.rb +0 -23
  81. data/testing/rspec/spec/integration/adapters/gherkin_2_adapter_spec.rb +0 -166
  82. data/testing/rspec/spec/integration/adapters/gherkin_3_adapter_spec.rb +0 -166
  83. data/testing/rspec/spec/integration/adapters/gherkin_4_adapter_spec.rb +0 -165
  84. data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +0 -165
  85. data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +0 -159
  86. data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +0 -162
  87. data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +0 -162
  88. data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +0 -162
  89. data/testing/rspec/spec/integration/models/background_integration_spec.rb +0 -438
  90. data/testing/rspec/spec/integration/models/cell_integration_spec.rb +0 -338
  91. data/testing/rspec/spec/integration/models/comment_integration_spec.rb +0 -180
  92. data/testing/rspec/spec/integration/models/directory_integration_spec.rb +0 -218
  93. data/testing/rspec/spec/integration/models/doc_string_integration_spec.rb +0 -398
  94. data/testing/rspec/spec/integration/models/example_integration_spec.rb +0 -753
  95. data/testing/rspec/spec/integration/models/feature_file_integration_spec.rb +0 -276
  96. data/testing/rspec/spec/integration/models/feature_integration_spec.rb +0 -655
  97. data/testing/rspec/spec/integration/models/model_integration_spec.rb +0 -15
  98. data/testing/rspec/spec/integration/models/outline_integration_spec.rb +0 -619
  99. data/testing/rspec/spec/integration/models/row_integration_spec.rb +0 -303
  100. data/testing/rspec/spec/integration/models/scenario_integration_spec.rb +0 -475
  101. data/testing/rspec/spec/integration/models/step_integration_spec.rb +0 -573
  102. data/testing/rspec/spec/integration/models/table_integration_spec.rb +0 -333
  103. data/testing/rspec/spec/integration/models/tag_integration_spec.rb +0 -271
  104. data/testing/rspec/spec/integration/nested_integration_spec.rb +0 -91
  105. data/testing/rspec/spec/integration/parsing_integration_spec.rb +0 -143
  106. data/testing/rspec/spec/integration/shared/models_integration_specs.rb +0 -18
  107. data/testing/rspec/spec/spec_helper.rb +0 -129
  108. data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +0 -25
  109. data/testing/rspec/spec/unit/described_unit_spec.rb +0 -23
  110. data/testing/rspec/spec/unit/models/background_unit_spec.rb +0 -83
  111. data/testing/rspec/spec/unit/models/cell_unit_spec.rb +0 -68
  112. data/testing/rspec/spec/unit/models/comment_unit_spec.rb +0 -68
  113. data/testing/rspec/spec/unit/models/directory_unit_spec.rb +0 -127
  114. data/testing/rspec/spec/unit/models/doc_string_unit_spec.rb +0 -100
  115. data/testing/rspec/spec/unit/models/example_unit_spec.rb +0 -133
  116. data/testing/rspec/spec/unit/models/feature_file_unit_spec.rb +0 -125
  117. data/testing/rspec/spec/unit/models/feature_unit_spec.rb +0 -157
  118. data/testing/rspec/spec/unit/models/model_unit_spec.rb +0 -15
  119. data/testing/rspec/spec/unit/models/outline_unit_spec.rb +0 -117
  120. data/testing/rspec/spec/unit/models/row_unit_spec.rb +0 -68
  121. data/testing/rspec/spec/unit/models/scenario_unit_spec.rb +0 -86
  122. data/testing/rspec/spec/unit/models/step_unit_spec.rb +0 -109
  123. data/testing/rspec/spec/unit/models/table_unit_spec.rb +0 -77
  124. data/testing/rspec/spec/unit/models/tag_unit_spec.rb +0 -68
  125. data/testing/rspec/spec/unit/named_unit_spec.rb +0 -23
  126. data/testing/rspec/spec/unit/nested_unit_spec.rb +0 -43
  127. data/testing/rspec/spec/unit/parsed_unit_spec.rb +0 -27
  128. data/testing/rspec/spec/unit/parsing_unit_spec.rb +0 -54
  129. data/testing/rspec/spec/unit/shared/bare_bones_models_unit_specs.rb +0 -14
  130. data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +0 -127
  131. data/testing/rspec/spec/unit/shared/described_models_unit_specs.rb +0 -38
  132. data/testing/rspec/spec/unit/shared/keyworded_models_unit_specs.rb +0 -58
  133. data/testing/rspec/spec/unit/shared/models_unit_specs.rb +0 -15
  134. data/testing/rspec/spec/unit/shared/named_models_unit_specs.rb +0 -39
  135. data/testing/rspec/spec/unit/shared/nested_models_unit_specs.rb +0 -51
  136. data/testing/rspec/spec/unit/shared/parsed_models_unit_specs.rb +0 -39
  137. data/testing/rspec/spec/unit/shared/prepopulated_models_unit_specs.rb +0 -18
  138. data/testing/rspec/spec/unit/shared/sourced_models_unit_specs.rb +0 -39
  139. data/testing/rspec/spec/unit/shared/stepped_models_unit_specs.rb +0 -46
  140. data/testing/rspec/spec/unit/shared/stringifiable_models_unit_specs.rb +0 -18
  141. data/testing/rspec/spec/unit/shared/tagged_models_unit_specs.rb +0 -72
  142. data/testing/rspec/spec/unit/sourceable_unit_spec.rb +0 -27
  143. data/testing/rspec/spec/unit/stepped_unit_spec.rb +0 -23
  144. data/testing/rspec/spec/unit/taggable_unit_spec.rb +0 -69
  145. data/testing/test_languages.json +0 -45
  146. data/todo.txt +0 -25
@@ -1,276 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'FeatureFile, Integration' do
5
-
6
- let(:clazz) { CukeModeler::FeatureFile }
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
- describe 'parsing data' do
18
-
19
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
20
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: test feature", :name => 'test_file')
21
-
22
- feature_file = clazz.new(test_file_path)
23
- data = feature_file.parsing_data
24
-
25
- expect(data.keys).to match_array([:uri, :feature, :comments])
26
- expect(File.basename(data[:uri])).to eq('test_file.feature')
27
- end
28
-
29
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(4, 5) do
30
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: test feature", :name => 'test_file')
31
-
32
- feature_file = clazz.new(test_file_path)
33
- data = feature_file.parsing_data
34
-
35
- expect(data.keys).to match_array([:type, :feature, :comments])
36
- expect(data[:type]).to eq(:GherkinDocument)
37
- end
38
-
39
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(3) do
40
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: test feature", :name => 'test_file')
41
-
42
- feature_file = clazz.new(test_file_path)
43
- data = feature_file.parsing_data
44
-
45
- # There is no parsing data stored above the feature level for gherkin 3.x
46
- expect(data).to be_nil
47
- end
48
-
49
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
50
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: test feature", :name => 'test_file')
51
-
52
- feature_file = clazz.new(test_file_path)
53
- data = feature_file.parsing_data
54
-
55
- # There is no parsing data stored above the feature level for gherkin 2.x
56
- expect(data).to eq([])
57
- end
58
-
59
- end
60
-
61
- it 'provides its own filename when being parsed' do
62
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => 'bad feature text', :name => 'test_file')
63
-
64
- expect { clazz.new(test_file_path) }.to raise_error(/'#{test_file_path}'/)
65
- end
66
-
67
- it 'cannot model a non-existent feature file' do
68
- path = "#{CukeModeler::FileHelper.create_directory}/missing_file.feature"
69
-
70
- expect { clazz.new(path) }.to raise_error(ArgumentError)
71
- end
72
-
73
-
74
- describe 'model population' do
75
-
76
- let(:source_text) { "#{FEATURE_KEYWORD}: Test feature" }
77
- let(:feature_file_path) { CukeModeler::FileHelper.create_feature_file }
78
- let(:feature_file) { clazz.new(feature_file_path) }
79
-
80
- before(:each) do
81
- File.open(feature_file_path, 'w') { |file| file.write(source_text) }
82
- end
83
-
84
- it "models the feature file's name" do
85
- expect(feature_file.name).to eq(File.basename(feature_file_path))
86
- end
87
-
88
- it "models the feature file's path" do
89
- expect(feature_file.path).to eq(feature_file_path)
90
- end
91
-
92
- it "models the feature file's feature" do
93
- feature_name = feature_file.feature.name
94
-
95
- expect(feature_name).to eq('Test feature')
96
- end
97
-
98
- it "models the feature file's comments" do
99
- source_text = "# feature comment
100
- @tag1 @tag2 @tag3
101
- #{FEATURE_KEYWORD}: A feature with everything it could have
102
-
103
- Including a description
104
- and then some.
105
-
106
- # background comment
107
- #{BACKGROUND_KEYWORD}:
108
-
109
- Background
110
- description
111
-
112
- #{STEP_KEYWORD} a step
113
- # table comment
114
- | value1 |
115
- # table row comment
116
- | value2 |
117
- #{STEP_KEYWORD} another step
118
-
119
- # scenario comment
120
- @scenario_tag
121
- #{SCENARIO_KEYWORD}:
122
-
123
- Scenario
124
- description
125
-
126
- #{STEP_KEYWORD} a step
127
- #{STEP_KEYWORD} another step
128
- \"\"\"
129
- some text
130
- \"\"\"
131
-
132
- # outline comment
133
- @outline_tag
134
- #{OUTLINE_KEYWORD}:
135
-
136
- Outline
137
- description
138
-
139
- # step comment
140
- #{STEP_KEYWORD} a step
141
- # table comment
142
- | value2 |
143
- # step comment
144
- #{STEP_KEYWORD} another step
145
- # doc string comment
146
- \"\"\"
147
- some text
148
- \"\"\"
149
-
150
- # example comment
151
- @example_tag
152
- #{EXAMPLE_KEYWORD}:
153
-
154
- Example
155
- description
156
-
157
- # row comment
158
- | param |
159
- | value |
160
- # final comment"
161
-
162
- File.open(feature_file_path, 'w') { |file| file.write(source_text) }
163
-
164
- feature_file = clazz.new(feature_file_path)
165
- comments = feature_file.comments.collect { |comment| comment.text }
166
-
167
-
168
- expected_comments = ['# feature comment',
169
- '# background comment',
170
- '# table comment',
171
- '# table row comment',
172
- '# scenario comment',
173
- '# outline comment',
174
- '# step comment',
175
- '# table comment',
176
- '# step comment',
177
- '# doc string comment',
178
- '# example comment',
179
- '# row comment']
180
-
181
- # gherkin 2.x 'loses' comments that are not followed by some element
182
- expected_comments << '# final comment' unless Gem.loaded_specs['gherkin'].version.version[/^2\./]
183
-
184
-
185
- expect(comments).to match_array(expected_comments)
186
- end
187
-
188
-
189
- # gherkin 3.x does not accept empty feature files
190
- context 'an empty feature file', :unless => gherkin?(3) do
191
-
192
- let(:source_text) { '' }
193
-
194
-
195
- it "models the feature file's feature" do
196
- expect(feature_file.feature).to be_nil
197
- end
198
-
199
- end
200
-
201
- end
202
-
203
- it 'properly sets its child models' do
204
- file_path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: Test feature", :name => 'test_file')
205
-
206
- file = clazz.new(file_path)
207
- feature = file.feature
208
-
209
- expect(feature.parent_model).to equal(file)
210
- end
211
-
212
-
213
- describe 'getting ancestors' do
214
-
215
- let(:directory_path) { CukeModeler::FileHelper.create_directory }
216
- let(:feature_file_path) { CukeModeler::FileHelper.create_feature_file(:text => '', :name => 'feature_file_test_file', :directory => directory_path) }
217
-
218
- before(:each) do
219
- File.open(feature_file_path, 'w') { |file| file.write("#{FEATURE_KEYWORD}: Test feature") }
220
- end
221
-
222
- let(:directory_model) { CukeModeler::Directory.new(directory_path) }
223
- let(:feature_file_model) { directory_model.feature_files.first }
224
-
225
-
226
- it 'can get its directory' do
227
- ancestor = feature_file_model.get_ancestor(:directory)
228
-
229
- expect(ancestor).to equal(directory_model)
230
- end
231
-
232
- it 'returns nil if it does not have the requested type of ancestor' do
233
- ancestor = feature_file_model.get_ancestor(:example)
234
-
235
- expect(ancestor).to be_nil
236
- end
237
-
238
- end
239
-
240
-
241
- describe 'feature file output' do
242
-
243
- context 'from source text' do
244
-
245
- let(:source_text) { "#{FEATURE_KEYWORD}: Test feature" }
246
- let(:feature_file_path) { CukeModeler::FileHelper.create_feature_file(:text => '', :name => 'feature_file_test_file') }
247
- let(:feature_file) { clazz.new(feature_file_path) }
248
-
249
- before(:each) do
250
- File.open(feature_file_path, 'w') { |file| file.write(source_text) }
251
- end
252
-
253
-
254
- it 'can output a feature file' do
255
- feature_file_output = feature_file.to_s
256
-
257
- expect(feature_file_output).to eq(feature_file_path)
258
- end
259
-
260
- end
261
-
262
- it 'can be remade from its own output' do
263
- path = CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}:", :name => 'feature_file_test_file')
264
- feature_file = clazz.new(path)
265
-
266
- feature_file_output = feature_file.to_s
267
- remade_feature_file_output = clazz.new(feature_file_output).to_s
268
-
269
- expect(remade_feature_file_output).to eq(feature_file_output)
270
- end
271
-
272
- end
273
-
274
- end
275
-
276
- end
@@ -1,655 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'Feature, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Feature }
7
- let(:feature) { 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' do
19
- source = "#{FEATURE_KEYWORD}:"
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 = "# language: en-au
30
- Pretty much: Feature name"
31
-
32
- expect { @model = clazz.new(source_text) }.to_not raise_error
33
-
34
- # Sanity check in case modeling failed in a non-explosive manner
35
- expect(@model.name).to eq('Feature name')
36
- ensure
37
- # Making sure that our changes don't escape a test and ruin the rest of the suite
38
- CukeModeler::Parsing.dialect = original_dialect
39
- end
40
- end
41
-
42
- it 'provides a descriptive filename when being parsed from stand alone text' do
43
- source = 'bad feature text'
44
-
45
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_feature\.feature'/)
46
- end
47
-
48
- it 'properly sets its child models' do
49
- source = "@a_tag
50
- #{FEATURE_KEYWORD}: Test feature
51
- #{BACKGROUND_KEYWORD}: Test background
52
- #{SCENARIO_KEYWORD}: Test scenario
53
- #{OUTLINE_KEYWORD}: Test outline
54
- #{EXAMPLE_KEYWORD}: Test Examples
55
- | param |
56
- | value |"
57
-
58
-
59
- feature = clazz.new(source)
60
- background = feature.background
61
- scenario = feature.tests[0]
62
- outline = feature.tests[1]
63
- tag = feature.tags[0]
64
-
65
-
66
- expect(outline.parent_model).to equal(feature)
67
- expect(scenario.parent_model).to equal(feature)
68
- expect(background.parent_model).to equal(feature)
69
- expect(tag.parent_model).to equal(feature)
70
- end
71
-
72
- describe 'parsing data' do
73
-
74
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
75
- feature = clazz.new("@tag\n#{FEATURE_KEYWORD}: test feature\ndescription\n#{BACKGROUND_KEYWORD}:\n#{SCENARIO_KEYWORD}:")
76
- data = feature.parsing_data
77
-
78
- expect(data.keys).to match_array([:tags, :location, :language, :keyword, :name, :children, :description])
79
- expect(data[:name]).to eq('test feature')
80
- end
81
-
82
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(4, 5) do
83
- feature = clazz.new("@tag\n#{FEATURE_KEYWORD}: test feature\ndescription\n#{BACKGROUND_KEYWORD}:\n#{SCENARIO_KEYWORD}:")
84
- data = feature.parsing_data
85
-
86
- expect(data.keys).to match_array([:type, :tags, :location, :language, :keyword, :name, :children, :description])
87
- expect(data[:type]).to eq(:Feature)
88
- end
89
-
90
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(3) do
91
- feature = clazz.new("@tag\n#{FEATURE_KEYWORD}: test feature\ndescription\n#{BACKGROUND_KEYWORD}:\n#{SCENARIO_KEYWORD}:")
92
- data = feature.parsing_data
93
-
94
- expect(data.keys).to match_array([:type, :tags, :location, :language, :keyword, :name, :scenarioDefinitions, :comments, :background, :description])
95
- expect(data[:type]).to eq(:Feature)
96
- end
97
-
98
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
99
- feature = clazz.new("@tag\n#{FEATURE_KEYWORD}: test feature\ndescription\n#{BACKGROUND_KEYWORD}:\n#{SCENARIO_KEYWORD}:")
100
- data = feature.parsing_data
101
-
102
- expect(data.keys).to match_array(['keyword', 'name', 'line', 'description', 'id', 'uri', 'elements', 'tags'])
103
- expect(data['keyword']).to eq('Feature')
104
- end
105
-
106
- end
107
-
108
-
109
- it 'trims whitespace from its source description' do
110
- source = ["#{FEATURE_KEYWORD}:",
111
- ' ',
112
- ' description line 1',
113
- '',
114
- ' description line 2',
115
- ' description line 3 ',
116
- '',
117
- '',
118
- '',
119
- " #{SCENARIO_KEYWORD}:"]
120
- source = source.join("\n")
121
-
122
- feature = clazz.new(source)
123
- description = feature.description.split("\n", -1)
124
-
125
- expect(description).to eq([' description line 1',
126
- '',
127
- 'description line 2',
128
- ' description line 3'])
129
- end
130
-
131
- it 'can selectively access its scenarios and outlines' do
132
- scenarios = [CukeModeler::Scenario.new, CukeModeler::Scenario.new]
133
- outlines = [CukeModeler::Outline.new, CukeModeler::Outline.new]
134
-
135
- feature.tests = scenarios + outlines
136
-
137
- expect(feature.scenarios).to match_array(scenarios)
138
- expect(feature.outlines).to match_array(outlines)
139
- end
140
-
141
-
142
- describe 'model population' do
143
-
144
- context 'from source text' do
145
-
146
- it "models the feature's keyword" do
147
- source_text = "#{FEATURE_KEYWORD}:"
148
- feature = CukeModeler::Feature.new(source_text)
149
-
150
- expect(feature.keyword).to eq(FEATURE_KEYWORD)
151
- end
152
-
153
- it "models the feature's source line" do
154
- source_text = "#{FEATURE_KEYWORD}:"
155
- feature = CukeModeler::Feature.new(source_text)
156
-
157
- expect(feature.source_line).to eq(1)
158
- end
159
-
160
-
161
- context 'a filled feature' do
162
-
163
- let(:source_text) { "@tag_1 @tag_2
164
- #{FEATURE_KEYWORD}: Feature Foo
165
-
166
- Some feature description.
167
-
168
- Some more.
169
- And some more.
170
-
171
- #{BACKGROUND_KEYWORD}: The background
172
- #{STEP_KEYWORD} some setup step
173
-
174
- #{SCENARIO_KEYWORD}: Scenario 1
175
- #{STEP_KEYWORD} a step
176
-
177
- #{OUTLINE_KEYWORD}: Outline 1
178
- #{STEP_KEYWORD} a step
179
- #{EXAMPLE_KEYWORD}:
180
- | param |
181
- | value |
182
-
183
- #{SCENARIO_KEYWORD}: Scenario 2
184
- #{STEP_KEYWORD} a step
185
-
186
- #{OUTLINE_KEYWORD}: Outline 2
187
- #{STEP_KEYWORD} a step
188
- #{EXAMPLE_KEYWORD}:
189
- | param |
190
- | value |" }
191
- let(:feature) { clazz.new(source_text) }
192
-
193
-
194
- it "models the feature's name" do
195
- expect(feature.name).to eq('Feature Foo')
196
- end
197
-
198
- it "models the feature's description" do
199
- description = feature.description.split("\n", -1)
200
-
201
- expect(description).to eq([' Some feature description.',
202
- '',
203
- 'Some more.',
204
- ' And some more.'])
205
- end
206
-
207
- it "models the feature's background" do
208
- expect(feature.background.name).to eq('The background')
209
- end
210
-
211
- it "models the feature's scenarios" do
212
- scenario_names = feature.scenarios.collect { |scenario| scenario.name }
213
-
214
- expect(scenario_names).to eq(['Scenario 1', 'Scenario 2'])
215
- end
216
-
217
- it "models the feature's outlines" do
218
- outline_names = feature.outlines.collect { |outline| outline.name }
219
-
220
- expect(outline_names).to eq(['Outline 1', 'Outline 2'])
221
- end
222
-
223
- it "models the feature's tags" do
224
- tag_names = feature.tags.collect { |tag| tag.name }
225
-
226
- expect(tag_names).to eq(['@tag_1', '@tag_2'])
227
- end
228
-
229
- end
230
-
231
-
232
- context 'an empty feature' do
233
-
234
- let(:source_text) { "#{FEATURE_KEYWORD}:" }
235
- let(:feature) { clazz.new(source_text) }
236
-
237
-
238
- it "models the feature's name" do
239
- expect(feature.name).to eq('')
240
- end
241
-
242
- it "models the feature's description" do
243
- expect(feature.description).to eq('')
244
- end
245
-
246
- it "models the feature's background" do
247
- expect(feature.background).to be_nil
248
- end
249
-
250
- it "models the feature's scenarios" do
251
- expect(feature.scenarios).to eq([])
252
- end
253
-
254
- it "models the feature's outlines" do
255
- expect(feature.outlines).to eq([])
256
- end
257
-
258
- it "models the feature's tags" do
259
- expect(feature.tags).to eq([])
260
- end
261
-
262
- end
263
-
264
- end
265
-
266
- end
267
-
268
-
269
- it 'knows how many test cases it has' do
270
- source_1 = "#{FEATURE_KEYWORD}: Test feature"
271
-
272
- source_2 = "#{FEATURE_KEYWORD}: Test feature
273
- #{SCENARIO_KEYWORD}: Test scenario
274
- #{OUTLINE_KEYWORD}: Test outline
275
- #{STEP_KEYWORD} a step
276
- #{EXAMPLE_KEYWORD}: Test examples
277
- |param|
278
- |value_1|
279
- |value_2|"
280
-
281
- feature_1 = clazz.new(source_1)
282
- feature_2 = clazz.new(source_2)
283
-
284
-
285
- expect(feature_1.test_case_count).to eq(0)
286
- expect(feature_2.test_case_count).to eq(3)
287
- end
288
-
289
-
290
- describe 'getting ancestors' do
291
-
292
- before(:each) do
293
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'feature_test_file', :directory => test_directory)
294
- end
295
-
296
-
297
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
298
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature" }
299
-
300
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
301
- let(:feature_model) { directory_model.feature_files.first.feature }
302
-
303
-
304
- it 'can get its directory' do
305
- ancestor = feature_model.get_ancestor(:directory)
306
-
307
- expect(ancestor).to equal(directory_model)
308
- end
309
-
310
- it 'can get its feature file' do
311
- ancestor = feature_model.get_ancestor(:feature_file)
312
-
313
- expect(ancestor).to equal(directory_model.feature_files.first)
314
- end
315
-
316
- it 'returns nil if it does not have the requested type of ancestor' do
317
- ancestor = feature_model.get_ancestor(:test)
318
-
319
- expect(ancestor).to be_nil
320
- end
321
-
322
- end
323
-
324
-
325
- describe 'feature output' do
326
-
327
- it 'can be remade from its own output' do
328
- source = "@tag1 @tag2 @tag3
329
- #{FEATURE_KEYWORD}: A feature with everything it could have
330
-
331
- Including a description
332
- and then some.
333
-
334
- #{BACKGROUND_KEYWORD}:
335
-
336
- Background
337
- description
338
-
339
- #{STEP_KEYWORD} a step
340
- | value1 |
341
- #{STEP_KEYWORD} another step
342
-
343
- @scenario_tag
344
- #{SCENARIO_KEYWORD}:
345
-
346
- Scenario
347
- description
348
-
349
- #{STEP_KEYWORD} a step
350
- #{STEP_KEYWORD} another step
351
- \"\"\"
352
- some text
353
- \"\"\"
354
-
355
- @outline_tag
356
- #{OUTLINE_KEYWORD}:
357
-
358
- Outline
359
- description
360
-
361
- #{STEP_KEYWORD} a step
362
- | value2 |
363
- #{STEP_KEYWORD} another step
364
- \"\"\"
365
- some text
366
- \"\"\"
367
-
368
- @example_tag
369
- #{EXAMPLE_KEYWORD}:
370
-
371
- Example
372
- description
373
-
374
- | param |
375
- | value |"
376
- feature = clazz.new(source)
377
-
378
- feature_output = feature.to_s
379
- remade_feature_output = clazz.new(feature_output).to_s
380
-
381
- expect(remade_feature_output).to eq(feature_output)
382
- end
383
-
384
-
385
- context 'from source text' do
386
-
387
- it 'can output an empty feature' do
388
- source = ["#{FEATURE_KEYWORD}:"]
389
- source = source.join("\n")
390
- feature = clazz.new(source)
391
-
392
- feature_output = feature.to_s.split("\n", -1)
393
-
394
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}:"])
395
- end
396
-
397
- it 'can output a feature that has a name' do
398
- source = ["#{FEATURE_KEYWORD}: test feature"]
399
- source = source.join("\n")
400
- feature = clazz.new(source)
401
-
402
- feature_output = feature.to_s.split("\n", -1)
403
-
404
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}: test feature"])
405
- end
406
-
407
- it 'can output a feature that has a description' do
408
- source = ["#{FEATURE_KEYWORD}:",
409
- 'Some description.',
410
- 'Some more description.']
411
- source = source.join("\n")
412
- feature = clazz.new(source)
413
-
414
- feature_output = feature.to_s.split("\n", -1)
415
-
416
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}:",
417
- '',
418
- 'Some description.',
419
- 'Some more description.'])
420
- end
421
-
422
- it 'can output a feature that has tags' do
423
- source = ['@tag1 @tag2',
424
- '@tag3',
425
- "#{FEATURE_KEYWORD}:"]
426
- source = source.join("\n")
427
- feature = clazz.new(source)
428
-
429
- feature_output = feature.to_s.split("\n", -1)
430
-
431
- expect(feature_output).to eq(['@tag1 @tag2 @tag3',
432
- "#{FEATURE_KEYWORD}:"])
433
- end
434
-
435
- it 'can output a feature that has a background' do
436
- source = ["#{FEATURE_KEYWORD}:",
437
- "#{BACKGROUND_KEYWORD}:",
438
- "#{STEP_KEYWORD} a step"]
439
- source = source.join("\n")
440
- feature = clazz.new(source)
441
-
442
- feature_output = feature.to_s.split("\n", -1)
443
-
444
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}:",
445
- '',
446
- " #{BACKGROUND_KEYWORD}:",
447
- " #{STEP_KEYWORD} a step"])
448
- end
449
-
450
- it 'can output a feature that has a scenario' do
451
- source = ["#{FEATURE_KEYWORD}:",
452
- "#{SCENARIO_KEYWORD}:",
453
- "#{STEP_KEYWORD} a step"]
454
- source = source.join("\n")
455
- feature = clazz.new(source)
456
-
457
- feature_output = feature.to_s.split("\n", -1)
458
-
459
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}:",
460
- '',
461
- " #{SCENARIO_KEYWORD}:",
462
- " #{STEP_KEYWORD} a step"])
463
- end
464
-
465
- it 'can output a feature that has an outline' do
466
- source = ["#{FEATURE_KEYWORD}:",
467
- "#{OUTLINE_KEYWORD}:",
468
- "#{STEP_KEYWORD} a step",
469
- "#{EXAMPLE_KEYWORD}:",
470
- '|param|',
471
- '|value|']
472
- source = source.join("\n")
473
- feature = clazz.new(source)
474
-
475
- feature_output = feature.to_s.split("\n", -1)
476
-
477
- expect(feature_output).to eq(["#{FEATURE_KEYWORD}:",
478
- '',
479
- " #{OUTLINE_KEYWORD}:",
480
- " #{STEP_KEYWORD} a step",
481
- '',
482
- " #{EXAMPLE_KEYWORD}:",
483
- ' | param |',
484
- ' | value |'])
485
- end
486
-
487
- it 'can output a feature that has everything' do
488
- source = ['@tag1 @tag2 @tag3',
489
- "#{FEATURE_KEYWORD}: A feature with everything it could have",
490
- 'Including a description',
491
- 'and then some.',
492
- "#{BACKGROUND_KEYWORD}:",
493
- 'Background',
494
- 'description',
495
- "#{STEP_KEYWORD} a step",
496
- '|value1|',
497
- "#{STEP_KEYWORD} another step",
498
- '@scenario_tag',
499
- "#{SCENARIO_KEYWORD}:",
500
- 'Scenario',
501
- 'description',
502
- "#{STEP_KEYWORD} a step",
503
- "#{STEP_KEYWORD} another step",
504
- '"""',
505
- 'some text',
506
- '"""',
507
- '@outline_tag',
508
- "#{OUTLINE_KEYWORD}:",
509
- 'Outline ',
510
- 'description',
511
- "#{STEP_KEYWORD} a step ",
512
- '|value2|',
513
- "#{STEP_KEYWORD} another step",
514
- '"""',
515
- 'some text',
516
- '"""',
517
- '@example_tag',
518
- "#{EXAMPLE_KEYWORD}:",
519
- 'Example',
520
- 'description',
521
- '|param|',
522
- '|value|']
523
- source = source.join("\n")
524
- feature = clazz.new(source)
525
-
526
- feature_output = feature.to_s.split("\n", -1)
527
-
528
- expect(feature_output).to eq(['@tag1 @tag2 @tag3',
529
- "#{FEATURE_KEYWORD}: A feature with everything it could have",
530
- '',
531
- 'Including a description',
532
- 'and then some.',
533
- '',
534
- " #{BACKGROUND_KEYWORD}:",
535
- '',
536
- ' Background',
537
- ' description',
538
- '',
539
- " #{STEP_KEYWORD} a step",
540
- ' | value1 |',
541
- " #{STEP_KEYWORD} another step",
542
- '',
543
- ' @scenario_tag',
544
- " #{SCENARIO_KEYWORD}:",
545
- '',
546
- ' Scenario',
547
- ' description',
548
- '',
549
- " #{STEP_KEYWORD} a step",
550
- " #{STEP_KEYWORD} another step",
551
- ' """',
552
- ' some text',
553
- ' """',
554
- '',
555
- ' @outline_tag',
556
- " #{OUTLINE_KEYWORD}:",
557
- '',
558
- ' Outline',
559
- ' description',
560
- '',
561
- " #{STEP_KEYWORD} a step",
562
- ' | value2 |',
563
- " #{STEP_KEYWORD} another step",
564
- ' """',
565
- ' some text',
566
- ' """',
567
- '',
568
- ' @example_tag',
569
- " #{EXAMPLE_KEYWORD}:",
570
- '',
571
- ' Example',
572
- ' description',
573
- '',
574
- ' | param |',
575
- ' | value |'])
576
- end
577
-
578
- end
579
-
580
-
581
- context 'from abstract instantiation' do
582
-
583
- let(:feature) { clazz.new }
584
-
585
-
586
- it 'can output a feature that has only tags' do
587
- feature.tags = [CukeModeler::Tag.new]
588
-
589
- expect { feature.to_s }.to_not raise_error
590
- end
591
-
592
- it 'can output a feature that has only a background' do
593
- feature.background = [CukeModeler::Background.new]
594
-
595
- expect { feature.to_s }.to_not raise_error
596
- end
597
-
598
- it 'can output a feature that has only scenarios' do
599
- feature.tests = [CukeModeler::Scenario.new]
600
-
601
- expect { feature.to_s }.to_not raise_error
602
- end
603
-
604
- it 'can output a feature that has only outlines' do
605
- feature.tests = [CukeModeler::Outline.new]
606
-
607
- expect { feature.to_s }.to_not raise_error
608
- end
609
-
610
- end
611
-
612
- end
613
-
614
- end
615
-
616
-
617
- describe 'stuff that is in no way part of the public API and entirely subject to change' do
618
-
619
- it 'provides a useful explosion message if it encounters an entirely new type of feature child' do
620
- begin
621
- $old_method = CukeModeler::Parsing.method(:parse_text)
622
-
623
-
624
- # Monkey patch the parsing method to mimic what would essentially be Gherkin creating new types of language objects
625
- module CukeModeler
626
- module Parsing
627
- class << self
628
- def parse_text(source_text, filename)
629
- result = $old_method.call(source_text, filename)
630
-
631
- result.first['feature']['elements'].first['type'] = :some_unknown_type
632
-
633
- result
634
- end
635
- end
636
- end
637
- end
638
-
639
-
640
- expect { clazz.new("#{FEATURE_KEYWORD}:\n#{SCENARIO_KEYWORD}:\n#{STEP_KEYWORD} foo") }.to raise_error(ArgumentError, /Unknown.*some_unknown_type/)
641
- ensure
642
- # Making sure that our changes don't escape a test and ruin the rest of the suite
643
- module CukeModeler
644
- module Parsing
645
- class << self
646
- define_method(:parse_text, $old_method)
647
- end
648
- end
649
- end
650
- end
651
- end
652
-
653
- end
654
-
655
- end