cuke_linter 0.10.0 → 0.11.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 +10 -2
- data/lib/cuke_linter/linters/feature_file_with_invalid_name_linter.rb +21 -0
- data/lib/cuke_linter/linters/linter.rb +5 -1
- data/lib/cuke_linter/linters/test_with_bad_name_linter.rb +24 -0
- data/lib/cuke_linter/version.rb +1 -1
- data/lib/cuke_linter.rb +5 -1
- data/testing/cucumber/features/default_linters.feature +2 -0
- data/testing/cucumber/features/linters/feature_file_with_invalid_name.feature +20 -0
- data/testing/cucumber/features/linters/test_with_bad_name.feature +29 -0
- data/testing/cucumber/step_definitions/setup_steps.rb +14 -0
- data/testing/cucumber/step_definitions/verification_steps.rb +9 -1
- data/testing/model_factory.rb +6 -0
- data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +31 -40
- data/testing/rspec/spec/integration/linters/feature_file_with_invalid_name_integration_spec.rb +8 -0
- data/testing/rspec/spec/integration/linters/test_with_bad_name_integration_spec.rb +8 -0
- data/testing/rspec/spec/unit/linters/feature_file_with_invalid_name_linter_unit_spec.rb +106 -0
- data/testing/rspec/spec/unit/linters/linter_unit_specs.rb +12 -7
- data/testing/rspec/spec/unit/linters/test_with_bad_name_linter_unit_spec.rb +81 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2262e2bfc35fa228578832a6dcaaf98c414ae641316de99c0e4123d58951bbf6
|
4
|
+
data.tar.gz: 02334cd45f28a225cef180e451f95eac230bcbc7912ae41637e6e999abe539f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e8b329df051721fd6ca9405740863ca4c8bcee606cbfe33854ad9d57e63bb4d5c3da99c0a4345d349e77f3adb39d676cec088ed469a557f44c90dcff1b6111
|
7
|
+
data.tar.gz: 31bdfa3dcb5dd22066b481aa45d9499b2f5c96a2f31f79581a8c1d2afa5d0d2d136ef247199e2ee5846914779f6955fad373ce9783bf7c4907ad6df4102c621e
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
Nothing yet...
|
9
|
+
Nothing yet... *(see development branch)*
|
10
|
+
|
11
|
+
## [0.11.0] - 2019-11-01
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- New linters
|
15
|
+
- FeatureFileWithInvalidNameLinter
|
16
|
+
- TestWithBadNameLinter
|
10
17
|
|
11
18
|
|
12
19
|
## [0.10.0] - 2019-10-04
|
@@ -105,7 +112,8 @@ Nothing yet...
|
|
105
112
|
- Custom linters, formatters, and command line usability
|
106
113
|
|
107
114
|
|
108
|
-
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.
|
115
|
+
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.11.0...HEAD
|
116
|
+
[0.11.0]: https://github.com/enkessler/cuke_linter/compare/v0.10.0...v0.11.0
|
109
117
|
[0.10.0]: https://github.com/enkessler/cuke_linter/compare/v0.9.0...v0.10.0
|
110
118
|
[0.9.0]: https://github.com/enkessler/cuke_linter/compare/v0.8.0...v0.9.0
|
111
119
|
[0.8.0]: https://github.com/enkessler/cuke_linter/compare/v0.7.0...v0.8.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CukeLinter
|
2
|
+
|
3
|
+
# A linter that detects invalid feature file names
|
4
|
+
|
5
|
+
class FeatureFileWithInvalidNameLinter < Linter
|
6
|
+
|
7
|
+
# The rule used to determine if a model has a problem
|
8
|
+
def rule(model)
|
9
|
+
return false unless model.is_a?(CukeModeler::FeatureFile)
|
10
|
+
|
11
|
+
base = File.basename model.path
|
12
|
+
base =~ /[A-Z -]/
|
13
|
+
end
|
14
|
+
|
15
|
+
# The message used to describe the problem that has been found
|
16
|
+
def message
|
17
|
+
'Feature files should be snake_cased.'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -25,7 +25,11 @@ module CukeLinter
|
|
25
25
|
if problem_found
|
26
26
|
problem_message = respond_to?(:message) ? message : @message
|
27
27
|
|
28
|
-
|
28
|
+
if model.is_a?(CukeModeler::FeatureFile)
|
29
|
+
{ problem: problem_message, location: "#{model.path}" }
|
30
|
+
else
|
31
|
+
{ problem: problem_message, location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }
|
32
|
+
end
|
29
33
|
else
|
30
34
|
nil
|
31
35
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CukeLinter
|
2
|
+
|
3
|
+
# A linter that detects scenarios and outlines that have a bad name
|
4
|
+
|
5
|
+
class TestWithBadNameLinter < Linter
|
6
|
+
|
7
|
+
# The rule used to determine if a model has a problem
|
8
|
+
def rule(model)
|
9
|
+
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
|
10
|
+
|
11
|
+
lowercase_name = model.name.downcase
|
12
|
+
return true if lowercase_name.include?('test') ||
|
13
|
+
lowercase_name.include?('verif') ||
|
14
|
+
lowercase_name.include?('check')
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
# The message used to describe the problem that has been found
|
19
|
+
def message
|
20
|
+
'"Test", "Verify" and "Check" should not be used in scenario names.'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/cuke_linter/version.rb
CHANGED
data/lib/cuke_linter.rb
CHANGED
@@ -7,6 +7,7 @@ require 'cuke_linter/linters/linter'
|
|
7
7
|
require 'cuke_linter/linters/background_does_more_than_setup_linter'
|
8
8
|
require 'cuke_linter/linters/element_with_too_many_tags_linter'
|
9
9
|
require 'cuke_linter/linters/example_without_name_linter'
|
10
|
+
require 'cuke_linter/linters/feature_file_with_invalid_name_linter'
|
10
11
|
require 'cuke_linter/linters/feature_with_too_many_different_tags_linter'
|
11
12
|
require 'cuke_linter/linters/feature_without_name_linter'
|
12
13
|
require 'cuke_linter/linters/feature_without_description_linter'
|
@@ -17,6 +18,7 @@ require 'cuke_linter/linters/step_with_end_period_linter'
|
|
17
18
|
require 'cuke_linter/linters/step_with_too_many_characters_linter'
|
18
19
|
require 'cuke_linter/linters/test_should_use_background_linter'
|
19
20
|
require 'cuke_linter/linters/test_with_action_step_as_final_step_linter'
|
21
|
+
require 'cuke_linter/linters/test_with_bad_name_linter'
|
20
22
|
require 'cuke_linter/linters/test_with_no_action_step_linter'
|
21
23
|
require 'cuke_linter/linters/test_with_no_name_linter'
|
22
24
|
require 'cuke_linter/linters/test_with_no_verification_step_linter'
|
@@ -33,6 +35,7 @@ module CukeLinter
|
|
33
35
|
@original_linters = { 'BackgroundDoesMoreThanSetupLinter' => BackgroundDoesMoreThanSetupLinter.new,
|
34
36
|
'ElementWithTooManyTagsLinter' => ElementWithTooManyTagsLinter.new,
|
35
37
|
'ExampleWithoutNameLinter' => ExampleWithoutNameLinter.new,
|
38
|
+
'FeatureFileWithInvalidNameLinter' => FeatureFileWithInvalidNameLinter.new,
|
36
39
|
'FeatureWithTooManyDifferentTagsLinter' => FeatureWithTooManyDifferentTagsLinter.new,
|
37
40
|
'FeatureWithoutDescriptionLinter' => FeatureWithoutDescriptionLinter.new,
|
38
41
|
'FeatureWithoutNameLinter' => FeatureWithoutNameLinter.new,
|
@@ -43,6 +46,7 @@ module CukeLinter
|
|
43
46
|
'StepWithTooManyCharactersLinter' => StepWithTooManyCharactersLinter.new,
|
44
47
|
'TestShouldUseBackgroundLinter' => TestShouldUseBackgroundLinter.new,
|
45
48
|
'TestWithActionStepAsFinalStepLinter' => TestWithActionStepAsFinalStepLinter.new,
|
49
|
+
'TestWithBadNameLinter' => TestWithBadNameLinter.new,
|
46
50
|
'TestWithNoActionStepLinter' => TestWithNoActionStepLinter.new,
|
47
51
|
'TestWithNoNameLinter' => TestWithNoNameLinter.new,
|
48
52
|
'TestWithNoVerificationStepLinter' => TestWithNoVerificationStepLinter.new,
|
@@ -110,7 +114,7 @@ module CukeLinter
|
|
110
114
|
def self.lint(file_paths: [], model_trees: [], linters: self.registered_linters.values, formatters: [[CukeLinter::PrettyFormatter.new]])
|
111
115
|
|
112
116
|
# TODO: Test this?
|
113
|
-
# Because directive memoization is based on a model's `#object_id` and Ruby reuses object IDs over the
|
117
|
+
# Because directive memoization is based on a model's `#object_id` and Ruby reuses object IDs over the
|
114
118
|
# life of a program as objects are garbage collected, it is not safe to remember the IDs forever. However,
|
115
119
|
# models shouldn't get GC'd in the middle of the linting process and so the start of the linting process is
|
116
120
|
# a good time to reset things
|
@@ -11,6 +11,7 @@ Feature: Default Linters
|
|
11
11
|
| BackgroundDoesMoreThanSetupLinter |
|
12
12
|
| ElementWithTooManyTagsLinter |
|
13
13
|
| ExampleWithoutNameLinter |
|
14
|
+
| FeatureFileWithInvalidNameLinter |
|
14
15
|
| FeatureWithTooManyDifferentTagsLinter |
|
15
16
|
| FeatureWithoutDescriptionLinter |
|
16
17
|
| FeatureWithoutNameLinter |
|
@@ -21,6 +22,7 @@ Feature: Default Linters
|
|
21
22
|
| StepWithTooManyCharactersLinter |
|
22
23
|
| TestShouldUseBackgroundLinter |
|
23
24
|
| TestWithActionStepAsFinalStepLinter |
|
25
|
+
| TestWithBadNameLinter |
|
24
26
|
| TestWithNoActionStepLinter |
|
25
27
|
| TestWithNoNameLinter |
|
26
28
|
| TestWithNoVerificationStepLinter |
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: Feature file with invalid name linter
|
2
|
+
|
3
|
+
As a writer of documentation
|
4
|
+
I want to be warned about invalid file names
|
5
|
+
so that I name all features consistently
|
6
|
+
|
7
|
+
Scenario Outline: Linting
|
8
|
+
Given a feature file model named "<name>.feature"
|
9
|
+
And a linter for features with invalid file names
|
10
|
+
When it is linted
|
11
|
+
Then an error is reported:
|
12
|
+
| linter | problem | location |
|
13
|
+
| FeatureFileWithInvalidNameLinter | Feature files should be snake_cased. | <path_to_file> |
|
14
|
+
|
15
|
+
Examples: Invalid Names
|
16
|
+
| name |
|
17
|
+
| Lint |
|
18
|
+
| lintMe |
|
19
|
+
| lint me |
|
20
|
+
| lint-me |
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
Feature: Tests with bad names are reported
|
3
|
+
|
4
|
+
As a writer of documentation
|
5
|
+
I want to be warned about assertion style scenario names
|
6
|
+
So that I will be able to understand the intent
|
7
|
+
|
8
|
+
Scenario Outline: Flag a test with a bad name
|
9
|
+
|
10
|
+
Note: Also works on outlines.
|
11
|
+
|
12
|
+
Given a linter for tests with bad names
|
13
|
+
And the following feature:
|
14
|
+
"""
|
15
|
+
Feature: Bad scenario names
|
16
|
+
|
17
|
+
Scenario: <example_word> scenario name
|
18
|
+
This scenario uses a bad name
|
19
|
+
"""
|
20
|
+
When it is linted
|
21
|
+
Then an error is reported:
|
22
|
+
| linter | problem | location |
|
23
|
+
| TestWithBadNameLinter | "Test", "Verify" and "Check" should not be used in scenario names. | <path_to_file>:3 |
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
| example_word |
|
27
|
+
| test |
|
28
|
+
| verify |
|
29
|
+
| check |
|
@@ -25,6 +25,10 @@ Given(/^a linter for features without scenarios$/) do
|
|
25
25
|
@linter = CukeLinter::FeatureWithoutScenariosLinter.new
|
26
26
|
end
|
27
27
|
|
28
|
+
Given(/^a linter for features with invalid file names$/) do
|
29
|
+
@linter = CukeLinter::FeatureFileWithInvalidNameLinter.new
|
30
|
+
end
|
31
|
+
|
28
32
|
Given(/^no other linters have been registered or unregistered$/) do
|
29
33
|
CukeLinter.reset_linters
|
30
34
|
end
|
@@ -37,6 +41,10 @@ Given(/^a linter for outlines with only one example row$/) do
|
|
37
41
|
@linter = CukeLinter::OutlineWithSingleExampleRowLinter.new
|
38
42
|
end
|
39
43
|
|
44
|
+
Given("a linter for tests with bad names") do
|
45
|
+
@linter = CukeLinter::TestWithBadNameLinter.new
|
46
|
+
end
|
47
|
+
|
40
48
|
Given(/^a linter for tests with too many steps$/) do
|
41
49
|
@linter = CukeLinter::TestWithTooManyStepsLinter.new
|
42
50
|
end
|
@@ -189,3 +197,9 @@ And(/^a feature file model based on the following text:$/) do |text|
|
|
189
197
|
|
190
198
|
@model = CukeModeler::FeatureFile.new(file_path)
|
191
199
|
end
|
200
|
+
|
201
|
+
Given(/^a feature file model named "([^"]*)"$/) do |file_path|
|
202
|
+
@model = CukeModeler::FeatureFile.new
|
203
|
+
|
204
|
+
@model.path = file_path
|
205
|
+
end
|
@@ -15,10 +15,18 @@ Then(/^the resulting output will include the following:$/) do |text|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Then(/^an error is reported:$/) do |table|
|
18
|
+
if @model.is_a?(CukeModeler::FeatureFile)
|
19
|
+
model_path = @model.path
|
20
|
+
model_source_line = ''
|
21
|
+
else
|
22
|
+
model_path = @model.get_ancestor(:feature_file).path
|
23
|
+
model_source_line = @model.source_line.to_s
|
24
|
+
end
|
25
|
+
|
18
26
|
table.hashes.each do |error_record|
|
19
27
|
expect(@results).to include({ linter: error_record['linter'],
|
20
28
|
problem: error_record['problem'],
|
21
|
-
location: error_record['location'].sub('<path_to_file>',
|
29
|
+
location: error_record['location'].sub('<path_to_file>', model_path).sub('<model_line_number>', model_source_line) })
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
data/testing/model_factory.rb
CHANGED
@@ -27,6 +27,12 @@ module CukeLinter
|
|
27
27
|
model
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.generate_feature_file_model
|
31
|
+
model = CukeModeler::FeatureFile.new
|
32
|
+
|
33
|
+
model
|
34
|
+
end
|
35
|
+
|
30
36
|
def self.generate_example_model(source_text: 'Examples:', parent_file_path: 'path_to_file')
|
31
37
|
fake_parent_model = generate_outline_model(parent_file_path: parent_file_path)
|
32
38
|
|
@@ -174,46 +174,37 @@ RSpec.describe CukeLinter do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'has a default set of registered linters' do
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
expect(subject.registered_linters
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
expect(subject.registered_linters['TestWithNoVerificationStepLinter']).to be_a(CukeLinter::TestWithNoVerificationStepLinter)
|
209
|
-
expect(subject.registered_linters.keys).to include('TestWithSetupStepAfterActionStepLinter')
|
210
|
-
expect(subject.registered_linters['TestWithSetupStepAfterActionStepLinter']).to be_a(CukeLinter::TestWithSetupStepAfterActionStepLinter)
|
211
|
-
expect(subject.registered_linters.keys).to include('TestWithSetupStepAfterVerificationStepLinter')
|
212
|
-
expect(subject.registered_linters['TestWithSetupStepAfterVerificationStepLinter']).to be_a(CukeLinter::TestWithSetupStepAfterVerificationStepLinter)
|
213
|
-
expect(subject.registered_linters.keys).to include('TestWithSetupStepAsFinalStepLinter')
|
214
|
-
expect(subject.registered_linters['TestWithSetupStepAsFinalStepLinter']).to be_a(CukeLinter::TestWithSetupStepAsFinalStepLinter)
|
215
|
-
expect(subject.registered_linters.keys).to include('TestWithTooManyStepsLinter')
|
216
|
-
expect(subject.registered_linters['TestWithTooManyStepsLinter']).to be_a(CukeLinter::TestWithTooManyStepsLinter)
|
177
|
+
subject.reset_linters
|
178
|
+
|
179
|
+
default_linter_classes = ['BackgroundDoesMoreThanSetupLinter',
|
180
|
+
'ElementWithTooManyTagsLinter',
|
181
|
+
'ExampleWithoutNameLinter',
|
182
|
+
'FeatureFileWithInvalidNameLinter',
|
183
|
+
'FeatureWithTooManyDifferentTagsLinter',
|
184
|
+
'FeatureWithoutDescriptionLinter',
|
185
|
+
'FeatureWithoutNameLinter',
|
186
|
+
'FeatureWithoutScenariosLinter',
|
187
|
+
'OutlineWithSingleExampleRowLinter',
|
188
|
+
'SingleTestBackgroundLinter',
|
189
|
+
'StepWithEndPeriodLinter',
|
190
|
+
'StepWithTooManyCharactersLinter',
|
191
|
+
'TestShouldUseBackgroundLinter',
|
192
|
+
'TestWithActionStepAsFinalStepLinter',
|
193
|
+
'TestWithBadNameLinter',
|
194
|
+
'TestWithNoActionStepLinter',
|
195
|
+
'TestWithNoNameLinter',
|
196
|
+
'TestWithNoVerificationStepLinter',
|
197
|
+
'TestWithSetupStepAfterActionStepLinter',
|
198
|
+
'TestWithSetupStepAfterVerificationStepLinter',
|
199
|
+
'TestWithSetupStepAsFinalStepLinter',
|
200
|
+
'TestWithTooManyStepsLinter']
|
201
|
+
|
202
|
+
expect(subject.registered_linters.keys).to eq(default_linter_classes)
|
203
|
+
|
204
|
+
default_linter_classes.each do |clazz|
|
205
|
+
expect(subject.registered_linters[clazz]).to be_a(CukeLinter.const_get(clazz))
|
206
|
+
|
207
|
+
end
|
217
208
|
end
|
218
209
|
|
219
210
|
it 'returns to its default set of linters after being reset' do
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative '../../../../../environments/rspec_env'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe CukeLinter::FeatureFileWithInvalidNameLinter 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('FeatureFileWithInvalidNameLinter')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'linting' do
|
16
|
+
|
17
|
+
it "only lints the file name" do
|
18
|
+
test_model = CukeLinter::ModelFactory.generate_feature_file_model
|
19
|
+
test_model.path = 'bad-directory/good_file.feature'
|
20
|
+
|
21
|
+
expect(subject.lint(test_model)).to be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with a feature file model that has an invalid file name" do
|
25
|
+
|
26
|
+
let(:test_model) do
|
27
|
+
model = CukeLinter::ModelFactory.generate_feature_file_model
|
28
|
+
|
29
|
+
model.path = model_file_path
|
30
|
+
model
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'because its file name is capitalized' do
|
34
|
+
let(:model_file_path) { 'Terrible' }
|
35
|
+
|
36
|
+
it_should_behave_like 'a linter linting a bad model'
|
37
|
+
|
38
|
+
it 'records a problem' do
|
39
|
+
result = subject.lint(test_model)
|
40
|
+
|
41
|
+
expect(result[:problem]).to eq('Feature files should be snake_cased.')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'because its file name is camel-cased' do
|
46
|
+
let(:model_file_path) { 'veryBad' }
|
47
|
+
|
48
|
+
it_should_behave_like 'a linter linting a bad model'
|
49
|
+
|
50
|
+
it 'records a problem' do
|
51
|
+
result = subject.lint(test_model)
|
52
|
+
|
53
|
+
expect(result[:problem]).to eq('Feature files should be snake_cased.')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'because its file name contains whitespace' do
|
58
|
+
let(:model_file_path) { 'stop this' }
|
59
|
+
|
60
|
+
it_should_behave_like 'a linter linting a bad model'
|
61
|
+
|
62
|
+
it 'records a problem' do
|
63
|
+
result = subject.lint(test_model)
|
64
|
+
|
65
|
+
expect(result[:problem]).to eq('Feature files should be snake_cased.')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'because its file name is hyphenated' do
|
70
|
+
let(:model_file_path) { 'the-worst-path' }
|
71
|
+
|
72
|
+
it_should_behave_like 'a linter linting a bad model'
|
73
|
+
|
74
|
+
it 'records a problem' do
|
75
|
+
result = subject.lint(test_model)
|
76
|
+
|
77
|
+
expect(result[:problem]).to eq('Feature files should be snake_cased.')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with a feature file model that does have a valid file name" do
|
84
|
+
|
85
|
+
let(:test_model) do
|
86
|
+
model = CukeLinter::ModelFactory.generate_feature_file_model
|
87
|
+
|
88
|
+
model.path = 'very_good_path'
|
89
|
+
model
|
90
|
+
end
|
91
|
+
|
92
|
+
it_should_behave_like 'a linter linting a good model'
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'a non-test model' do
|
97
|
+
|
98
|
+
let(:test_model) { CukeModeler::Model.new }
|
99
|
+
|
100
|
+
it_should_behave_like 'a linter linting a good model'
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -40,13 +40,18 @@ shared_examples_for 'a linter linting a bad model' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'correctly records the location of the problem' do
|
43
|
-
test_model.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
if test_model.is_a?(CukeModeler::FeatureFile)
|
44
|
+
result = subject.lint(test_model)
|
45
|
+
expect(result[:location]).to eq("#{model_file_path}")
|
46
|
+
else
|
47
|
+
test_model.source_line = 1
|
48
|
+
result = subject.lint(test_model)
|
49
|
+
expect(result[:location]).to eq("#{model_file_path}:1")
|
50
|
+
|
51
|
+
test_model.source_line = 3
|
52
|
+
result = subject.lint(test_model)
|
53
|
+
expect(result[:location]).to eq("#{model_file_path}:3")
|
54
|
+
end
|
50
55
|
end
|
51
56
|
|
52
57
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative '../../../../../environments/rspec_env'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe CukeLinter::TestWithBadNameLinter 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('TestWithBadNameLinter')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'linting' do
|
16
|
+
|
17
|
+
['scenario', 'outline'].each do |model_type|
|
18
|
+
|
19
|
+
context "with a #{model_type} that has a bad name" do
|
20
|
+
|
21
|
+
context 'because its name contains a bad word' do
|
22
|
+
|
23
|
+
['test', 'check', 'verify'].each do |bad_word|
|
24
|
+
|
25
|
+
let(:test_model) do
|
26
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
27
|
+
model.name = "#{bad_word} bad names are reported"
|
28
|
+
|
29
|
+
model
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like 'a linter linting a bad model'
|
33
|
+
|
34
|
+
it 'records a problem' do
|
35
|
+
result = subject.lint(test_model)
|
36
|
+
|
37
|
+
expect(result[:problem]).to eq('"Test", "Verify" and "Check" should not be used in scenario names.')
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'because bad words are case insensitive' do
|
43
|
+
|
44
|
+
['Test', 'TEST'].each do |bad_word|
|
45
|
+
|
46
|
+
let(:test_model) do
|
47
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
48
|
+
model.name = "#{bad_word} bad names are reported"
|
49
|
+
|
50
|
+
model
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like 'a linter linting a bad model'
|
54
|
+
|
55
|
+
it 'records a problem' do
|
56
|
+
result = subject.lint(test_model)
|
57
|
+
|
58
|
+
expect(result[:problem]).to eq('"Test", "Verify" and "Check" should not be used in scenario names.')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'a non-test model' do
|
68
|
+
|
69
|
+
let(:test_model) { CukeModeler::Model.new }
|
70
|
+
|
71
|
+
it_should_behave_like 'a linter linting a good model'
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuke_linter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuke_modeler
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/cuke_linter/linters/background_does_more_than_setup_linter.rb
|
181
181
|
- lib/cuke_linter/linters/element_with_too_many_tags_linter.rb
|
182
182
|
- lib/cuke_linter/linters/example_without_name_linter.rb
|
183
|
+
- lib/cuke_linter/linters/feature_file_with_invalid_name_linter.rb
|
183
184
|
- lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb
|
184
185
|
- lib/cuke_linter/linters/feature_without_description_linter.rb
|
185
186
|
- lib/cuke_linter/linters/feature_without_name_linter.rb
|
@@ -191,6 +192,7 @@ files:
|
|
191
192
|
- lib/cuke_linter/linters/step_with_too_many_characters_linter.rb
|
192
193
|
- lib/cuke_linter/linters/test_should_use_background_linter.rb
|
193
194
|
- lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb
|
195
|
+
- lib/cuke_linter/linters/test_with_bad_name_linter.rb
|
194
196
|
- lib/cuke_linter/linters/test_with_no_action_step_linter.rb
|
195
197
|
- lib/cuke_linter/linters/test_with_no_name_linter.rb
|
196
198
|
- lib/cuke_linter/linters/test_with_no_verification_step_linter.rb
|
@@ -209,6 +211,7 @@ files:
|
|
209
211
|
- testing/cucumber/features/linters/background_does_more_than_setup.feature
|
210
212
|
- testing/cucumber/features/linters/element_with_too_many_tags.feature
|
211
213
|
- testing/cucumber/features/linters/example_without_name.feature
|
214
|
+
- testing/cucumber/features/linters/feature_file_with_invalid_name.feature
|
212
215
|
- testing/cucumber/features/linters/feature_with_too_many_different_tags.feature
|
213
216
|
- testing/cucumber/features/linters/feature_without_description.feature
|
214
217
|
- testing/cucumber/features/linters/feature_without_name.feature
|
@@ -219,6 +222,7 @@ files:
|
|
219
222
|
- testing/cucumber/features/linters/step_with_end_period.feature
|
220
223
|
- testing/cucumber/features/linters/test_should_use_background.feature
|
221
224
|
- testing/cucumber/features/linters/test_with_action_as_final_step.feature
|
225
|
+
- testing/cucumber/features/linters/test_with_bad_name.feature
|
222
226
|
- testing/cucumber/features/linters/test_with_no_action_step.feature
|
223
227
|
- testing/cucumber/features/linters/test_with_no_name.feature
|
224
228
|
- testing/cucumber/features/linters/test_with_no_verification_step.feature
|
@@ -241,6 +245,7 @@ files:
|
|
241
245
|
- testing/rspec/spec/integration/linters/background_does_more_than_setup_linter_integration_spec.rb
|
242
246
|
- testing/rspec/spec/integration/linters/element_with_too_many_tags_linter_integration_spec.rb
|
243
247
|
- testing/rspec/spec/integration/linters/example_without_name_linter_integration_spec.rb
|
248
|
+
- testing/rspec/spec/integration/linters/feature_file_with_invalid_name_integration_spec.rb
|
244
249
|
- testing/rspec/spec/integration/linters/feature_with_too_many_different_tags_linter_integration_spec.rb
|
245
250
|
- testing/rspec/spec/integration/linters/feature_without_description_linter_integration_spec.rb
|
246
251
|
- testing/rspec/spec/integration/linters/feature_without_name_linter_integration_spec.rb
|
@@ -253,6 +258,7 @@ files:
|
|
253
258
|
- testing/rspec/spec/integration/linters/step_with_too_many_characters_linter_integration_spec.rb
|
254
259
|
- testing/rspec/spec/integration/linters/test_should_use_background_linter_integration_spec.rb
|
255
260
|
- testing/rspec/spec/integration/linters/test_with_action_step_as_final_step_linter_integration_spec.rb
|
261
|
+
- testing/rspec/spec/integration/linters/test_with_bad_name_integration_spec.rb
|
256
262
|
- testing/rspec/spec/integration/linters/test_with_no_action_step_integration_spec.rb
|
257
263
|
- testing/rspec/spec/integration/linters/test_with_no_name_integration_spec.rb
|
258
264
|
- testing/rspec/spec/integration/linters/test_with_no_verification_step_integration_spec.rb
|
@@ -267,6 +273,7 @@ files:
|
|
267
273
|
- testing/rspec/spec/unit/linters/configurable_linter_unit_specs.rb
|
268
274
|
- testing/rspec/spec/unit/linters/element_with_too_many_tags_linter_unit_spec.rb
|
269
275
|
- testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb
|
276
|
+
- testing/rspec/spec/unit/linters/feature_file_with_invalid_name_linter_unit_spec.rb
|
270
277
|
- testing/rspec/spec/unit/linters/feature_with_too_many_different_tags_linter_unit_spec.rb
|
271
278
|
- testing/rspec/spec/unit/linters/feature_without_description_linter_unit_spec.rb
|
272
279
|
- testing/rspec/spec/unit/linters/feature_without_name_linter_unit_spec.rb
|
@@ -279,6 +286,7 @@ files:
|
|
279
286
|
- testing/rspec/spec/unit/linters/step_with_too_many_characters_linter_unit_spec.rb
|
280
287
|
- testing/rspec/spec/unit/linters/test_should_use_background_linter_unit_spec.rb
|
281
288
|
- testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb
|
289
|
+
- testing/rspec/spec/unit/linters/test_with_bad_name_linter_unit_spec.rb
|
282
290
|
- testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb
|
283
291
|
- testing/rspec/spec/unit/linters/test_with_no_name_linter_unit_spec.rb
|
284
292
|
- testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb
|