cuke_modeler 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/.travis.yml +1 -1
  4. data/Gemfile +4 -0
  5. data/History.rdoc +71 -3
  6. data/LICENSE.txt +22 -22
  7. data/README.md +24 -10
  8. data/Rakefile +2 -12
  9. data/cuke_modeler.gemspec +1 -1
  10. data/features/analysis/test_comparison.feature +37 -122
  11. data/features/modeling/background_modeling.feature +77 -0
  12. data/features/modeling/background_output.feature +42 -0
  13. data/features/modeling/cell_modeling.feature +23 -0
  14. data/features/modeling/cell_output.feature +22 -0
  15. data/features/modeling/directory_modeling.feature +65 -0
  16. data/features/modeling/directory_output.feature +12 -0
  17. data/features/modeling/doc_string_modeling.feature +61 -0
  18. data/features/modeling/doc_string_output.feature +32 -0
  19. data/features/modeling/example_modeling.feature +125 -0
  20. data/features/modeling/example_output.feature +39 -0
  21. data/features/modeling/feature_file_modeling.feature +40 -0
  22. data/features/modeling/feature_file_output.feature +12 -0
  23. data/features/modeling/feature_modeling.feature +109 -0
  24. data/features/modeling/feature_output.feature +104 -0
  25. data/features/modeling/model_output.feature +22 -0
  26. data/features/modeling/model_structure.feature +48 -0
  27. data/features/modeling/outline_modeling.feature +144 -0
  28. data/features/modeling/outline_output.feature +69 -0
  29. data/features/modeling/row_modeling.feature +48 -0
  30. data/features/modeling/row_output.feature +22 -0
  31. data/features/modeling/scenario_modeling.feature +118 -0
  32. data/features/modeling/scenario_output.feature +45 -0
  33. data/features/modeling/step_modeling.feature +84 -0
  34. data/features/modeling/step_output.feature +29 -0
  35. data/features/modeling/table_modeling.feature +50 -0
  36. data/features/modeling/table_output.feature +24 -0
  37. data/features/modeling/tag_modeling.feature +43 -0
  38. data/features/modeling/tag_output.feature +22 -0
  39. data/features/step_definitions/action_steps.rb +11 -1
  40. data/features/step_definitions/background_steps.rb +1 -85
  41. data/features/step_definitions/directory_steps.rb +2 -48
  42. data/features/step_definitions/doc_string_steps.rb +1 -67
  43. data/features/step_definitions/feature_file_steps.rb +2 -37
  44. data/features/step_definitions/feature_steps.rb +4 -100
  45. data/features/step_definitions/modeling_steps.rb +44 -0
  46. data/features/step_definitions/setup_steps.rb +19 -41
  47. data/features/step_definitions/step_steps.rb +2 -166
  48. data/features/step_definitions/table_steps.rb +1 -58
  49. data/features/step_definitions/tag_steps.rb +2 -72
  50. data/features/step_definitions/verification_steps.rb +152 -4
  51. data/features/support/env.rb +4 -6
  52. data/gemfiles/{gherkin.gemfile → gherkin2.gemfile} +4 -0
  53. data/gemfiles/gherkin3.gemfile +4 -0
  54. data/gemfiles/gherkin4.gemfile +4 -0
  55. data/lib/cuke_modeler.rb +24 -22
  56. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +103 -31
  57. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +103 -40
  58. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +111 -50
  59. data/lib/cuke_modeler/containing.rb +255 -4
  60. data/lib/cuke_modeler/described.rb +28 -0
  61. data/lib/cuke_modeler/models/background.rb +66 -0
  62. data/lib/cuke_modeler/models/cell.rb +48 -0
  63. data/lib/cuke_modeler/models/directory.rb +95 -0
  64. data/lib/cuke_modeler/models/doc_string.rb +59 -0
  65. data/lib/cuke_modeler/models/example.rb +167 -0
  66. data/lib/cuke_modeler/models/feature.rb +106 -0
  67. data/lib/cuke_modeler/models/feature_file.rb +64 -0
  68. data/lib/cuke_modeler/models/model.rb +32 -0
  69. data/lib/cuke_modeler/models/outline.rb +79 -0
  70. data/lib/cuke_modeler/models/row.rb +49 -0
  71. data/lib/cuke_modeler/models/scenario.rb +69 -0
  72. data/lib/cuke_modeler/models/step.rb +68 -0
  73. data/lib/cuke_modeler/models/table.rb +67 -0
  74. data/lib/cuke_modeler/models/tag.rb +46 -0
  75. data/lib/cuke_modeler/named.rb +19 -0
  76. data/lib/cuke_modeler/nested.rb +22 -15
  77. data/lib/cuke_modeler/parsed.rb +11 -0
  78. data/lib/cuke_modeler/parsing.rb +66 -83
  79. data/lib/cuke_modeler/sourceable.rb +3 -11
  80. data/lib/cuke_modeler/stepped.rb +24 -0
  81. data/lib/cuke_modeler/taggable.rb +6 -29
  82. data/lib/cuke_modeler/version.rb +2 -1
  83. data/spec/integration/background_integration_spec.rb +332 -7
  84. data/spec/integration/cell_integration_spec.rb +321 -0
  85. data/spec/integration/directory_integration_spec.rb +175 -9
  86. data/spec/integration/doc_string_integration_spec.rb +318 -7
  87. data/spec/integration/example_integration_spec.rb +602 -19
  88. data/spec/integration/feature_file_integration_spec.rb +98 -3
  89. data/spec/integration/feature_integration_spec.rb +445 -27
  90. data/spec/integration/gherkin_2_adapter_spec.rb +122 -0
  91. data/spec/integration/gherkin_3_adapter_spec.rb +125 -0
  92. data/spec/integration/gherkin_4_adapter_spec.rb +123 -0
  93. data/spec/integration/model_integration_spec.rb +15 -0
  94. data/spec/integration/nested_integration_spec.rb +91 -0
  95. data/spec/integration/outline_integration_spec.rb +485 -12
  96. data/spec/integration/parsing_integration_spec.rb +85 -0
  97. data/spec/integration/row_integration_spec.rb +221 -18
  98. data/spec/integration/scenario_integration_spec.rb +368 -14
  99. data/spec/integration/shared/models_integration_specs.rb +18 -0
  100. data/spec/integration/step_integration_spec.rb +328 -77
  101. data/spec/integration/table_integration_spec.rb +242 -20
  102. data/spec/integration/tag_integration_spec.rb +178 -13
  103. data/spec/spec_helper.rb +32 -18
  104. data/spec/unit/background_unit_spec.rb +24 -44
  105. data/spec/unit/cell_unit_spec.rb +73 -0
  106. data/spec/unit/described_unit_spec.rb +23 -0
  107. data/spec/unit/directory_unit_spec.rb +52 -62
  108. data/spec/unit/doc_string_unit_spec.rb +47 -100
  109. data/spec/unit/example_unit_spec.rb +50 -296
  110. data/spec/unit/feature_file_unit_spec.rb +53 -52
  111. data/spec/unit/feature_unit_spec.rb +39 -83
  112. data/spec/unit/model_unit_spec.rb +15 -0
  113. data/spec/unit/named_unit_spec.rb +23 -0
  114. data/spec/unit/nested_unit_spec.rb +24 -21
  115. data/spec/unit/outline_unit_spec.rb +46 -69
  116. data/spec/unit/parsed_unit_spec.rb +27 -0
  117. data/spec/unit/parsing_unit_spec.rb +2 -70
  118. data/spec/unit/row_unit_spec.rb +22 -51
  119. data/spec/unit/scenario_unit_spec.rb +27 -59
  120. data/spec/unit/{bare_bones_unit_specs.rb → shared/bare_bones_models_unit_specs.rb} +2 -2
  121. data/spec/unit/shared/containing_models_unit_specs.rb +18 -0
  122. data/spec/unit/shared/described_models_unit_specs.rb +38 -0
  123. data/spec/unit/shared/models_unit_specs.rb +15 -0
  124. data/spec/unit/shared/named_models_unit_specs.rb +39 -0
  125. data/spec/unit/shared/nested_models_unit_specs.rb +51 -0
  126. data/spec/unit/shared/parsed_models_unit_specs.rb +39 -0
  127. data/spec/unit/shared/prepopulated_models_unit_specs.rb +18 -0
  128. data/spec/unit/shared/sourced_models_unit_specs.rb +39 -0
  129. data/spec/unit/shared/stepped_models_unit_specs.rb +46 -0
  130. data/spec/unit/shared/stringifiable_models_unit_specs.rb +18 -0
  131. data/spec/unit/shared/tagged_models_unit_specs.rb +72 -0
  132. data/spec/unit/sourceable_unit_spec.rb +12 -4
  133. data/spec/unit/step_unit_spec.rb +40 -231
  134. data/spec/unit/stepped_unit_spec.rb +23 -0
  135. data/spec/unit/table_unit_spec.rb +27 -89
  136. data/spec/unit/tag_unit_spec.rb +30 -53
  137. data/spec/unit/taggable_unit_spec.rb +26 -42
  138. data/todo.txt +32 -0
  139. metadata +135 -217
  140. data/features/analysis/test_manipulation.feature +0 -37
  141. data/features/modeling/gherkin/background_modeling.feature +0 -65
  142. data/features/modeling/gherkin/background_output.feature +0 -131
  143. data/features/modeling/gherkin/directory_modeling.feature +0 -110
  144. data/features/modeling/gherkin/directory_output.feature +0 -14
  145. data/features/modeling/gherkin/doc_string_modeling.feature +0 -53
  146. data/features/modeling/gherkin/doc_string_output.feature +0 -72
  147. data/features/modeling/gherkin/example_modeling.feature +0 -101
  148. data/features/modeling/gherkin/example_output.feature +0 -193
  149. data/features/modeling/gherkin/feature_file_modeling.feature +0 -54
  150. data/features/modeling/gherkin/feature_file_output.feature +0 -14
  151. data/features/modeling/gherkin/feature_modeling.feature +0 -154
  152. data/features/modeling/gherkin/feature_output.feature +0 -245
  153. data/features/modeling/gherkin/outline_modeling.feature +0 -90
  154. data/features/modeling/gherkin/outline_output.feature +0 -198
  155. data/features/modeling/gherkin/row_modeling.feature +0 -68
  156. data/features/modeling/gherkin/row_output.feature +0 -28
  157. data/features/modeling/gherkin/scenario_modeling.feature +0 -79
  158. data/features/modeling/gherkin/scenario_output.feature +0 -148
  159. data/features/modeling/gherkin/step_modeling.feature +0 -75
  160. data/features/modeling/gherkin/step_output.feature +0 -53
  161. data/features/modeling/gherkin/table_modeling.feature +0 -42
  162. data/features/modeling/gherkin/table_output.feature +0 -43
  163. data/features/modeling/gherkin/table_row_modeling.feature +0 -57
  164. data/features/modeling/gherkin/table_row_output.feature +0 -28
  165. data/features/modeling/gherkin/tag_modeling.feature +0 -48
  166. data/features/modeling/gherkin/tag_output.feature +0 -17
  167. data/features/modeling/gherkin3/background_modeling.feature +0 -64
  168. data/features/modeling/gherkin3/background_output.feature +0 -131
  169. data/features/modeling/gherkin3/directory_modeling.feature +0 -110
  170. data/features/modeling/gherkin3/directory_output.feature +0 -14
  171. data/features/modeling/gherkin3/doc_string_modeling.feature +0 -53
  172. data/features/modeling/gherkin3/doc_string_output.feature +0 -72
  173. data/features/modeling/gherkin3/example_modeling.feature +0 -100
  174. data/features/modeling/gherkin3/example_output.feature +0 -207
  175. data/features/modeling/gherkin3/feature_file_modeling.feature +0 -54
  176. data/features/modeling/gherkin3/feature_file_output.feature +0 -14
  177. data/features/modeling/gherkin3/feature_modeling.feature +0 -155
  178. data/features/modeling/gherkin3/feature_output.feature +0 -249
  179. data/features/modeling/gherkin3/outline_modeling.feature +0 -89
  180. data/features/modeling/gherkin3/outline_output.feature +0 -255
  181. data/features/modeling/gherkin3/row_modeling.feature +0 -68
  182. data/features/modeling/gherkin3/row_output.feature +0 -28
  183. data/features/modeling/gherkin3/scenario_modeling.feature +0 -78
  184. data/features/modeling/gherkin3/scenario_output.feature +0 -148
  185. data/features/modeling/gherkin3/step_modeling.feature +0 -75
  186. data/features/modeling/gherkin3/step_output.feature +0 -53
  187. data/features/modeling/gherkin3/table_modeling.feature +0 -42
  188. data/features/modeling/gherkin3/table_output.feature +0 -43
  189. data/features/modeling/gherkin3/table_row_modeling.feature +0 -57
  190. data/features/modeling/gherkin3/table_row_output.feature +0 -28
  191. data/features/modeling/gherkin3/tag_modeling.feature +0 -49
  192. data/features/modeling/gherkin3/tag_output.feature +0 -17
  193. data/features/modeling/gherkin4/background_modeling.feature +0 -64
  194. data/features/modeling/gherkin4/background_output.feature +0 -131
  195. data/features/modeling/gherkin4/directory_modeling.feature +0 -110
  196. data/features/modeling/gherkin4/directory_output.feature +0 -14
  197. data/features/modeling/gherkin4/doc_string_modeling.feature +0 -53
  198. data/features/modeling/gherkin4/doc_string_output.feature +0 -72
  199. data/features/modeling/gherkin4/example_modeling.feature +0 -100
  200. data/features/modeling/gherkin4/example_output.feature +0 -193
  201. data/features/modeling/gherkin4/feature_file_modeling.feature +0 -54
  202. data/features/modeling/gherkin4/feature_file_output.feature +0 -14
  203. data/features/modeling/gherkin4/feature_modeling.feature +0 -153
  204. data/features/modeling/gherkin4/feature_output.feature +0 -245
  205. data/features/modeling/gherkin4/outline_modeling.feature +0 -89
  206. data/features/modeling/gherkin4/outline_output.feature +0 -198
  207. data/features/modeling/gherkin4/row_modeling.feature +0 -68
  208. data/features/modeling/gherkin4/row_output.feature +0 -28
  209. data/features/modeling/gherkin4/scenario_modeling.feature +0 -78
  210. data/features/modeling/gherkin4/scenario_output.feature +0 -148
  211. data/features/modeling/gherkin4/step_modeling.feature +0 -75
  212. data/features/modeling/gherkin4/step_output.feature +0 -53
  213. data/features/modeling/gherkin4/table_modeling.feature +0 -42
  214. data/features/modeling/gherkin4/table_output.feature +0 -43
  215. data/features/modeling/gherkin4/table_row_modeling.feature +0 -57
  216. data/features/modeling/gherkin4/table_row_output.feature +0 -28
  217. data/features/modeling/gherkin4/tag_modeling.feature +0 -48
  218. data/features/modeling/gherkin4/tag_output.feature +0 -17
  219. data/features/step_definitions/outline_steps.rb +0 -258
  220. data/features/step_definitions/test_steps.rb +0 -123
  221. data/lib/cuke_modeler/background.rb +0 -38
  222. data/lib/cuke_modeler/directory.rb +0 -83
  223. data/lib/cuke_modeler/doc_string.rb +0 -87
  224. data/lib/cuke_modeler/example.rb +0 -195
  225. data/lib/cuke_modeler/feature.rb +0 -147
  226. data/lib/cuke_modeler/feature_element.rb +0 -73
  227. data/lib/cuke_modeler/feature_file.rb +0 -77
  228. data/lib/cuke_modeler/outline.rb +0 -68
  229. data/lib/cuke_modeler/raw.rb +0 -20
  230. data/lib/cuke_modeler/row.rb +0 -64
  231. data/lib/cuke_modeler/scenario.rb +0 -45
  232. data/lib/cuke_modeler/step.rb +0 -216
  233. data/lib/cuke_modeler/table.rb +0 -90
  234. data/lib/cuke_modeler/table_row.rb +0 -64
  235. data/lib/cuke_modeler/tag.rb +0 -62
  236. data/lib/cuke_modeler/test_element.rb +0 -79
  237. data/lib/cuke_modeler/world.rb +0 -113
  238. data/spec/integration/table_row_integration_spec.rb +0 -76
  239. data/spec/integration/world_integration_spec.rb +0 -14
  240. data/spec/unit/containing_element_unit_specs.rb +0 -18
  241. data/spec/unit/feature_element_unit_spec.rb +0 -19
  242. data/spec/unit/feature_element_unit_specs.rb +0 -52
  243. data/spec/unit/nested_element_unit_specs.rb +0 -39
  244. data/spec/unit/prepopulated_unit_specs.rb +0 -14
  245. data/spec/unit/raw_element_unit_specs.rb +0 -27
  246. data/spec/unit/raw_unit_spec.rb +0 -28
  247. data/spec/unit/sourced_element_unit_specs.rb +0 -18
  248. data/spec/unit/table_row_unit_spec.rb +0 -102
  249. data/spec/unit/tagged_element_unit_specs.rb +0 -67
  250. data/spec/unit/test_element_unit_spec.rb +0 -54
  251. data/spec/unit/test_element_unit_specs.rb +0 -34
  252. data/spec/unit/world_unit_spec.rb +0 -140
@@ -1,3 +1,4 @@
1
1
  module CukeModeler
2
- VERSION = "0.4.1"
2
+ # The gem version
3
+ VERSION = "1.0.0"
3
4
  end
@@ -1,15 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
- SimpleCov.command_name('Background') unless RUBY_VERSION.to_s < '1.9.0'
4
3
 
5
4
  describe 'Background, Integration' do
6
5
 
7
6
  let(:clazz) { CukeModeler::Background }
8
7
 
9
8
 
9
+ describe 'common behavior' do
10
+
11
+ it_should_behave_like 'a model, integration'
12
+
13
+ end
14
+
10
15
  describe 'unique behavior' do
11
16
 
12
- it 'properly sets its child elements' do
17
+ it 'can be instantiated with the minimum viable Gherkin' do
18
+ source = 'Background:'
19
+
20
+ expect { clazz.new(source) }.to_not raise_error
21
+ end
22
+
23
+ it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
24
+ background = clazz.new("Background: test background\ndescription\n* a step")
25
+ data = background.parsing_data
26
+
27
+ expect(data.keys).to match_array([:type, :location, :keyword, :name, :steps, :description])
28
+ expect(data[:type]).to eq(:Background)
29
+ end
30
+
31
+ it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
32
+ background = clazz.new("Background: test background\ndescription\n* a step")
33
+ data = background.parsing_data
34
+
35
+ expect(data.keys).to match_array([:type, :location, :keyword, :name, :steps, :description])
36
+ expect(data[:type]).to eq(:Background)
37
+ end
38
+
39
+ it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
40
+ background = clazz.new("Background: test background\ndescription\n* a step")
41
+ data = background.parsing_data
42
+
43
+ expect(data.keys).to match_array(['keyword', 'name', 'line', 'description', 'steps', 'type'])
44
+ expect(data['keyword']).to eq('Background')
45
+ end
46
+
47
+ it 'provides a descriptive filename when being parsed from stand alone text' do
48
+ source = "bad background text \n Background:\n And a step\n @foo "
49
+
50
+ expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_background\.feature'/)
51
+ end
52
+
53
+ it 'properly sets its child models' do
13
54
  source = [' Background: Test background',
14
55
  ' * a step']
15
56
  source = source.join("\n")
@@ -17,9 +58,32 @@ describe 'Background, Integration' do
17
58
  background = clazz.new(source)
18
59
  step = background.steps.first
19
60
 
20
- expect(step.parent_element).to equal(background)
61
+ expect(step.parent_model).to equal(background)
21
62
  end
22
63
 
64
+ it 'trims whitespace from its source description' do
65
+ source = ['Background:',
66
+ ' ',
67
+ ' description line 1',
68
+ '',
69
+ ' description line 2',
70
+ ' description line 3 ',
71
+ '',
72
+ '',
73
+ '',
74
+ ' * a step']
75
+ source = source.join("\n")
76
+
77
+ background = clazz.new(source)
78
+ description = background.description.split("\n")
79
+
80
+ expect(description).to eq([' description line 1',
81
+ '',
82
+ 'description line 2',
83
+ ' description line 3'])
84
+ end
85
+
86
+
23
87
  describe 'getting ancestors' do
24
88
 
25
89
  before(:each) do
@@ -34,7 +98,7 @@ describe 'Background, Integration' do
34
98
  end
35
99
 
36
100
  let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
37
- let(:background) { directory.feature_files.first.features.first.background }
101
+ let(:background) { directory.feature_files.first.feature.background }
38
102
 
39
103
 
40
104
  it 'can get its directory' do
@@ -52,7 +116,7 @@ describe 'Background, Integration' do
52
116
  it 'can get its feature' do
53
117
  ancestor = background.get_ancestor(:feature)
54
118
 
55
- expect(ancestor).to equal(directory.feature_files.first.features.first)
119
+ expect(ancestor).to equal(directory.feature_files.first.feature)
56
120
  end
57
121
 
58
122
  it 'returns nil if it does not have the requested type of ancestor' do
@@ -63,9 +127,270 @@ describe 'Background, Integration' do
63
127
 
64
128
  end
65
129
 
66
- describe 'background output edge cases' do
67
130
 
68
- context 'a new background object' do
131
+ describe 'model population' do
132
+
133
+ context 'from source text' do
134
+
135
+ it "models the background's source line" do
136
+ source_text = "Feature:
137
+
138
+ Background: foo
139
+ * step"
140
+ background = CukeModeler::Feature.new(source_text).background
141
+
142
+ expect(background.source_line).to eq(3)
143
+ end
144
+
145
+ context 'a filled background' do
146
+
147
+ let(:source_text) { "Background: Background name
148
+
149
+ Background description.
150
+
151
+ Some more.
152
+ Even more.
153
+
154
+ * a step
155
+ * another step" }
156
+ let(:background) { clazz.new(source_text) }
157
+
158
+
159
+ it "models the background's name" do
160
+ expect(background.name).to eq('Background name')
161
+ end
162
+
163
+ it "models the background's description" do
164
+ description = background.description.split("\n")
165
+
166
+ expect(description).to eq([' Background description.',
167
+ '',
168
+ 'Some more.',
169
+ ' Even more.'])
170
+ end
171
+
172
+ it "models the background's steps" do
173
+ step_names = background.steps.collect { |step| step.text }
174
+
175
+ expect(step_names).to eq(['a step', 'another step'])
176
+ end
177
+
178
+ end
179
+
180
+ context 'an empty background' do
181
+
182
+ let(:source_text) { 'Background:' }
183
+ let(:background) { clazz.new(source_text) }
184
+
185
+
186
+ it "models the background's name" do
187
+ expect(background.name).to eq('')
188
+ end
189
+
190
+ it "models the background's description" do
191
+ expect(background.description).to eq('')
192
+ end
193
+
194
+ it "models the background's steps" do
195
+ expect(background.steps).to eq([])
196
+ end
197
+
198
+ end
199
+
200
+ end
201
+
202
+ end
203
+
204
+
205
+ describe 'comparison' do
206
+
207
+ it 'is equal to a background with the same steps' do
208
+ source = "Background:
209
+ * step 1
210
+ * step 2"
211
+ background_1 = clazz.new(source)
212
+
213
+ source = "Background:
214
+ * step 1
215
+ * step 2"
216
+ background_2 = clazz.new(source)
217
+
218
+ source = "Background:
219
+ * step 2
220
+ * step 1"
221
+ background_3 = clazz.new(source)
222
+
223
+
224
+ expect(background_1).to eq(background_2)
225
+ expect(background_1).to_not eq(background_3)
226
+ end
227
+
228
+ it 'is equal to a scenario with the same steps' do
229
+ source = "Background:
230
+ * step 1
231
+ * step 2"
232
+ background = clazz.new(source)
233
+
234
+ source = "Scenario:
235
+ * step 1
236
+ * step 2"
237
+ scenario_1 = CukeModeler::Scenario.new(source)
238
+
239
+ source = "Scenario:
240
+ * step 2
241
+ * step 1"
242
+ scenario_2 = CukeModeler::Scenario.new(source)
243
+
244
+
245
+ expect(background).to eq(scenario_1)
246
+ expect(background).to_not eq(scenario_2)
247
+ end
248
+
249
+ it 'is equal to an outline with the same steps' do
250
+ source = "Background:
251
+ * step 1
252
+ * step 2"
253
+ background = clazz.new(source)
254
+
255
+ source = "Scenario Outline:
256
+ * step 1
257
+ * step 2
258
+ Examples:
259
+ | param |
260
+ | value |"
261
+ outline_1 = CukeModeler::Outline.new(source)
262
+
263
+ source = "Scenario Outline:
264
+ * step 2
265
+ * step 1
266
+ Examples:
267
+ | param |
268
+ | value |"
269
+ outline_2 = CukeModeler::Outline.new(source)
270
+
271
+
272
+ expect(background).to eq(outline_1)
273
+ expect(background).to_not eq(outline_2)
274
+ end
275
+
276
+ end
277
+
278
+
279
+ describe 'background output' do
280
+
281
+ it 'can be remade from its own output' do
282
+ source = ['Background: A background with everything it could have',
283
+ '',
284
+ 'Including a description',
285
+ 'and then some.',
286
+ '',
287
+ ' * a step',
288
+ ' | value |',
289
+ ' * another step',
290
+ ' """',
291
+ ' some string',
292
+ ' """']
293
+ source = source.join("\n")
294
+ background = clazz.new(source)
295
+
296
+ background_output = background.to_s
297
+ remade_background_output = clazz.new(background_output).to_s
298
+
299
+ expect(remade_background_output).to eq(background_output)
300
+ end
301
+
302
+
303
+ context 'from source text' do
304
+
305
+ it 'can output an empty background' do
306
+ source = ['Background:']
307
+ source = source.join("\n")
308
+ background = clazz.new(source)
309
+
310
+ background_output = background.to_s.split("\n")
311
+
312
+ expect(background_output).to eq(['Background:'])
313
+ end
314
+
315
+ it 'can output a background that has a name' do
316
+ source = ['Background: test background']
317
+ source = source.join("\n")
318
+ background = clazz.new(source)
319
+
320
+ background_output = background.to_s.split("\n")
321
+
322
+ expect(background_output).to eq(['Background: test background'])
323
+ end
324
+
325
+ it 'can output a background that has a description' do
326
+ source = ['Background:',
327
+ 'Some description.',
328
+ 'Some more description.']
329
+ source = source.join("\n")
330
+ background = clazz.new(source)
331
+
332
+ background_output = background.to_s.split("\n")
333
+
334
+ expect(background_output).to eq(['Background:',
335
+ '',
336
+ 'Some description.',
337
+ 'Some more description.'])
338
+ end
339
+
340
+ it 'can output a background that has steps' do
341
+ source = ['Background:',
342
+ '* a step',
343
+ '|value|',
344
+ '* another step',
345
+ '"""',
346
+ 'some string',
347
+ '"""']
348
+ source = source.join("\n")
349
+ background = clazz.new(source)
350
+
351
+ background_output = background.to_s.split("\n")
352
+
353
+ expect(background_output).to eq(['Background:',
354
+ ' * a step',
355
+ ' | value |',
356
+ ' * another step',
357
+ ' """',
358
+ ' some string',
359
+ ' """'])
360
+ end
361
+
362
+ it 'can output a background that has everything' do
363
+ source = ['Background: A background with everything it could have',
364
+ 'Including a description',
365
+ 'and then some.',
366
+ '* a step',
367
+ '|value|',
368
+ '* another step',
369
+ '"""',
370
+ 'some string',
371
+ '"""']
372
+ source = source.join("\n")
373
+ background = clazz.new(source)
374
+
375
+ background_output = background.to_s.split("\n")
376
+
377
+ expect(background_output).to eq(['Background: A background with everything it could have',
378
+ '',
379
+ 'Including a description',
380
+ 'and then some.',
381
+ '',
382
+ ' * a step',
383
+ ' | value |',
384
+ ' * another step',
385
+ ' """',
386
+ ' some string',
387
+ ' """'])
388
+ end
389
+
390
+ end
391
+
392
+
393
+ context 'from abstract instantiation' do
69
394
 
70
395
  let(:background) { clazz.new }
71
396
 
@@ -0,0 +1,321 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'Cell, Integration' do
5
+
6
+ let(:clazz) { CukeModeler::Cell }
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 = ''
20
+
21
+ expect { clazz.new(source) }.to_not raise_error
22
+ end
23
+
24
+ it 'provides a descriptive filename when being parsed from stand alone text' do
25
+ source = "not a \n cell"
26
+
27
+ expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_cell\.feature'/)
28
+ end
29
+
30
+ it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
31
+ cell = clazz.new('a cell')
32
+ data = cell.parsing_data
33
+
34
+ expect(data.keys).to match_array([:type, :location, :value])
35
+ expect(data[:type]).to eq(:TableCell)
36
+ end
37
+
38
+ it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
39
+ cell = clazz.new("a cell")
40
+ data = cell.parsing_data
41
+
42
+ expect(data.keys).to match_array([:type, :location, :value])
43
+ expect(data[:type]).to eq('TableCell')
44
+ end
45
+
46
+ it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
47
+ cell = clazz.new("a cell")
48
+ data = cell.parsing_data
49
+
50
+ # Cells did not exist as full fledged objects in the Gherkin2 parser
51
+ expect(data).to eq('a cell')
52
+ end
53
+
54
+
55
+ describe 'getting ancestors' do
56
+
57
+ before(:each) do
58
+ source = ['Feature: Test feature',
59
+ '',
60
+ ' Scenario: Test test',
61
+ ' * a step',
62
+ ' | a value |']
63
+ source = source.join("\n")
64
+
65
+ file_path = "#{@default_file_directory}/cell_test_file.feature"
66
+ File.open(file_path, 'w') { |file| file.write(source) }
67
+ end
68
+
69
+ let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
70
+ let(:cell) { directory.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
71
+
72
+
73
+ it 'can get its directory' do
74
+ ancestor = cell.get_ancestor(:directory)
75
+
76
+ expect(ancestor).to equal(directory)
77
+ end
78
+
79
+ it 'can get its feature file' do
80
+ ancestor = cell.get_ancestor(:feature_file)
81
+
82
+ expect(ancestor).to equal(directory.feature_files.first)
83
+ end
84
+
85
+ it 'can get its feature' do
86
+ ancestor = cell.get_ancestor(:feature)
87
+
88
+ expect(ancestor).to equal(directory.feature_files.first.feature)
89
+ end
90
+
91
+ context 'a cell that is part of an outline' do
92
+
93
+ before(:each) do
94
+ source = 'Feature: Test feature
95
+
96
+ Scenario Outline: Test outline
97
+ * a step
98
+ Examples:
99
+ | param |
100
+ | value |'
101
+
102
+ file_path = "#{@default_file_directory}/cell_test_file.feature"
103
+ File.open(file_path, 'w') { |file| file.write(source) }
104
+ end
105
+
106
+ let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
107
+ let(:cell) { directory.feature_files.first.feature.tests.first.examples.first.rows.first.cells.first }
108
+
109
+
110
+ it 'can get its outline' do
111
+ ancestor = cell.get_ancestor(:outline)
112
+
113
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first)
114
+ end
115
+
116
+ it 'can get its example' do
117
+ ancestor = cell.get_ancestor(:example)
118
+
119
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first.examples.first)
120
+ end
121
+
122
+ it 'can get its row' do
123
+ ancestor = cell.get_ancestor(:row)
124
+
125
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first.examples.first.rows.first)
126
+ end
127
+
128
+ end
129
+
130
+
131
+ context 'a cell that is part of a scenario' do
132
+
133
+ before(:each) do
134
+ source = 'Feature: Test feature
135
+
136
+ Scenario: Test test
137
+ * a step:
138
+ | a | table |'
139
+
140
+ file_path = "#{@default_file_directory}/cell_test_file.feature"
141
+ File.open(file_path, 'w') { |file| file.write(source) }
142
+ end
143
+
144
+ let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
145
+ let(:cell) { directory.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
146
+
147
+
148
+ it 'can get its scenario' do
149
+ ancestor = cell.get_ancestor(:scenario)
150
+
151
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first)
152
+ end
153
+
154
+ end
155
+
156
+ context 'a cell that is part of a background' do
157
+
158
+ before(:each) do
159
+ source = 'Feature: Test feature
160
+
161
+ Background: Test background
162
+ * a step:
163
+ | a | table |'
164
+
165
+ file_path = "#{@default_file_directory}/cell_test_file.feature"
166
+ File.open(file_path, 'w') { |file| file.write(source) }
167
+ end
168
+
169
+ let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
170
+ let(:cell) { directory.feature_files.first.feature.background.steps.first.block.rows.first.cells.first }
171
+
172
+
173
+ it 'can get its background' do
174
+ ancestor = cell.get_ancestor(:background)
175
+
176
+ expect(ancestor).to equal(directory.feature_files.first.feature.background)
177
+ end
178
+
179
+ end
180
+
181
+ context 'a cell that is part of a step' do
182
+
183
+ before(:each) do
184
+ source = 'Feature: Test feature
185
+
186
+ Scenario: Test test
187
+ * a step:
188
+ | a | table |'
189
+
190
+ file_path = "#{@default_file_directory}/cell_test_file.feature"
191
+ File.open(file_path, 'w') { |file| file.write(source) }
192
+ end
193
+
194
+ let(:directory) { CukeModeler::Directory.new(@default_file_directory) }
195
+ let(:cell) { directory.feature_files.first.feature.tests.first.steps.first.block.rows.first.cells.first }
196
+
197
+
198
+ it 'can get its step' do
199
+ ancestor = cell.get_ancestor(:step)
200
+
201
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first.steps.first)
202
+ end
203
+
204
+ it 'can get its table' do
205
+ ancestor = cell.get_ancestor(:table)
206
+
207
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first.steps.first.block)
208
+ end
209
+
210
+ it 'can get its row' do
211
+ ancestor = cell.get_ancestor(:row)
212
+
213
+ expect(ancestor).to equal(directory.feature_files.first.feature.tests.first.steps.first.block.rows.first)
214
+ end
215
+
216
+ end
217
+
218
+ it 'returns nil if it does not have the requested type of ancestor' do
219
+ ancestor = cell.get_ancestor(:example)
220
+
221
+ expect(ancestor).to be_nil
222
+ end
223
+
224
+ end
225
+
226
+
227
+ describe 'model population' do
228
+
229
+ context 'from source text' do
230
+
231
+ let(:source_text) { 'a cell' }
232
+ let(:cell) { clazz.new(source_text) }
233
+
234
+
235
+ it "models the cell's value" do
236
+ expect(cell.value).to eq('a cell')
237
+ end
238
+
239
+ it "models the cell's source line" do
240
+ source_text = 'Feature:
241
+
242
+ Scenario:
243
+ * a step
244
+ | value |'
245
+ cell = CukeModeler::Feature.new(source_text).tests.first.steps.first.block.rows.first.cells.first
246
+
247
+ expect(cell.source_line).to eq(5)
248
+ end
249
+
250
+ end
251
+
252
+ end
253
+
254
+
255
+ describe 'cell output' do
256
+
257
+ it 'can be remade from its own output' do
258
+ source = 'a \\\\ complex \| cell'
259
+ cell = clazz.new(source)
260
+
261
+ cell_output = cell.to_s
262
+ remade_cell_output = clazz.new(cell_output).to_s
263
+
264
+ expect(remade_cell_output).to eq(cell_output)
265
+ end
266
+
267
+
268
+ context 'from source text' do
269
+
270
+ it 'can output a cell' do
271
+ source = 'a cell'
272
+ cell = clazz.new(source)
273
+
274
+ expect(cell.to_s).to eq('a cell')
275
+ end
276
+
277
+ # Because vertical bars mark the beginning and end of a cell, any vertical bars inside
278
+ # of the cell (which would have had to have been escaped to get inside of the cell in
279
+ # the first place) will be escaped when outputted so as to retain the quality of being
280
+ # able to use the output directly as Gherkin.
281
+
282
+ it 'can output a cell that has vertical bars in it' do
283
+ source = 'cell with a \| in it'
284
+ cell = clazz.new(source)
285
+
286
+ cell_output = cell.to_s
287
+
288
+ expect(cell_output).to eq('cell with a \| in it')
289
+ end
290
+
291
+ # Because backslashes are used to escape special characters, any backslashes inside
292
+ # of the cell (which would have had to have been escaped to get inside of the cell in
293
+ # the first place) will be escaped when outputted so as to retain the quality of being
294
+ # able to use the output directly as Gherkin.
295
+
296
+ it 'can output a cell that has backslashes in it' do
297
+ source = 'cell with a \\\\ in it'
298
+ cell = clazz.new(source)
299
+
300
+ cell_output = cell.to_s
301
+
302
+ expect(cell_output).to eq('cell with a \\\\ in it')
303
+ end
304
+
305
+ # Depending on the order in which special characters are escaped, extra backslashes might occur.
306
+ it 'can output a cell that has several kinds of special characters in it' do
307
+ source = 'cell with a \\\\ and \| in it'
308
+ cell = clazz.new(source)
309
+
310
+ cell_output = cell.to_s
311
+
312
+ expect(cell_output).to eq('cell with a \\\\ and \| in it')
313
+ end
314
+
315
+ end
316
+
317
+ end
318
+
319
+ end
320
+
321
+ end