cuke_linter 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/CONTRIBUTING.md +26 -0
- data/README.md +2 -15
- data/lib/cuke_linter.rb +36 -18
- data/lib/cuke_linter/linters/example_without_name_linter.rb +1 -1
- data/lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb +38 -0
- data/lib/cuke_linter/linters/test_should_use_background_linter.rb +28 -0
- data/lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb +23 -0
- data/lib/cuke_linter/linters/test_with_setup_step_after_action_step_linter.rb +31 -0
- data/lib/cuke_linter/linters/test_with_setup_step_after_verification_step_linter.rb +31 -0
- data/lib/cuke_linter/linters/test_with_setup_step_as_final_step_linter.rb +23 -0
- data/lib/cuke_linter/version.rb +1 -1
- data/testing/cucumber/features/default_linters.feature +20 -14
- data/testing/cucumber/features/linters/example_without_name.feature +8 -6
- data/testing/cucumber/features/linters/feature_with_too_many_different_tags.feature +56 -0
- data/testing/cucumber/features/linters/step_with_end_period.feature +1 -1
- data/testing/cucumber/features/linters/test_should_use_background.feature +29 -0
- data/testing/cucumber/features/linters/test_with_action_as_final_step.feature +28 -0
- data/testing/cucumber/features/linters/test_with_setup_step_after_action_step.feature +30 -0
- data/testing/cucumber/features/linters/test_with_setup_step_after_verification_step.feature +30 -0
- data/testing/cucumber/features/linters/test_with_setup_step_as_final_step.feature +28 -0
- data/testing/cucumber/features/linters/test_with_too_many_steps.feature +5 -0
- data/testing/cucumber/step_definitions/setup_steps.rb +28 -0
- data/testing/model_factory.rb +1 -1
- data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +12 -0
- data/testing/rspec/spec/integration/linters/feature_with_too_many_different_tags_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_should_use_background_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_with_action_step_as_final_step_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_with_setup_step_after_action_step_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_with_setup_step_after_verification_step_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_with_setup_step_as_final_step_linter_integration_spec.rb +8 -0
- data/testing/rspec/spec/unit/linters/background_does_more_than_setup_linter_unit_spec.rb +20 -57
- data/testing/rspec/spec/unit/linters/element_with_too_many_tags_linter_unit_spec.rb +18 -52
- data/testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb +41 -43
- data/testing/rspec/spec/unit/linters/feature_with_too_many_different_tags_linter_unit_spec.rb +293 -0
- data/testing/rspec/spec/unit/linters/feature_without_description_linter_unit_spec.rb +25 -42
- data/testing/rspec/spec/unit/linters/feature_without_name_linter_unit_spec.rb +10 -38
- data/testing/rspec/spec/unit/linters/feature_without_scenarios_linter_unit_spec.rb +32 -52
- data/testing/rspec/spec/unit/linters/linter_unit_spec.rb +27 -10
- data/testing/rspec/spec/unit/linters/linter_unit_specs.rb +26 -12
- data/testing/rspec/spec/unit/linters/outline_with_single_example_row_linter_unit_spec.rb +19 -66
- data/testing/rspec/spec/unit/linters/single_test_background_linter_unit_spec.rb +12 -39
- data/testing/rspec/spec/unit/linters/step_with_end_period_linter_unit_spec.rb +9 -28
- data/testing/rspec/spec/unit/linters/step_with_too_many_characters_linter_unit_spec.rb +19 -45
- data/testing/rspec/spec/unit/linters/test_should_use_background_linter_unit_spec.rb +226 -0
- data/testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb +98 -0
- data/testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb +10 -51
- data/testing/rspec/spec/unit/linters/test_with_no_name_linter_unit_spec.rb +11 -38
- data/testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb +16 -54
- data/testing/rspec/spec/unit/linters/test_with_setup_step_after_action_step_linter_unit_spec.rb +124 -0
- data/testing/rspec/spec/unit/linters/test_with_setup_step_after_verification_step_linter_unit_spec.rb +125 -0
- data/testing/rspec/spec/unit/linters/test_with_setup_step_as_final_step_linter_unit_spec.rb +98 -0
- data/testing/rspec/spec/unit/linters/test_with_too_many_steps_linter_unit_spec.rb +9 -49
- metadata +27 -2
@@ -0,0 +1,226 @@
|
|
1
|
+
require_relative '../../../../../environments/rspec_env'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe CukeLinter::TestShouldUseBackgroundLinter do
|
5
|
+
|
6
|
+
let(:model_file_path) { 'some_file_path' }
|
7
|
+
|
8
|
+
it_should_behave_like 'a linter at the unit level'
|
9
|
+
|
10
|
+
|
11
|
+
it 'has a name' do
|
12
|
+
expect(subject.name).to eq('TestShouldUseBackgroundLinter')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'linting' do
|
16
|
+
|
17
|
+
['scenario', 'outline'].each do |model_type|
|
18
|
+
|
19
|
+
context "with a #{model_type} that shares a first step with all other tests in the feature" do
|
20
|
+
|
21
|
+
let(:test_model) do
|
22
|
+
step_text = 'the step'
|
23
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path,
|
24
|
+
source_text: "Feature:
|
25
|
+
Scenario:
|
26
|
+
* #{step_text}
|
27
|
+
Scenario Outline:
|
28
|
+
* #{step_text}
|
29
|
+
Examples:
|
30
|
+
| param |
|
31
|
+
| value |")
|
32
|
+
|
33
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
34
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
35
|
+
|
36
|
+
model.parent_model = feature_model
|
37
|
+
feature_model.tests << model
|
38
|
+
|
39
|
+
model
|
40
|
+
end
|
41
|
+
|
42
|
+
it_should_behave_like 'a linter linting a bad model'
|
43
|
+
|
44
|
+
|
45
|
+
it 'records a problem' do
|
46
|
+
result = subject.lint(test_model)
|
47
|
+
|
48
|
+
expect(result[:problem]).to eq('Test shares steps with all other tests in feature. Use a background.')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with a #{model_type} that does not share a first step with all other tests in the feature" do
|
54
|
+
|
55
|
+
context 'because the steps are different' do
|
56
|
+
|
57
|
+
let(:test_model) do
|
58
|
+
step_text = 'the step'
|
59
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
60
|
+
Scenario:
|
61
|
+
* #{step_text}
|
62
|
+
Scenario Outline:
|
63
|
+
* #{step_text}
|
64
|
+
Examples:
|
65
|
+
| param |
|
66
|
+
| value |")
|
67
|
+
|
68
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
69
|
+
model.steps = [CukeModeler::Step.new("* #{step_text} plus extra")]
|
70
|
+
|
71
|
+
model.parent_model = feature_model
|
72
|
+
feature_model.tests << model
|
73
|
+
|
74
|
+
model
|
75
|
+
end
|
76
|
+
|
77
|
+
it_should_behave_like 'a linter linting a good model'
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'because it has no steps' do
|
82
|
+
|
83
|
+
context 'because its steps are empty' do
|
84
|
+
|
85
|
+
let(:test_model) do
|
86
|
+
step_text = 'the step'
|
87
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
88
|
+
Scenario:
|
89
|
+
* #{step_text}
|
90
|
+
Scenario Outline:
|
91
|
+
* #{step_text}
|
92
|
+
Examples:
|
93
|
+
| param |
|
94
|
+
| value |")
|
95
|
+
|
96
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
97
|
+
model.steps = []
|
98
|
+
|
99
|
+
model.parent_model = feature_model
|
100
|
+
feature_model.tests << model
|
101
|
+
|
102
|
+
model
|
103
|
+
end
|
104
|
+
|
105
|
+
it_should_behave_like 'a linter linting a good model'
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'because its steps are nil' do
|
110
|
+
|
111
|
+
let(:test_model) do
|
112
|
+
step_text = 'the step'
|
113
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
114
|
+
Scenario:
|
115
|
+
* #{step_text}
|
116
|
+
Scenario Outline:
|
117
|
+
* #{step_text}
|
118
|
+
Examples:
|
119
|
+
| param |
|
120
|
+
| value |")
|
121
|
+
|
122
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
123
|
+
model.steps = nil
|
124
|
+
|
125
|
+
model.parent_model = feature_model
|
126
|
+
feature_model.tests << model
|
127
|
+
|
128
|
+
model
|
129
|
+
end
|
130
|
+
|
131
|
+
it_should_behave_like 'a linter linting a good model'
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'because another test has no steps' do
|
138
|
+
|
139
|
+
context 'because its steps are empty' do
|
140
|
+
|
141
|
+
let(:test_model) do
|
142
|
+
step_text = 'the step'
|
143
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
144
|
+
Scenario:
|
145
|
+
* #{step_text}
|
146
|
+
Scenario Outline:
|
147
|
+
* #{step_text}
|
148
|
+
Examples:
|
149
|
+
| param |
|
150
|
+
| value |")
|
151
|
+
|
152
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
153
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
154
|
+
|
155
|
+
model.parent_model = feature_model
|
156
|
+
feature_model.tests.first.steps = []
|
157
|
+
feature_model.tests << model
|
158
|
+
|
159
|
+
model
|
160
|
+
end
|
161
|
+
|
162
|
+
it_should_behave_like 'a linter linting a good model'
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'because its steps are nil' do
|
167
|
+
|
168
|
+
let(:test_model) do
|
169
|
+
step_text = 'the step'
|
170
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
171
|
+
Scenario:
|
172
|
+
* #{step_text}
|
173
|
+
Scenario Outline:
|
174
|
+
* #{step_text}
|
175
|
+
Examples:
|
176
|
+
| param |
|
177
|
+
| value |")
|
178
|
+
|
179
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
180
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
181
|
+
|
182
|
+
model.parent_model = feature_model
|
183
|
+
feature_model.tests.first.steps = nil
|
184
|
+
feature_model.tests << model
|
185
|
+
|
186
|
+
model
|
187
|
+
end
|
188
|
+
|
189
|
+
it_should_behave_like 'a linter linting a good model'
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'because there are not other tests in the feature' do
|
196
|
+
|
197
|
+
let(:test_model) do
|
198
|
+
step_text = 'the step'
|
199
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:')
|
200
|
+
|
201
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
202
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
203
|
+
|
204
|
+
model.parent_model = feature_model
|
205
|
+
feature_model.tests << model
|
206
|
+
|
207
|
+
model
|
208
|
+
end
|
209
|
+
|
210
|
+
it_should_behave_like 'a linter linting a good model'
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'a non-test model' do
|
219
|
+
|
220
|
+
let(:test_model) { CukeModeler::Model.new }
|
221
|
+
|
222
|
+
it_should_behave_like 'a linter linting a good model'
|
223
|
+
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative '../../../../../environments/rspec_env'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe CukeLinter::TestWithActionStepAsFinalStepLinter do
|
5
|
+
|
6
|
+
let(:model_file_path) { 'some_file_path' }
|
7
|
+
|
8
|
+
it_should_behave_like 'a linter at the unit level'
|
9
|
+
|
10
|
+
|
11
|
+
it 'has a name' do
|
12
|
+
expect(subject.name).to eq('TestWithActionStepAsFinalStepLinter')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'linting' do
|
16
|
+
|
17
|
+
['scenario', 'outline'].each do |model_type|
|
18
|
+
|
19
|
+
context "with a #{model_type} that has an action step as its final step" do
|
20
|
+
|
21
|
+
let(:test_model) do
|
22
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
23
|
+
model.steps = [CukeModeler::Step.new('Given a step'),
|
24
|
+
CukeModeler::Step.new('When a step')]
|
25
|
+
|
26
|
+
model
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like 'a linter linting a bad model'
|
30
|
+
|
31
|
+
|
32
|
+
it 'records a problem' do
|
33
|
+
result = subject.lint(test_model)
|
34
|
+
|
35
|
+
expect(result[:problem]).to eq("Test has 'When' as the final step.")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with a #{model_type} that does not have an action step as its final step" do
|
41
|
+
|
42
|
+
context 'because it has no steps' do
|
43
|
+
|
44
|
+
context 'because its steps are empty' do
|
45
|
+
|
46
|
+
let(:test_model) do
|
47
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
48
|
+
model.steps = []
|
49
|
+
|
50
|
+
model
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like 'a linter linting a good model'
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'because its steps are nil' do
|
58
|
+
|
59
|
+
let(:test_model) do
|
60
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
61
|
+
model.steps = nil
|
62
|
+
|
63
|
+
model
|
64
|
+
end
|
65
|
+
|
66
|
+
it_should_behave_like 'a linter linting a good model'
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'because its final step is not an action step' do
|
73
|
+
|
74
|
+
let(:test_model) do
|
75
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
76
|
+
model.steps = [CukeModeler::Step.new('Then a step')]
|
77
|
+
|
78
|
+
model
|
79
|
+
end
|
80
|
+
|
81
|
+
it_should_behave_like 'a linter linting a good model'
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
context 'a non-test model' do
|
91
|
+
|
92
|
+
let(:test_model) { CukeModeler::Model.new }
|
93
|
+
|
94
|
+
it_should_behave_like 'a linter linting a good model'
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -3,16 +3,7 @@ require_relative '../../../../../environments/rspec_env'
|
|
3
3
|
|
4
4
|
RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario:
|
8
|
-
When an action step')
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:bad_data) do
|
12
|
-
CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario:
|
13
|
-
* no action step')
|
14
|
-
end
|
15
|
-
|
6
|
+
let(:model_file_path) { 'some_file_path' }
|
16
7
|
|
17
8
|
it_should_behave_like 'a linter at the unit level'
|
18
9
|
|
@@ -32,7 +23,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
32
23
|
context 'because its steps are empty' do
|
33
24
|
|
34
25
|
let(:test_model) do
|
35
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path:
|
26
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
36
27
|
model.steps = []
|
37
28
|
|
38
29
|
model
|
@@ -44,22 +35,14 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
44
35
|
expect(result[:problem]).to eq("Test does not have a 'When' step.")
|
45
36
|
end
|
46
37
|
|
47
|
-
|
48
|
-
test_model.source_line = 1
|
49
|
-
result = subject.lint(test_model)
|
50
|
-
expect(result[:location]).to eq('path_to_file:1')
|
51
|
-
|
52
|
-
test_model.source_line = 3
|
53
|
-
result = subject.lint(test_model)
|
54
|
-
expect(result[:location]).to eq('path_to_file:3')
|
55
|
-
end
|
38
|
+
it_should_behave_like 'a linter linting a bad model'
|
56
39
|
|
57
40
|
end
|
58
41
|
|
59
42
|
context 'because its steps are nil' do
|
60
43
|
|
61
44
|
let(:test_model) do
|
62
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path:
|
45
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
63
46
|
model.steps = nil
|
64
47
|
|
65
48
|
model
|
@@ -71,15 +54,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
71
54
|
expect(result[:problem]).to eq("Test does not have a 'When' step.")
|
72
55
|
end
|
73
56
|
|
74
|
-
|
75
|
-
test_model.source_line = 1
|
76
|
-
result = subject.lint(test_model)
|
77
|
-
expect(result[:location]).to eq('path_to_file:1')
|
78
|
-
|
79
|
-
test_model.source_line = 3
|
80
|
-
result = subject.lint(test_model)
|
81
|
-
expect(result[:location]).to eq('path_to_file:3')
|
82
|
-
end
|
57
|
+
it_should_behave_like 'a linter linting a bad model'
|
83
58
|
|
84
59
|
end
|
85
60
|
|
@@ -88,7 +63,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
88
63
|
context 'because none of its steps is an action step' do
|
89
64
|
|
90
65
|
let(:test_model) do
|
91
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path:
|
66
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
92
67
|
model.steps = [CukeModeler::Step.new('* not an action step')]
|
93
68
|
|
94
69
|
model
|
@@ -100,15 +75,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
100
75
|
expect(result[:problem]).to eq("Test does not have a 'When' step.")
|
101
76
|
end
|
102
77
|
|
103
|
-
|
104
|
-
test_model.source_line = 1
|
105
|
-
result = subject.lint(test_model)
|
106
|
-
expect(result[:location]).to eq('path_to_file:1')
|
107
|
-
|
108
|
-
test_model.source_line = 3
|
109
|
-
result = subject.lint(test_model)
|
110
|
-
expect(result[:location]).to eq('path_to_file:3')
|
111
|
-
end
|
78
|
+
it_should_behave_like 'a linter linting a bad model'
|
112
79
|
|
113
80
|
end
|
114
81
|
|
@@ -128,9 +95,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
128
95
|
model
|
129
96
|
end
|
130
97
|
|
131
|
-
|
132
|
-
expect(subject.lint(test_model)).to eq(nil)
|
133
|
-
end
|
98
|
+
it_should_behave_like 'a linter linting a good model'
|
134
99
|
|
135
100
|
end
|
136
101
|
|
@@ -143,9 +108,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
143
108
|
model
|
144
109
|
end
|
145
110
|
|
146
|
-
|
147
|
-
expect(subject.lint(test_model)).to eq(nil)
|
148
|
-
end
|
111
|
+
it_should_behave_like 'a linter linting a good model'
|
149
112
|
|
150
113
|
end
|
151
114
|
|
@@ -206,11 +169,7 @@ RSpec.describe CukeLinter::TestWithNoActionStepLinter do
|
|
206
169
|
|
207
170
|
let(:test_model) { CukeModeler::Model.new }
|
208
171
|
|
209
|
-
|
210
|
-
result = subject.lint(test_model)
|
211
|
-
|
212
|
-
expect(result).to eq(nil)
|
213
|
-
end
|
172
|
+
it_should_behave_like 'a linter linting a good model'
|
214
173
|
|
215
174
|
end
|
216
175
|
end
|