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.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/.travis.yml +1 -1
- data/Gemfile +4 -0
- data/History.rdoc +71 -3
- data/LICENSE.txt +22 -22
- data/README.md +24 -10
- data/Rakefile +2 -12
- data/cuke_modeler.gemspec +1 -1
- data/features/analysis/test_comparison.feature +37 -122
- data/features/modeling/background_modeling.feature +77 -0
- data/features/modeling/background_output.feature +42 -0
- data/features/modeling/cell_modeling.feature +23 -0
- data/features/modeling/cell_output.feature +22 -0
- data/features/modeling/directory_modeling.feature +65 -0
- data/features/modeling/directory_output.feature +12 -0
- data/features/modeling/doc_string_modeling.feature +61 -0
- data/features/modeling/doc_string_output.feature +32 -0
- data/features/modeling/example_modeling.feature +125 -0
- data/features/modeling/example_output.feature +39 -0
- data/features/modeling/feature_file_modeling.feature +40 -0
- data/features/modeling/feature_file_output.feature +12 -0
- data/features/modeling/feature_modeling.feature +109 -0
- data/features/modeling/feature_output.feature +104 -0
- data/features/modeling/model_output.feature +22 -0
- data/features/modeling/model_structure.feature +48 -0
- data/features/modeling/outline_modeling.feature +144 -0
- data/features/modeling/outline_output.feature +69 -0
- data/features/modeling/row_modeling.feature +48 -0
- data/features/modeling/row_output.feature +22 -0
- data/features/modeling/scenario_modeling.feature +118 -0
- data/features/modeling/scenario_output.feature +45 -0
- data/features/modeling/step_modeling.feature +84 -0
- data/features/modeling/step_output.feature +29 -0
- data/features/modeling/table_modeling.feature +50 -0
- data/features/modeling/table_output.feature +24 -0
- data/features/modeling/tag_modeling.feature +43 -0
- data/features/modeling/tag_output.feature +22 -0
- data/features/step_definitions/action_steps.rb +11 -1
- data/features/step_definitions/background_steps.rb +1 -85
- data/features/step_definitions/directory_steps.rb +2 -48
- data/features/step_definitions/doc_string_steps.rb +1 -67
- data/features/step_definitions/feature_file_steps.rb +2 -37
- data/features/step_definitions/feature_steps.rb +4 -100
- data/features/step_definitions/modeling_steps.rb +44 -0
- data/features/step_definitions/setup_steps.rb +19 -41
- data/features/step_definitions/step_steps.rb +2 -166
- data/features/step_definitions/table_steps.rb +1 -58
- data/features/step_definitions/tag_steps.rb +2 -72
- data/features/step_definitions/verification_steps.rb +152 -4
- data/features/support/env.rb +4 -6
- data/gemfiles/{gherkin.gemfile → gherkin2.gemfile} +4 -0
- data/gemfiles/gherkin3.gemfile +4 -0
- data/gemfiles/gherkin4.gemfile +4 -0
- data/lib/cuke_modeler.rb +24 -22
- data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +103 -31
- data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +103 -40
- data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +111 -50
- data/lib/cuke_modeler/containing.rb +255 -4
- data/lib/cuke_modeler/described.rb +28 -0
- data/lib/cuke_modeler/models/background.rb +66 -0
- data/lib/cuke_modeler/models/cell.rb +48 -0
- data/lib/cuke_modeler/models/directory.rb +95 -0
- data/lib/cuke_modeler/models/doc_string.rb +59 -0
- data/lib/cuke_modeler/models/example.rb +167 -0
- data/lib/cuke_modeler/models/feature.rb +106 -0
- data/lib/cuke_modeler/models/feature_file.rb +64 -0
- data/lib/cuke_modeler/models/model.rb +32 -0
- data/lib/cuke_modeler/models/outline.rb +79 -0
- data/lib/cuke_modeler/models/row.rb +49 -0
- data/lib/cuke_modeler/models/scenario.rb +69 -0
- data/lib/cuke_modeler/models/step.rb +68 -0
- data/lib/cuke_modeler/models/table.rb +67 -0
- data/lib/cuke_modeler/models/tag.rb +46 -0
- data/lib/cuke_modeler/named.rb +19 -0
- data/lib/cuke_modeler/nested.rb +22 -15
- data/lib/cuke_modeler/parsed.rb +11 -0
- data/lib/cuke_modeler/parsing.rb +66 -83
- data/lib/cuke_modeler/sourceable.rb +3 -11
- data/lib/cuke_modeler/stepped.rb +24 -0
- data/lib/cuke_modeler/taggable.rb +6 -29
- data/lib/cuke_modeler/version.rb +2 -1
- data/spec/integration/background_integration_spec.rb +332 -7
- data/spec/integration/cell_integration_spec.rb +321 -0
- data/spec/integration/directory_integration_spec.rb +175 -9
- data/spec/integration/doc_string_integration_spec.rb +318 -7
- data/spec/integration/example_integration_spec.rb +602 -19
- data/spec/integration/feature_file_integration_spec.rb +98 -3
- data/spec/integration/feature_integration_spec.rb +445 -27
- data/spec/integration/gherkin_2_adapter_spec.rb +122 -0
- data/spec/integration/gherkin_3_adapter_spec.rb +125 -0
- data/spec/integration/gherkin_4_adapter_spec.rb +123 -0
- data/spec/integration/model_integration_spec.rb +15 -0
- data/spec/integration/nested_integration_spec.rb +91 -0
- data/spec/integration/outline_integration_spec.rb +485 -12
- data/spec/integration/parsing_integration_spec.rb +85 -0
- data/spec/integration/row_integration_spec.rb +221 -18
- data/spec/integration/scenario_integration_spec.rb +368 -14
- data/spec/integration/shared/models_integration_specs.rb +18 -0
- data/spec/integration/step_integration_spec.rb +328 -77
- data/spec/integration/table_integration_spec.rb +242 -20
- data/spec/integration/tag_integration_spec.rb +178 -13
- data/spec/spec_helper.rb +32 -18
- data/spec/unit/background_unit_spec.rb +24 -44
- data/spec/unit/cell_unit_spec.rb +73 -0
- data/spec/unit/described_unit_spec.rb +23 -0
- data/spec/unit/directory_unit_spec.rb +52 -62
- data/spec/unit/doc_string_unit_spec.rb +47 -100
- data/spec/unit/example_unit_spec.rb +50 -296
- data/spec/unit/feature_file_unit_spec.rb +53 -52
- data/spec/unit/feature_unit_spec.rb +39 -83
- data/spec/unit/model_unit_spec.rb +15 -0
- data/spec/unit/named_unit_spec.rb +23 -0
- data/spec/unit/nested_unit_spec.rb +24 -21
- data/spec/unit/outline_unit_spec.rb +46 -69
- data/spec/unit/parsed_unit_spec.rb +27 -0
- data/spec/unit/parsing_unit_spec.rb +2 -70
- data/spec/unit/row_unit_spec.rb +22 -51
- data/spec/unit/scenario_unit_spec.rb +27 -59
- data/spec/unit/{bare_bones_unit_specs.rb → shared/bare_bones_models_unit_specs.rb} +2 -2
- data/spec/unit/shared/containing_models_unit_specs.rb +18 -0
- data/spec/unit/shared/described_models_unit_specs.rb +38 -0
- data/spec/unit/shared/models_unit_specs.rb +15 -0
- data/spec/unit/shared/named_models_unit_specs.rb +39 -0
- data/spec/unit/shared/nested_models_unit_specs.rb +51 -0
- data/spec/unit/shared/parsed_models_unit_specs.rb +39 -0
- data/spec/unit/shared/prepopulated_models_unit_specs.rb +18 -0
- data/spec/unit/shared/sourced_models_unit_specs.rb +39 -0
- data/spec/unit/shared/stepped_models_unit_specs.rb +46 -0
- data/spec/unit/shared/stringifiable_models_unit_specs.rb +18 -0
- data/spec/unit/shared/tagged_models_unit_specs.rb +72 -0
- data/spec/unit/sourceable_unit_spec.rb +12 -4
- data/spec/unit/step_unit_spec.rb +40 -231
- data/spec/unit/stepped_unit_spec.rb +23 -0
- data/spec/unit/table_unit_spec.rb +27 -89
- data/spec/unit/tag_unit_spec.rb +30 -53
- data/spec/unit/taggable_unit_spec.rb +26 -42
- data/todo.txt +32 -0
- metadata +135 -217
- data/features/analysis/test_manipulation.feature +0 -37
- data/features/modeling/gherkin/background_modeling.feature +0 -65
- data/features/modeling/gherkin/background_output.feature +0 -131
- data/features/modeling/gherkin/directory_modeling.feature +0 -110
- data/features/modeling/gherkin/directory_output.feature +0 -14
- data/features/modeling/gherkin/doc_string_modeling.feature +0 -53
- data/features/modeling/gherkin/doc_string_output.feature +0 -72
- data/features/modeling/gherkin/example_modeling.feature +0 -101
- data/features/modeling/gherkin/example_output.feature +0 -193
- data/features/modeling/gherkin/feature_file_modeling.feature +0 -54
- data/features/modeling/gherkin/feature_file_output.feature +0 -14
- data/features/modeling/gherkin/feature_modeling.feature +0 -154
- data/features/modeling/gherkin/feature_output.feature +0 -245
- data/features/modeling/gherkin/outline_modeling.feature +0 -90
- data/features/modeling/gherkin/outline_output.feature +0 -198
- data/features/modeling/gherkin/row_modeling.feature +0 -68
- data/features/modeling/gherkin/row_output.feature +0 -28
- data/features/modeling/gherkin/scenario_modeling.feature +0 -79
- data/features/modeling/gherkin/scenario_output.feature +0 -148
- data/features/modeling/gherkin/step_modeling.feature +0 -75
- data/features/modeling/gherkin/step_output.feature +0 -53
- data/features/modeling/gherkin/table_modeling.feature +0 -42
- data/features/modeling/gherkin/table_output.feature +0 -43
- data/features/modeling/gherkin/table_row_modeling.feature +0 -57
- data/features/modeling/gherkin/table_row_output.feature +0 -28
- data/features/modeling/gherkin/tag_modeling.feature +0 -48
- data/features/modeling/gherkin/tag_output.feature +0 -17
- data/features/modeling/gherkin3/background_modeling.feature +0 -64
- data/features/modeling/gherkin3/background_output.feature +0 -131
- data/features/modeling/gherkin3/directory_modeling.feature +0 -110
- data/features/modeling/gherkin3/directory_output.feature +0 -14
- data/features/modeling/gherkin3/doc_string_modeling.feature +0 -53
- data/features/modeling/gherkin3/doc_string_output.feature +0 -72
- data/features/modeling/gherkin3/example_modeling.feature +0 -100
- data/features/modeling/gherkin3/example_output.feature +0 -207
- data/features/modeling/gherkin3/feature_file_modeling.feature +0 -54
- data/features/modeling/gherkin3/feature_file_output.feature +0 -14
- data/features/modeling/gherkin3/feature_modeling.feature +0 -155
- data/features/modeling/gherkin3/feature_output.feature +0 -249
- data/features/modeling/gherkin3/outline_modeling.feature +0 -89
- data/features/modeling/gherkin3/outline_output.feature +0 -255
- data/features/modeling/gherkin3/row_modeling.feature +0 -68
- data/features/modeling/gherkin3/row_output.feature +0 -28
- data/features/modeling/gherkin3/scenario_modeling.feature +0 -78
- data/features/modeling/gherkin3/scenario_output.feature +0 -148
- data/features/modeling/gherkin3/step_modeling.feature +0 -75
- data/features/modeling/gherkin3/step_output.feature +0 -53
- data/features/modeling/gherkin3/table_modeling.feature +0 -42
- data/features/modeling/gherkin3/table_output.feature +0 -43
- data/features/modeling/gherkin3/table_row_modeling.feature +0 -57
- data/features/modeling/gherkin3/table_row_output.feature +0 -28
- data/features/modeling/gherkin3/tag_modeling.feature +0 -49
- data/features/modeling/gherkin3/tag_output.feature +0 -17
- data/features/modeling/gherkin4/background_modeling.feature +0 -64
- data/features/modeling/gherkin4/background_output.feature +0 -131
- data/features/modeling/gherkin4/directory_modeling.feature +0 -110
- data/features/modeling/gherkin4/directory_output.feature +0 -14
- data/features/modeling/gherkin4/doc_string_modeling.feature +0 -53
- data/features/modeling/gherkin4/doc_string_output.feature +0 -72
- data/features/modeling/gherkin4/example_modeling.feature +0 -100
- data/features/modeling/gherkin4/example_output.feature +0 -193
- data/features/modeling/gherkin4/feature_file_modeling.feature +0 -54
- data/features/modeling/gherkin4/feature_file_output.feature +0 -14
- data/features/modeling/gherkin4/feature_modeling.feature +0 -153
- data/features/modeling/gherkin4/feature_output.feature +0 -245
- data/features/modeling/gherkin4/outline_modeling.feature +0 -89
- data/features/modeling/gherkin4/outline_output.feature +0 -198
- data/features/modeling/gherkin4/row_modeling.feature +0 -68
- data/features/modeling/gherkin4/row_output.feature +0 -28
- data/features/modeling/gherkin4/scenario_modeling.feature +0 -78
- data/features/modeling/gherkin4/scenario_output.feature +0 -148
- data/features/modeling/gherkin4/step_modeling.feature +0 -75
- data/features/modeling/gherkin4/step_output.feature +0 -53
- data/features/modeling/gherkin4/table_modeling.feature +0 -42
- data/features/modeling/gherkin4/table_output.feature +0 -43
- data/features/modeling/gherkin4/table_row_modeling.feature +0 -57
- data/features/modeling/gherkin4/table_row_output.feature +0 -28
- data/features/modeling/gherkin4/tag_modeling.feature +0 -48
- data/features/modeling/gherkin4/tag_output.feature +0 -17
- data/features/step_definitions/outline_steps.rb +0 -258
- data/features/step_definitions/test_steps.rb +0 -123
- data/lib/cuke_modeler/background.rb +0 -38
- data/lib/cuke_modeler/directory.rb +0 -83
- data/lib/cuke_modeler/doc_string.rb +0 -87
- data/lib/cuke_modeler/example.rb +0 -195
- data/lib/cuke_modeler/feature.rb +0 -147
- data/lib/cuke_modeler/feature_element.rb +0 -73
- data/lib/cuke_modeler/feature_file.rb +0 -77
- data/lib/cuke_modeler/outline.rb +0 -68
- data/lib/cuke_modeler/raw.rb +0 -20
- data/lib/cuke_modeler/row.rb +0 -64
- data/lib/cuke_modeler/scenario.rb +0 -45
- data/lib/cuke_modeler/step.rb +0 -216
- data/lib/cuke_modeler/table.rb +0 -90
- data/lib/cuke_modeler/table_row.rb +0 -64
- data/lib/cuke_modeler/tag.rb +0 -62
- data/lib/cuke_modeler/test_element.rb +0 -79
- data/lib/cuke_modeler/world.rb +0 -113
- data/spec/integration/table_row_integration_spec.rb +0 -76
- data/spec/integration/world_integration_spec.rb +0 -14
- data/spec/unit/containing_element_unit_specs.rb +0 -18
- data/spec/unit/feature_element_unit_spec.rb +0 -19
- data/spec/unit/feature_element_unit_specs.rb +0 -52
- data/spec/unit/nested_element_unit_specs.rb +0 -39
- data/spec/unit/prepopulated_unit_specs.rb +0 -14
- data/spec/unit/raw_element_unit_specs.rb +0 -27
- data/spec/unit/raw_unit_spec.rb +0 -28
- data/spec/unit/sourced_element_unit_specs.rb +0 -18
- data/spec/unit/table_row_unit_spec.rb +0 -102
- data/spec/unit/tagged_element_unit_specs.rb +0 -67
- data/spec/unit/test_element_unit_spec.rb +0 -54
- data/spec/unit/test_element_unit_specs.rb +0 -34
- data/spec/unit/world_unit_spec.rb +0 -140
data/lib/cuke_modeler/version.rb
CHANGED
@@ -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 '
|
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.
|
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.
|
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.
|
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
|
-
|
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
|