cuke_modeler 1.3.0 → 2.1.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 (90) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +60 -17
  3. data/CHANGELOG.md +312 -0
  4. data/Gemfile +19 -3
  5. data/LICENSE.txt +1 -1
  6. data/README.md +17 -7
  7. data/Rakefile +45 -28
  8. data/appveyor.yml +57 -17
  9. data/cuke_modeler.gemspec +6 -3
  10. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +1 -0
  11. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +1 -0
  12. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +2 -1
  13. data/lib/cuke_modeler/adapters/gherkin_5_adapter.rb +12 -0
  14. data/lib/cuke_modeler/adapters/gherkin_6_adapter.rb +310 -0
  15. data/lib/cuke_modeler/adapters/gherkin_7_adapter.rb +307 -0
  16. data/lib/cuke_modeler/adapters/gherkin_8_adapter.rb +12 -0
  17. data/lib/cuke_modeler/adapters/gherkin_9_adapter.rb +12 -0
  18. data/lib/cuke_modeler/containing.rb +16 -0
  19. data/lib/cuke_modeler/described.rb +1 -0
  20. data/lib/cuke_modeler/models/step.rb +31 -2
  21. data/lib/cuke_modeler/named.rb +1 -0
  22. data/lib/cuke_modeler/nested.rb +1 -0
  23. data/lib/cuke_modeler/parsed.rb +1 -0
  24. data/lib/cuke_modeler/parsing.rb +116 -68
  25. data/lib/cuke_modeler/sourceable.rb +1 -0
  26. data/lib/cuke_modeler/stepped.rb +1 -0
  27. data/lib/cuke_modeler/taggable.rb +1 -0
  28. data/lib/cuke_modeler/version.rb +1 -1
  29. data/testing/cucumber/features/analysis/step_comparison.feature +25 -0
  30. data/testing/cucumber/features/analysis/test_comparison.feature +1 -1
  31. data/testing/cucumber/step_definitions/feature_file_steps.rb +1 -1
  32. data/testing/cucumber/step_definitions/modeling_steps.rb +7 -2
  33. data/testing/cucumber/step_definitions/verification_steps.rb +11 -2
  34. data/testing/file_helper.rb +3 -0
  35. data/testing/gemfiles/gherkin2.gemfile +8 -0
  36. data/testing/gemfiles/gherkin3.gemfile +6 -0
  37. data/testing/gemfiles/gherkin4.gemfile +7 -0
  38. data/testing/gemfiles/gherkin5.gemfile +7 -0
  39. data/testing/gemfiles/gherkin6.gemfile +10 -0
  40. data/testing/gemfiles/gherkin7.gemfile +9 -0
  41. data/testing/gemfiles/gherkin8.gemfile +9 -0
  42. data/testing/gemfiles/gherkin9.gemfile +9 -0
  43. data/testing/helper_methods.rb +23 -0
  44. data/testing/rspec/spec/integration/{gherkin_2_adapter_spec.rb → adapters/gherkin_2_adapter_spec.rb} +13 -13
  45. data/testing/rspec/spec/integration/{gherkin_3_adapter_spec.rb → adapters/gherkin_3_adapter_spec.rb} +13 -13
  46. data/testing/rspec/spec/integration/{gherkin_4_adapter_spec.rb → adapters/gherkin_4_adapter_spec.rb} +13 -13
  47. data/testing/rspec/spec/integration/adapters/gherkin_5_adapter_spec.rb +165 -0
  48. data/testing/rspec/spec/integration/adapters/gherkin_6_adapter_spec.rb +159 -0
  49. data/testing/rspec/spec/integration/adapters/gherkin_7_adapter_spec.rb +162 -0
  50. data/testing/rspec/spec/integration/adapters/gherkin_8_adapter_spec.rb +162 -0
  51. data/testing/rspec/spec/integration/adapters/gherkin_9_adapter_spec.rb +162 -0
  52. data/testing/rspec/spec/integration/{background_integration_spec.rb → models/background_integration_spec.rb} +90 -86
  53. data/testing/rspec/spec/integration/{cell_integration_spec.rb → models/cell_integration_spec.rb} +49 -38
  54. data/testing/rspec/spec/integration/{comment_integration_spec.rb → models/comment_integration_spec.rb} +31 -20
  55. data/testing/rspec/spec/integration/{directory_integration_spec.rb → models/directory_integration_spec.rb} +3 -3
  56. data/testing/rspec/spec/integration/{doc_string_integration_spec.rb → models/doc_string_integration_spec.rb} +39 -35
  57. data/testing/rspec/spec/integration/{example_integration_spec.rb → models/example_integration_spec.rb} +109 -83
  58. data/testing/rspec/spec/integration/{feature_file_integration_spec.rb → models/feature_file_integration_spec.rb} +52 -38
  59. data/testing/rspec/spec/integration/{feature_integration_spec.rb → models/feature_integration_spec.rb} +125 -112
  60. data/testing/rspec/spec/integration/{model_integration_spec.rb → models/model_integration_spec.rb} +1 -1
  61. data/testing/rspec/spec/integration/{outline_integration_spec.rb → models/outline_integration_spec.rb} +138 -129
  62. data/testing/rspec/spec/integration/{row_integration_spec.rb → models/row_integration_spec.rb} +55 -35
  63. data/testing/rspec/spec/integration/{scenario_integration_spec.rb → models/scenario_integration_spec.rb} +92 -88
  64. data/testing/rspec/spec/integration/models/step_integration_spec.rb +573 -0
  65. data/testing/rspec/spec/integration/{table_integration_spec.rb → models/table_integration_spec.rb} +38 -34
  66. data/testing/rspec/spec/integration/{tag_integration_spec.rb → models/tag_integration_spec.rb} +56 -36
  67. data/testing/rspec/spec/integration/parsing_integration_spec.rb +45 -7
  68. data/testing/rspec/spec/spec_helper.rb +79 -43
  69. data/testing/rspec/spec/unit/cuke_modeler_unit_spec.rb +25 -0
  70. data/testing/rspec/spec/unit/{background_unit_spec.rb → models/background_unit_spec.rb} +1 -1
  71. data/testing/rspec/spec/unit/{cell_unit_spec.rb → models/cell_unit_spec.rb} +1 -1
  72. data/testing/rspec/spec/unit/{comment_unit_spec.rb → models/comment_unit_spec.rb} +1 -1
  73. data/testing/rspec/spec/unit/{directory_unit_spec.rb → models/directory_unit_spec.rb} +1 -1
  74. data/testing/rspec/spec/unit/{doc_string_unit_spec.rb → models/doc_string_unit_spec.rb} +1 -1
  75. data/testing/rspec/spec/unit/{example_unit_spec.rb → models/example_unit_spec.rb} +1 -1
  76. data/testing/rspec/spec/unit/{feature_file_unit_spec.rb → models/feature_file_unit_spec.rb} +1 -1
  77. data/testing/rspec/spec/unit/{feature_unit_spec.rb → models/feature_unit_spec.rb} +1 -1
  78. data/testing/rspec/spec/unit/{model_unit_spec.rb → models/model_unit_spec.rb} +1 -1
  79. data/testing/rspec/spec/unit/{outline_unit_spec.rb → models/outline_unit_spec.rb} +1 -1
  80. data/testing/rspec/spec/unit/{row_unit_spec.rb → models/row_unit_spec.rb} +1 -1
  81. data/testing/rspec/spec/unit/{scenario_unit_spec.rb → models/scenario_unit_spec.rb} +1 -1
  82. data/testing/rspec/spec/unit/{step_unit_spec.rb → models/step_unit_spec.rb} +2 -2
  83. data/testing/rspec/spec/unit/{table_unit_spec.rb → models/table_unit_spec.rb} +1 -1
  84. data/testing/rspec/spec/unit/{tag_unit_spec.rb → models/tag_unit_spec.rb} +1 -1
  85. data/testing/rspec/spec/unit/shared/containing_models_unit_specs.rb +102 -0
  86. data/todo.txt +5 -2
  87. metadata +80 -47
  88. data/History.md +0 -186
  89. data/testing/cucumber/support/transforms.rb +0 -3
  90. data/testing/rspec/spec/integration/step_integration_spec.rb +0 -459
data/History.md DELETED
@@ -1,186 +0,0 @@
1
- ### Version 1.3.0 / 2017-10-19
2
-
3
- * Now compatible with Gherkin 5.x.
4
-
5
-
6
- ### Version 1.2.1 / 2017-04-25
7
-
8
- * Now officially compatible with Rake 12.x.
9
-
10
-
11
- ### Version 1.2.0 / 2016-11-23
12
-
13
- * The comments in a feature file are now a modeled element.
14
-
15
-
16
- ### Version 1.1.1 / 2016-10-28
17
-
18
- * Bug fix - Abstract instantiation of models when using a non-default dialect
19
- now works correctly.
20
-
21
-
22
- ### Version 1.1.0 / 2016-10-28
23
-
24
- * Support added for non-English dialects. This gem should now be able to model
25
- feature files using any dialect supported by the 'gherkin' gem.
26
-
27
- * Models for elements of Gherkin that have keywords (e.g. 'Feature', 'Scenario',
28
- 'Examples') now keep track of the keyword used by the element that they model.
29
-
30
- * Bug fix - Fixed a bug that was causing example models to output extra newline
31
- characters under certain circumstances.
32
-
33
-
34
- ### Version 1.0.4 / 2016-10-07
35
-
36
- * Bug Fix - Fixed a bug that caused some models to include nil objects in their
37
- children collection if they did not have the relevant child object.
38
-
39
-
40
- ### Version 1.0.3 / 2016-09-12
41
-
42
- * Fixed a gem dependency that was accidentally declared with '<=' instead of '<'.
43
-
44
-
45
- ### Version 1.0.2 / 2016-09-12
46
-
47
- * A more detailed gem description and summary have been added to the gemspec.
48
-
49
- * The gem now declares version limits on its dependencies.
50
-
51
- * Badges for the current status of the project have been added to the Readme.
52
-
53
-
54
- ### Version 1.0.1 / 2016-09-10
55
-
56
- * In the Readme file, added a link to the published documentation.
57
-
58
-
59
- ### Version 1.0.0 / 2016-09-08
60
-
61
- * All modeled elements of a Cucumber test suite are now modeled with actual
62
- classes. Previously, some elements (such as tags or rows in an example table)
63
- were modeled with simple strings.
64
-
65
- * A base model class has been added in order to simplify adding new element
66
- models. Other classes and modules used for organizing common model behavior
67
- have been created/removed/renamed.
68
-
69
- * Feature file models now only have a single feature model instead of a
70
- collection of them (that would only ever have one item in it).
71
-
72
- * Rows in an example table and rows in a step table no longer use two different
73
- classes for modeling.
74
-
75
- * Background models can now be compared to other models that have steps (i.e.
76
- scenarios and outlines).
77
-
78
- * All models for Gherkin elements now track the line number from which they
79
- originate in a source file.
80
-
81
- * The source line of a model is now a mutable attribute instead of being read
82
- only.
83
-
84
- * The file path of a feature file is now a mutable attribute instead of being
85
- read only.
86
-
87
- * Standardized the initial values of the attributes of abstractly created
88
- models so that they are consistent across model types.
89
-
90
- * Added specific ancestor types for scenario, outline, and background models as
91
- alternatives to the generic 'test' ancestor type.
92
-
93
- * Extra whitespace around parsed element descriptions is now trimmed away
94
- before being stored in a model.
95
-
96
- * Adding rows to examples via hashes can now be done without regard to the
97
- order of the keys in the hash. The correct order can be determined by the
98
- model.
99
-
100
- * The saved parsing data that is generated by the 'gherkin' gem is no longer
101
- duplicated for each model, resulting in significantly less memory usage.
102
-
103
- * String output of models has been improved. More special characters in Gherkin
104
- (e.g. vertical bars in rows) are appropriately escaped in the string output
105
- of a model and several minor bugs related to using model string output as the
106
- input text for new models have been fixed.
107
-
108
- * Removed the backdoor used to pass around model data during the model creation
109
- process. Model input can now only be text.
110
-
111
- * Simple counting methods have been removed. Ruby's collection methods are just
112
- as easy to use directly when dealing with classes that contain collections
113
- and the removal of these counting methods simplifies the codebase.
114
-
115
- * The 'World' module has been removed. The scope of this gem is to model files
116
- written in Gherkin. Concepts like 'step definitions' and 'hooks' are better
117
- left to libraries that include (possibly programming language specific) test
118
- execution logic within their scope of concern.
119
-
120
- * Step models no longer have 'arguments' because they require the concept of
121
- step definitions, which are no longer within the scope of this gem.
122
-
123
- * Removed deprecated behavior
124
- - Marked
125
- - Doc strings no longer use an array of strings to model their content
126
- - Tables no longer use nested arrays of strings to model their rows
127
- - Models that have descriptions no longer use an array of strings to
128
- model their description
129
- - The convenient (read: awkward) #step_text has been removed.
130
- - Unmarked
131
- - Examples no longer use an array of hashes to model their rows
132
-
133
- * Various methods have been renamed.
134
-
135
-
136
- ### Version 0.4.1 / 2016-05-12
137
-
138
- * Increased the flexibility of input when adding rows to an Example object. Non-
139
- string values can now be used as input and they will be converted into
140
- strings. Original input objects are not modified.
141
-
142
- * Added some error checking around adding value rows to an Example object
143
- without adding a parameter row as well.
144
-
145
-
146
- ### Version 0.4.0 / 2016-05-01
147
-
148
- * The path of a Directory object is now a changeable attribute instead of only
149
- being populated if the instance was given a diretory to model.
150
-
151
- * Bug fix - Fixed a bug that occurred if a Directory object was asked for its
152
- \#name when it was created as 'abstract' instead of modeling an existing
153
- directory.
154
-
155
-
156
- ### Version 0.3.0 / 2016-04-24
157
-
158
- * Support for version 4.x of the 'gherkin' gem added.
159
-
160
- * Bug fix - Fixed a bug that was preventing Example objects from being created
161
- from text if that text had less Gherkin structure than normal.
162
-
163
-
164
- ### Version 0.2.0 / 2016-02-21
165
-
166
- * Better error feedback when parsing errors are encountered. It is now easier
167
- to tell which file contained invalid Gherkin.
168
-
169
-
170
- ### Version 0.1.0 / 2016-02-10
171
-
172
- * Support for version 3.x of the 'gherkin' gem added.
173
-
174
- * Bug fix - The saved parsing data that is generated by the 'gherkin' gem is no
175
- longer modified by the rest of the model creation process.
176
-
177
-
178
- ### Version 0.0.2 / 2015-11-22
179
-
180
- * Bug fix - Fixed a bug that was causing object comparison using #== to not
181
- work when comparing some models to other types of objects.
182
-
183
-
184
- ### Version 0.0.1 / 2014-06-02
185
-
186
- * Initial release
@@ -1,3 +0,0 @@
1
- Transform /^(-?\d+)$/ do |number|
2
- number.to_i
3
- end
@@ -1,459 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
2
-
3
-
4
- describe 'Step, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Step }
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 = "#{@step_keyword} a step"
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 = "Y'know a step"
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.keyword).to eq("Y'know")
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 step text\n And a step\n @foo"
42
-
43
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_step\.feature'/)
44
- end
45
-
46
- it 'stores the original data generated by the parsing adapter (with a table)', :gherkin4 => true do
47
- step = clazz.new("#{@step_keyword} test step\n|table|")
48
- data = step.parsing_data
49
-
50
- expect(data.keys).to match_array([:type, :location, :keyword, :text, :argument])
51
- expect(data[:type]).to eq(:Step)
52
- end
53
-
54
- it 'stores the original data generated by the parsing adapter (with a doc string)', :gherkin4 => true do
55
- step = clazz.new("#{@step_keyword} test step\n\"\"\"\na doc string\n\"\"\"")
56
- data = step.parsing_data
57
-
58
- expect(data.keys).to match_array([:type, :location, :keyword, :text, :argument])
59
- expect(data[:type]).to eq(:Step)
60
- end
61
-
62
- it 'stores the original data generated by the parsing adapter (with a table)', :gherkin3 => true do
63
- step = clazz.new("#{@step_keyword} test step\n|table|")
64
- data = step.parsing_data
65
-
66
- expect(data.keys).to match_array([:type, :location, :keyword, :text, :argument])
67
- expect(data[:type]).to eq(:Step)
68
- end
69
-
70
- it 'stores the original data generated by the parsing adapter (with a doc string)', :gherkin3 => true do
71
- step = clazz.new("#{@step_keyword} test step\n\"\"\"\na doc string\n\"\"\"")
72
- data = step.parsing_data
73
-
74
- expect(data.keys).to match_array([:type, :location, :keyword, :text, :argument])
75
- expect(data[:type]).to eq(:Step)
76
- end
77
-
78
- it 'stores the original data generated by the parsing adapter (with a table)', :gherkin2 => true do
79
- step = clazz.new("#{@step_keyword} test step\n|table|")
80
- data = step.parsing_data
81
-
82
- expect(data.keys).to match_array(['keyword', 'name', 'line', 'rows'])
83
- expect(data['keyword']).to eq("#{@step_keyword} ")
84
- end
85
-
86
- it 'stores the original data generated by the parsing adapter (with a doc string)', :gherkin2 => true do
87
- step = clazz.new("#{@step_keyword} test step\n\"\"\"\na doc string\n\"\"\"")
88
- data = step.parsing_data
89
-
90
- expect(data.keys).to match_array(['keyword', 'name', 'line', 'doc_string'])
91
- expect(data['keyword']).to eq("#{@step_keyword} ")
92
- end
93
-
94
- describe 'model population' do
95
-
96
- context 'from source text' do
97
-
98
- let(:source_text) { "#{@step_keyword} a step" }
99
- let(:step) { clazz.new(source_text) }
100
-
101
-
102
- it "models the step's keyword" do
103
- expect(step.keyword).to eq("#{@step_keyword}")
104
- end
105
-
106
- it "models the step's text" do
107
- expect(step.text).to eq('a step')
108
- end
109
-
110
- it "models the step's source line" do
111
- source_text = "#{@feature_keyword}:
112
-
113
- #{@scenario_keyword}: foo
114
- #{@step_keyword} step"
115
- step = CukeModeler::Feature.new(source_text).tests.first.steps.first
116
-
117
- expect(step.source_line).to eq(4)
118
- end
119
-
120
-
121
- context 'with no block' do
122
-
123
- let(:source_text) { "#{@step_keyword} a step" }
124
- let(:step) { clazz.new(source_text) }
125
-
126
-
127
- it "models the step's block" do
128
- expect(step.block).to be_nil
129
- end
130
-
131
- end
132
-
133
- context 'a step with a table' do
134
-
135
- let(:source_text) { "#{@step_keyword} a step
136
- | value 1 |
137
- | value 2 |" }
138
- let(:step) { clazz.new(source_text) }
139
-
140
-
141
- it "models the step's table" do
142
- table_cell_values = step.block.rows.collect { |row| row.cells.collect { |cell| cell.value } }
143
-
144
- expect(table_cell_values).to eq([['value 1'], ['value 2']])
145
- end
146
-
147
- end
148
-
149
- context 'a step with a doc string' do
150
-
151
- let(:source_text) { "#{@step_keyword} a step
152
- \"\"\"
153
- some text
154
- \"\"\"" }
155
- let(:step) { clazz.new(source_text) }
156
-
157
-
158
- it "models the step's doc string" do
159
- doc_string = step.block
160
-
161
- expect(doc_string.content).to eq('some text')
162
- end
163
-
164
- end
165
-
166
- end
167
-
168
- end
169
-
170
-
171
- it 'properly sets its child models' do
172
- source_1 = "#{@step_keyword} a step
173
- \"\"\"
174
- a doc string
175
- \"\"\""
176
- source_2 = "#{@step_keyword} a step
177
- | a block|"
178
-
179
- step_1 = clazz.new(source_1)
180
- step_2 = clazz.new(source_2)
181
-
182
-
183
- doc_string = step_1.block
184
- table = step_2.block
185
-
186
- expect(doc_string.parent_model).to equal(step_1)
187
- expect(table.parent_model).to equal(step_2)
188
- end
189
-
190
-
191
- describe 'step comparison' do
192
-
193
- it 'is equal to another Step that has the same text' do
194
- source_1 = "#{@step_keyword} a step"
195
- source_2 = "#{@step_keyword} a step"
196
- source_3 = "#{@step_keyword} a different step"
197
-
198
- step_1 = clazz.new(source_1)
199
- step_2 = clazz.new(source_2)
200
- step_3 = clazz.new(source_3)
201
-
202
-
203
- expect(step_1).to eq(step_2)
204
- expect(step_1).to_not eq(step_3)
205
- end
206
-
207
- it 'ignores steps keywords when comparing steps' do
208
- source_1 = "#{@given_keyword} a step"
209
- source_2 = "#{@then_keyword} a step"
210
-
211
- step_1 = clazz.new(source_1)
212
- step_2 = clazz.new(source_2)
213
-
214
-
215
- expect(step_1).to eq(step_2)
216
- end
217
-
218
- it 'ignores step tables when comparing steps' do
219
- source_1 = "#{@step_keyword} a step"
220
- source_2 = "#{@step_keyword} a step\n|with a table|"
221
-
222
- step_1 = clazz.new(source_1)
223
- step_2 = clazz.new(source_2)
224
-
225
-
226
- expect(step_1).to eq(step_2)
227
- end
228
-
229
- it 'ignores step doc strings when comparing steps' do
230
- source_1 = "#{@step_keyword} a step"
231
- source_2 = "#{@step_keyword} a step\n\"\"\"\nwith a doc string\n\"\"\""
232
-
233
-
234
- step_1 = clazz.new(source_1)
235
- step_2 = clazz.new(source_2)
236
-
237
-
238
- expect(step_1).to eq(step_2)
239
- end
240
-
241
- end
242
-
243
-
244
- describe 'getting ancestors' do
245
-
246
- before(:each) do
247
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'step_test_file', :directory => test_directory)
248
- end
249
-
250
-
251
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
252
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
253
-
254
- #{@scenario_keyword}: Test test
255
- #{@step_keyword} a step:"
256
- }
257
-
258
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
259
- let(:step_model) { directory_model.feature_files.first.feature.tests.first.steps.first }
260
-
261
-
262
- it 'can get its directory' do
263
- ancestor = step_model.get_ancestor(:directory)
264
-
265
- expect(ancestor).to equal(directory_model)
266
- end
267
-
268
- it 'can get its feature file' do
269
- ancestor = step_model.get_ancestor(:feature_file)
270
-
271
- expect(ancestor).to equal(directory_model.feature_files.first)
272
- end
273
-
274
- it 'can get its feature' do
275
- ancestor = step_model.get_ancestor(:feature)
276
-
277
- expect(ancestor).to equal(directory_model.feature_files.first.feature)
278
- end
279
-
280
-
281
- context 'a step that is part of a scenario' do
282
-
283
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
284
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
285
-
286
- #{@scenario_keyword}: Test scenario
287
- #{@step_keyword} a step"
288
- }
289
-
290
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
291
- let(:step_model) { directory_model.feature_files.first.feature.tests.first.steps.first }
292
-
293
-
294
- it 'can get its scenario' do
295
- ancestor = step_model.get_ancestor(:scenario)
296
-
297
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
298
- end
299
-
300
- end
301
-
302
- context 'a step that is part of an outline' do
303
-
304
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
305
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
306
-
307
- #{@outline_keyword}: Test outline
308
- #{@step_keyword} a step
309
- #{@example_keyword}:
310
- | param |
311
- | value |"
312
- }
313
-
314
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
315
- let(:step_model) { directory_model.feature_files.first.feature.tests.first.steps.first }
316
-
317
-
318
- it 'can get its outline' do
319
- ancestor = step_model.get_ancestor(:outline)
320
-
321
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
322
- end
323
-
324
- end
325
-
326
- context 'a step that is part of a background' do
327
-
328
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
329
- let(:source_gherkin) { "#{@feature_keyword}: Test feature
330
-
331
- #{@background_keyword}: Test background
332
- #{@step_keyword} a step"
333
- }
334
-
335
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
336
- let(:step_model) { directory_model.feature_files.first.feature.background.steps.first }
337
-
338
-
339
- it 'can get its background' do
340
- ancestor = step_model.get_ancestor(:background)
341
-
342
- expect(ancestor).to equal(directory_model.feature_files.first.feature.background)
343
- end
344
-
345
- end
346
-
347
- it 'returns nil if it does not have the requested type of ancestor' do
348
- ancestor = step_model.get_ancestor(:example)
349
-
350
- expect(ancestor).to be_nil
351
- end
352
-
353
- end
354
-
355
-
356
- describe 'step output' do
357
-
358
- context 'from source text' do
359
-
360
- context 'with no block' do
361
-
362
- let(:source_text) { ["#{@step_keyword} a step"].join("\n") }
363
- let(:step) { clazz.new(source_text) }
364
-
365
- it 'can output a step' do
366
- step_output = step.to_s.split("\n", -1)
367
-
368
- expect(step_output).to eq(["#{@step_keyword} a step"])
369
- end
370
-
371
- it 'can be remade from its own output' do
372
- step_output = step.to_s
373
- remade_step_output = clazz.new(step_output).to_s
374
-
375
- expect(remade_step_output).to eq(step_output)
376
- end
377
-
378
- end
379
-
380
- context 'a step with a table' do
381
-
382
- let(:source_text) { ["#{@step_keyword} a step",
383
- ' | value1 | value2 |',
384
- ' | value3 | value4 |'].join("\n") }
385
- let(:step) { clazz.new(source_text) }
386
-
387
-
388
- it 'can output a step that has a table' do
389
- step_output = step.to_s.split("\n", -1)
390
-
391
- expect(step_output).to eq(["#{@step_keyword} a step",
392
- ' | value1 | value2 |',
393
- ' | value3 | value4 |'])
394
-
395
- end
396
-
397
- it 'can be remade from its own output' do
398
- step_output = step.to_s
399
- remade_step_output = clazz.new(step_output).to_s
400
-
401
- expect(remade_step_output).to eq(step_output)
402
- end
403
-
404
- end
405
-
406
- context 'a step with a doc string' do
407
-
408
- let(:source_text) { ["#{@step_keyword} a step",
409
- ' """',
410
- ' some text',
411
- ' """'].join("\n") }
412
- let(:step) { clazz.new(source_text) }
413
-
414
-
415
- it 'can output a step that has a doc string' do
416
- step_output = step.to_s.split("\n", -1)
417
-
418
- expect(step_output).to eq(["#{@step_keyword} a step",
419
- ' """',
420
- ' some text',
421
- ' """'])
422
- end
423
-
424
- it 'can be remade from its own output' do
425
- step_output = step.to_s
426
- remade_step_output = clazz.new(step_output).to_s
427
-
428
- expect(remade_step_output).to eq(step_output)
429
- end
430
-
431
- end
432
-
433
- end
434
-
435
-
436
- context 'from abstract instantiation' do
437
-
438
- let(:step) { clazz.new }
439
-
440
-
441
- it 'can output a step that has only a table' do
442
- step.block = CukeModeler::Table.new
443
-
444
- expect { step.to_s }.to_not raise_error
445
- end
446
-
447
- it 'can output a step that has only a doc string' do
448
- step.block = CukeModeler::DocString.new
449
-
450
- expect { step.to_s }.to_not raise_error
451
- end
452
-
453
- end
454
-
455
- end
456
-
457
- end
458
-
459
- end