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,180 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'Comment, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Comment }
7
-
8
-
9
- describe 'common behavior' do
10
-
11
- it_should_behave_like 'a model, integration'
12
-
13
- end
14
-
15
-
16
- describe 'unique behavior' do
17
-
18
- it 'can be instantiated with the minimum viable Gherkin' do
19
- source = '# a comment'
20
-
21
- expect { clazz.new(source) }.to_not raise_error
22
- end
23
-
24
- it 'can parse text that uses a non-default dialect' do
25
- original_dialect = CukeModeler::Parsing.dialect
26
- CukeModeler::Parsing.dialect = 'en-au'
27
-
28
- begin
29
- source_text = '# a comment'
30
-
31
- expect { @model = clazz.new(source_text) }.to_not raise_error
32
-
33
- # Sanity check in case modeling failed in a non-explosive manner
34
- expect(@model.text).to eq('# a comment')
35
- ensure
36
- # Making sure that our changes don't escape a test and ruin the rest of the suite
37
- CukeModeler::Parsing.dialect = original_dialect
38
- end
39
- end
40
-
41
- it 'provides a descriptive filename when being parsed from stand alone text' do
42
- source = 'bad comment text'
43
-
44
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_comment\.feature'/)
45
- end
46
-
47
- describe 'parsing data' do
48
-
49
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
50
- comment = clazz.new('# a comment')
51
- data = comment.parsing_data
52
-
53
- expect(data.keys).to match_array([:location, :text])
54
- expect(data[:text]).to eq('# a comment')
55
- end
56
-
57
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(4, 5) do
58
- comment = clazz.new('# a comment')
59
- data = comment.parsing_data
60
-
61
- expect(data.keys).to match_array([:type, :location, :text])
62
- expect(data[:type]).to eq(:Comment)
63
- end
64
-
65
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(3) do
66
- comment = clazz.new('# a comment')
67
- data = comment.parsing_data
68
-
69
- expect(data.keys).to match_array([:type, :location, :text])
70
- expect(data[:type]).to eq('Comment')
71
- end
72
-
73
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
74
- comment = clazz.new('# a comment')
75
- data = comment.parsing_data
76
-
77
- expect(data.keys).to match_array(['value', 'line'])
78
- end
79
-
80
- end
81
-
82
- describe 'getting ancestors' do
83
-
84
- before(:each) do
85
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'comment_test_file', :directory => test_directory)
86
- end
87
-
88
-
89
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
90
- let(:source_gherkin) { "# feature comment
91
- #{FEATURE_KEYWORD}: Test feature"
92
- }
93
-
94
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
95
- let(:comment_model) { directory_model.feature_files.first.comments.first }
96
-
97
-
98
- it 'can get its directory' do
99
- ancestor = comment_model.get_ancestor(:directory)
100
-
101
- expect(ancestor).to equal(directory_model)
102
- end
103
-
104
- it 'can get its feature file' do
105
- ancestor = comment_model.get_ancestor(:feature_file)
106
-
107
- expect(ancestor).to equal(directory_model.feature_files.first)
108
- end
109
-
110
- it 'returns nil if it does not have the requested type of ancestor' do
111
- ancestor = comment_model.get_ancestor(:example)
112
-
113
- expect(ancestor).to be_nil
114
- end
115
-
116
- end
117
-
118
-
119
- describe 'model population' do
120
-
121
- context 'from source text' do
122
-
123
- let(:source_text) { '# a comment' }
124
- let(:comment) { clazz.new(source_text) }
125
-
126
-
127
- it "models the comment's text" do
128
- expect(comment.text).to eq('# a comment')
129
- end
130
-
131
- it "models the comment's source line" do
132
- source_text = "# a comment
133
- #{FEATURE_KEYWORD}:"
134
-
135
- test_file_path = CukeModeler::FileHelper.create_feature_file(:text => source_text, :name => 'comment_test_file')
136
- comment = CukeModeler::FeatureFile.new(test_file_path).comments.first
137
-
138
- expect(comment.source_line).to eq(1)
139
- end
140
-
141
- it 'removes surrounding whitespace' do
142
- comment = clazz.new(' # a comment ')
143
-
144
- expect(comment.text).to eq('# a comment')
145
- end
146
-
147
- end
148
-
149
- end
150
-
151
-
152
- describe 'comment output' do
153
-
154
- it 'can be remade from its own output' do
155
- source = '# a comment'
156
- comment = clazz.new(source)
157
-
158
- comment_output = comment.to_s
159
- remade_comment_output = clazz.new(comment_output).to_s
160
-
161
- expect(remade_comment_output).to eq(comment_output)
162
- end
163
-
164
-
165
- context 'from source text' do
166
-
167
- it 'can output a comment' do
168
- source = '# a comment'
169
- comment = clazz.new(source)
170
-
171
- expect(comment.to_s).to eq('# a comment')
172
- end
173
-
174
- end
175
-
176
- end
177
-
178
- end
179
-
180
- end
@@ -1,218 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'Directory, Integration' do
5
-
6
- let(:clazz) { CukeModeler::Directory }
7
-
8
-
9
- describe 'common behavior' do
10
-
11
- it_should_behave_like 'a model, integration'
12
-
13
- end
14
-
15
-
16
- describe 'unique behavior' do
17
-
18
-
19
- describe 'modeling directories' do
20
-
21
-
22
- context 'with an existing directory' do
23
-
24
- let(:root_test_path) { CukeModeler::FileHelper.create_directory }
25
-
26
- let(:directory_path) { CukeModeler::FileHelper.create_directory(:name => 'nested_directory', :directory => root_test_path) }
27
- let(:directory_model) { clazz.new(directory_path) }
28
-
29
-
30
- it 'models the path of the directory' do
31
- expect(directory_model.path).to eq(directory_path)
32
- end
33
-
34
- it 'models the name of the directory' do
35
- name = File.basename(directory_path)
36
-
37
- expect(directory_model.name).to eq(name)
38
- end
39
-
40
-
41
- context 'with both files and feature files' do
42
-
43
- let(:feature_files) { ['test_file_1', 'test_file_2'] }
44
- let(:non_feature_files) { ['test_file_3'] }
45
-
46
- before(:each) do
47
- feature_files.each do |file_name|
48
- # Some versions of Gherkin require feature content to be present in feature files
49
- CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: Test feature", :name => file_name, :directory => directory_path)
50
- end
51
-
52
- non_feature_files.each do |file_name|
53
- CukeModeler::FileHelper.create_file(:text => '', :name => file_name, :extension => '.file', :directory => directory_path)
54
- end
55
- end
56
-
57
-
58
- it 'models the feature files contained in the directory' do
59
- modeled_files = directory_model.feature_files.collect { |file| file.name[/test_file_\d/] }
60
-
61
- expect(modeled_files).to match_array(feature_files)
62
- end
63
-
64
- it 'does not model non-feature files contained in the directory' do
65
- modeled_files = directory_model.feature_files.collect { |file| file.name[/test_file_\d/] }
66
-
67
- non_feature_files.all? do |file|
68
- expect(modeled_files).to_not include(file)
69
- end
70
- end
71
-
72
- end
73
-
74
-
75
- context 'with no feature files' do
76
-
77
- let(:directory_path) { CukeModeler::FileHelper.create_directory(:name => 'empty_directory', :directory => root_test_path) }
78
- let(:directory_model) { clazz.new(directory_path) }
79
-
80
-
81
- it 'models the feature files contained in the directory' do
82
- modeled_files = directory_model.feature_files.collect { |file| file.name }
83
-
84
- expect(modeled_files).to eq([])
85
- end
86
-
87
- end
88
-
89
-
90
- context 'with a nested directory' do
91
-
92
- let(:directory_path) { CukeModeler::FileHelper.create_directory(:name => 'test_directory', :directory => root_test_path) }
93
- let(:directory_model) { clazz.new(directory_path) }
94
-
95
- let(:nested_directories) { ['nested_directory_1', 'nested_directory_2'] }
96
-
97
- before(:each) do
98
- nested_directories.each do |nested_directory|
99
- CukeModeler::FileHelper.create_directory(:name => nested_directory, :directory => directory_path)
100
- end
101
- end
102
-
103
-
104
- it 'models the directories in the directory' do
105
- modeled_directories = directory_model.directories.collect { |nested_directory| nested_directory.name[/nested_directory_\d/] }
106
-
107
- expect(modeled_directories).to match_array(nested_directories)
108
- end
109
-
110
- end
111
-
112
-
113
- context 'with no directories' do
114
-
115
- let(:directory_path) { CukeModeler::FileHelper.create_directory(:name => 'empty_directory', :directory => root_test_path) }
116
- let(:directory_model) { clazz.new(directory_path) }
117
-
118
-
119
- it 'models the directories contained in the directory' do
120
- modeled_directories = directory_model.directories.collect { |nested_directory| nested_directory.name }
121
-
122
- expect(modeled_directories).to eq([])
123
- end
124
-
125
- end
126
-
127
- end
128
-
129
-
130
- context 'with a non-existing directory' do
131
-
132
- let(:root_test_path) { CukeModeler::FileHelper.create_directory }
133
- let(:directory_path) { "#{root_test_path}/this_directory_should_not_exist" }
134
-
135
-
136
- it 'cannot model a non-existent directory' do
137
- expect { clazz.new(directory_path) }.to raise_error(ArgumentError)
138
- end
139
-
140
- end
141
-
142
- end
143
-
144
-
145
- it 'properly sets its child models' do
146
- directory_path = CukeModeler::FileHelper.create_directory
147
- _nested_directory_path = CukeModeler::FileHelper.create_directory(:name => 'nested_directory', :directory => directory_path)
148
-
149
- CukeModeler::FileHelper.create_feature_file(:text => "#{FEATURE_KEYWORD}: Test feature", :name => 'test_file', :directory => directory_path)
150
-
151
-
152
- directory_model = clazz.new(directory_path)
153
- nested_directory_model = directory_model.directories.first
154
- file_model = directory_model.feature_files.first
155
-
156
- expect(nested_directory_model.parent_model).to equal(directory_model)
157
- expect(file_model.parent_model).to equal(directory_model)
158
- end
159
-
160
-
161
- describe 'getting ancestors' do
162
-
163
- before(:each) do
164
- CukeModeler::FileHelper.create_directory(:name => 'nested_directory', :directory => test_directory)
165
- end
166
-
167
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
168
-
169
- let(:directory_model) { clazz.new(test_directory) }
170
- let(:nested_directory_model) { directory_model.directories.first }
171
-
172
-
173
- it 'can get its directory' do
174
- ancestor = nested_directory_model.get_ancestor(:directory)
175
-
176
- expect(ancestor).to equal(directory_model)
177
- end
178
-
179
- it 'returns nil if it does not have the requested type of ancestor' do
180
- ancestor = nested_directory_model.get_ancestor(:example)
181
-
182
- expect(ancestor).to be_nil
183
- end
184
-
185
- end
186
-
187
-
188
- describe 'directory output' do
189
-
190
- context 'from source text' do
191
-
192
- let(:directory_path) { CukeModeler::FileHelper.create_directory }
193
- let(:directory_model) { clazz.new(directory_path) }
194
-
195
-
196
- it 'can output a directory' do
197
- directory_output = directory_model.to_s
198
-
199
- expect(directory_output).to eq(directory_path)
200
- end
201
-
202
- end
203
-
204
- it 'can be remade from its own output' do
205
- source = CukeModeler::FileHelper.create_directory
206
- directory = clazz.new(source)
207
-
208
- directory_output = directory.to_s
209
- remade_directory_output = clazz.new(directory_output).to_s
210
-
211
- expect(remade_directory_output).to eq(directory_output)
212
- end
213
-
214
- end
215
-
216
- end
217
-
218
- end
@@ -1,398 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../spec_helper"
2
-
3
-
4
- describe 'DocString, Integration' do
5
-
6
- let(:clazz) { CukeModeler::DocString }
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 = "\"\"\"\n\"\"\""
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 = "\"\"\"\ntext foo\n\"\"\""
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.content).to eq('text foo')
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 doc string text'
42
-
43
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_doc_string\.feature'/)
44
- end
45
-
46
- describe 'parsing data' do
47
-
48
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(6, 7, 8, 9) do
49
- doc_string = clazz.new("\"\"\" content type\nsome doc string\n\"\"\"")
50
- data = doc_string.parsing_data
51
-
52
- expect(data.keys).to match_array([:location, :content, :content_type, :delimiter])
53
- expect(data[:content]).to eq('some doc string')
54
- end
55
-
56
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(3, 4, 5) do
57
- doc_string = clazz.new("\"\"\" content type\nsome doc string\n\"\"\"")
58
- data = doc_string.parsing_data
59
-
60
- expect(data.keys).to match_array([:type, :location, :content, :contentType])
61
- expect(data[:type]).to eq(:DocString)
62
- end
63
-
64
- it 'stores the original data generated by the parsing adapter', :if => gherkin?(2) do
65
- doc_string = clazz.new("\"\"\" content type\nsome doc string\n\"\"\"")
66
- data = doc_string.parsing_data
67
-
68
- expect(data.keys).to match_array(['value', 'content_type', 'line'])
69
- expect(data['value']).to eq('some doc string')
70
- end
71
-
72
- end
73
-
74
- it 'stores its content as a String' do
75
- source = "\"\"\"\nsome text\nsome more text\n\"\"\""
76
- doc_string = clazz.new(source)
77
-
78
- content = doc_string.content
79
-
80
- expect(content).to be_a(String)
81
- end
82
-
83
-
84
- describe 'getting ancestors' do
85
-
86
- before(:each) do
87
- CukeModeler::FileHelper.create_feature_file(:text => source_gherkin, :name => 'doc_string_test_file', :directory => test_directory)
88
- end
89
-
90
-
91
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
92
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
93
-
94
- #{SCENARIO_KEYWORD}: Test test
95
- #{STEP_KEYWORD} a big step:
96
- \"\"\"
97
- a
98
- doc
99
- string
100
- \"\"\""
101
- }
102
-
103
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
104
- let(:doc_string_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block }
105
-
106
-
107
- it 'can get its directory' do
108
- ancestor = doc_string_model.get_ancestor(:directory)
109
-
110
- expect(ancestor).to equal(directory_model)
111
- end
112
-
113
- it 'can get its feature file' do
114
- ancestor = doc_string_model.get_ancestor(:feature_file)
115
-
116
- expect(ancestor).to equal(directory_model.feature_files.first)
117
- end
118
-
119
- it 'can get its feature' do
120
- ancestor = doc_string_model.get_ancestor(:feature)
121
-
122
- expect(ancestor).to equal(directory_model.feature_files.first.feature)
123
- end
124
-
125
- context 'a doc string that is part of a scenario' do
126
-
127
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
128
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
129
-
130
- #{SCENARIO_KEYWORD}: Test test
131
- #{STEP_KEYWORD} a big step:
132
- \"\"\"
133
- a
134
- doc
135
- string
136
- \"\"\""
137
- }
138
-
139
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
140
- let(:doc_string_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block }
141
-
142
-
143
- it 'can get its scenario' do
144
- ancestor = doc_string_model.get_ancestor(:scenario)
145
-
146
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
147
- end
148
-
149
- end
150
-
151
- context 'a doc string that is part of an outline' do
152
-
153
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
154
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
155
-
156
- #{OUTLINE_KEYWORD}: Test outline
157
- #{STEP_KEYWORD} a big step:
158
- \"\"\"
159
- a
160
- doc
161
- string
162
- \"\"\"
163
- #{EXAMPLE_KEYWORD}:
164
- | param |
165
- | value |"
166
- }
167
-
168
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
169
- let(:doc_string_model) { directory_model.feature_files.first.feature.tests.first.steps.first.block }
170
-
171
-
172
- it 'can get its outline' do
173
- ancestor = doc_string_model.get_ancestor(:outline)
174
-
175
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first)
176
- end
177
-
178
- end
179
-
180
- context 'a doc string that is part of a background' do
181
-
182
- let(:test_directory) { CukeModeler::FileHelper.create_directory }
183
- let(:source_gherkin) { "#{FEATURE_KEYWORD}: Test feature
184
-
185
- #{BACKGROUND_KEYWORD}: Test background
186
- #{STEP_KEYWORD} a big step:
187
- \"\"\"
188
- a
189
- doc
190
- string
191
- \"\"\""
192
- }
193
-
194
- let(:directory_model) { CukeModeler::Directory.new(test_directory) }
195
- let(:doc_string_model) { directory_model.feature_files.first.feature.background.steps.first.block }
196
-
197
-
198
- it 'can get its background' do
199
- ancestor = doc_string_model.get_ancestor(:background)
200
-
201
- expect(ancestor).to equal(directory_model.feature_files.first.feature.background)
202
- end
203
-
204
- end
205
-
206
- it 'can get its step' do
207
- ancestor = doc_string_model.get_ancestor(:step)
208
-
209
- expect(ancestor).to equal(directory_model.feature_files.first.feature.tests.first.steps.first)
210
- end
211
-
212
- it 'returns nil if it does not have the requested type of ancestor' do
213
- ancestor = doc_string_model.get_ancestor(:example)
214
-
215
- expect(ancestor).to be_nil
216
- end
217
-
218
- end
219
-
220
-
221
- describe 'model population' do
222
-
223
- context 'from source text' do
224
-
225
- context 'a filled doc string' do
226
-
227
- let(:source_text) { ['""" type foo',
228
- 'bar',
229
- '"""'].join("\n") }
230
- let(:doc_string) { clazz.new(source_text) }
231
-
232
-
233
- it "models the doc string's content type" do
234
- expect(doc_string.content_type).to eq('type foo')
235
- end
236
-
237
- it "models the doc_string's content" do
238
- expect(doc_string.content).to eq('bar')
239
- end
240
-
241
- end
242
-
243
- context 'an empty doc_string' do
244
-
245
- let(:source_text) { '"""
246
- """' }
247
- let(:doc_string) { clazz.new(source_text) }
248
-
249
- it "models the doc_string's content type" do
250
- expect(doc_string.content_type).to be_nil
251
- end
252
-
253
- it "models the doc_string's content" do
254
- expect(doc_string.content).to eq('')
255
- end
256
-
257
- end
258
-
259
- it "models the doc string's source line" do
260
- source_text = "#{FEATURE_KEYWORD}:
261
-
262
- #{SCENARIO_KEYWORD}:
263
- #{STEP_KEYWORD} step
264
- \"\"\"
265
- foo
266
- \"\"\""
267
- doc_string = CukeModeler::Feature.new(source_text).tests.first.steps.first.block
268
-
269
- expect(doc_string.source_line).to eq(5)
270
- end
271
-
272
- end
273
-
274
- end
275
-
276
-
277
- describe 'doc string output' do
278
-
279
- it 'can be remade from its own output' do
280
- source = ['"""" the type',
281
- "#{STEP_KEYWORD} a step",
282
- ' \"\"\"',
283
- ' that also has a doc string',
284
- ' \"\"\"',
285
- '"""']
286
- source = source.join("\n")
287
- doc_string = clazz.new(source)
288
-
289
- doc_string_output = doc_string.to_s
290
- remade_doc_string_output = clazz.new(doc_string_output).to_s
291
-
292
- expect(remade_doc_string_output).to eq(doc_string_output)
293
- end
294
-
295
-
296
- context 'from source text' do
297
-
298
- it 'can output an empty doc string' do
299
- source = ['"""',
300
- '"""']
301
- source = source.join("\n")
302
- doc_string = clazz.new(source)
303
-
304
- doc_string_output = doc_string.to_s.split("\n", -1)
305
-
306
- expect(doc_string_output).to eq(['"""', '"""'])
307
- end
308
-
309
- it 'can output a doc string that has a content type' do
310
- source = ['""" foo',
311
- '"""']
312
- source = source.join("\n")
313
- doc_string = clazz.new(source)
314
-
315
- doc_string_output = doc_string.to_s.split("\n", -1)
316
-
317
- expect(doc_string_output).to eq(['""" foo',
318
- '"""'])
319
- end
320
-
321
- it 'can output a doc_string that has contents' do
322
- source = ['"""',
323
- 'foo',
324
- '"""']
325
- source = source.join("\n")
326
- doc_string = clazz.new(source)
327
-
328
- doc_string_output = doc_string.to_s.split("\n", -1)
329
-
330
- expect(doc_string_output).to eq(['"""',
331
- 'foo',
332
- '"""'])
333
- end
334
-
335
- # Since triple double quotes mark the beginning and end of a doc string, any triple
336
- # double quotes inside of the doc string (which would have had to have been escaped
337
- # to get inside in the first place) will be escaped when outputted so as to
338
- # retain the quality of being able to use the output directly as gherkin.
339
-
340
- it 'can output a doc_string that has triple double quotes in the contents' do
341
- source = ['"""',
342
- 'a \"\"\"',
343
- '\"\"\" again',
344
- '"""']
345
- source = source.join("\n")
346
- doc_string = clazz.new(source)
347
-
348
- doc_string_output = doc_string.to_s.split("\n", -1)
349
-
350
- expect(doc_string_output).to eq(['"""',
351
- 'a \"\"\"',
352
- '\"\"\" again',
353
- '"""'])
354
- end
355
-
356
- # Double quotes that are not three (or more) in a row do not seem to need and special escaping when
357
- # used in Gherkin. Therefore they should be left alone.
358
- it 'only escapes triple double quotes' do
359
- source = ['"""',
360
- 'change these \"\"\"\"\"\"',
361
- 'but leave " and "" alone',
362
- '"""']
363
- source = source.join("\n")
364
- doc_string = clazz.new(source)
365
-
366
- doc_string_output = doc_string.to_s.split("\n", -1)
367
-
368
- expect(doc_string_output).to eq(['"""',
369
- 'change these \"\"\"\"\"\"',
370
- 'but leave " and "" alone',
371
- '"""'])
372
- end
373
-
374
- it 'can output a doc string that has everything' do
375
- source = ['""" type foo',
376
- '\"\"\"',
377
- 'bar',
378
- '\"\"\"',
379
- '"""']
380
- source = source.join("\n")
381
- doc_string = clazz.new(source)
382
-
383
- doc_string_output = doc_string.to_s.split("\n", -1)
384
-
385
- expect(doc_string_output).to eq(['""" type foo',
386
- '\"\"\"',
387
- 'bar',
388
- '\"\"\"',
389
- '"""'])
390
- end
391
-
392
- end
393
-
394
- end
395
-
396
- end
397
-
398
- end