cuke_modeler 1.5.1 → 3.2.0

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