Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
971 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/cuke_linter/linters/element_with_common_tags_linter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects Gherkin elements that have the same tag on all of their taggable child elements | ||
|
||
class ElementWithCommonTagsLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Feature) || model.is_a?(CukeModeler::Outline) | ||
|
||
@linted_model_class = model.class | ||
|
||
child_accessor_method = model.is_a?(CukeModeler::Feature) ? :tests : :examples | ||
child_models = model.send(child_accessor_method) || [] | ||
|
||
tag_sets = child_models.collect { |child_model| child_model.tags || [] } | ||
tag_name_sets = tag_sets.collect { |tags| tags.map(&:name) } | ||
|
||
return false if tag_name_sets.count < 2 | ||
|
||
@common_tag = tag_name_sets.reduce(:&).first | ||
|
||
!@common_tag.nil? | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
class_name = @linted_model_class.name.split('::').last | ||
|
||
case class_name | ||
when 'Feature' | ||
"All tests in #{class_name} have tag '#{@common_tag}'. Move tag to #{class_name} level." | ||
when 'Outline' | ||
"All Examples in #{class_name} have tag '#{@common_tag}'. Move tag to #{class_name} level." | ||
else | ||
raise("Linted an unexpected model type '#{class_name}'!") | ||
end | ||
end | ||
|
||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects taggable Gherkin elements that have duplicate tags | ||
|
||
class ElementWithDuplicateTagsLinter < Linter | ||
|
||
# Changes the linting settings on the linter using the provided configuration | ||
def configure(options) | ||
@tag_inheritance = options['IncludeInheritedTags'] | ||
end | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Feature) || | ||
model.is_a?(CukeModeler::Scenario) || | ||
model.is_a?(CukeModeler::Outline) || | ||
model.is_a?(CukeModeler::Example) | ||
|
||
|
||
@linted_model_class = model.class | ||
|
||
if @tag_inheritance | ||
relevant_tags = model.all_tags | ||
else | ||
relevant_tags = model.tags || [] | ||
end | ||
|
||
|
||
tag_names = relevant_tags.map(&:name) | ||
|
||
@duplicate_tag = tag_names.find { |tag| tag_names.count(tag) > 1 } | ||
|
||
!@duplicate_tag.nil? | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
class_name = @linted_model_class.name.split('::').last | ||
|
||
"#{class_name} has duplicate tag '#{@duplicate_tag}'." | ||
end | ||
|
||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
lib/cuke_linter/linters/feature_file_with_mismatched_name_linter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects mismatched feature file names | ||
|
||
class FeatureFileWithMismatchedNameLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::FeatureFile) | ||
|
||
file_name = File.basename(model.path, '.feature') | ||
feature_name = model.feature.name | ||
|
||
normalized_file_name = file_name.downcase.delete('_ -') | ||
normalized_feature_name = feature_name.downcase.delete('_ -') | ||
|
||
normalized_file_name != normalized_feature_name | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
'Feature file name does not match feature name.' | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module CukeLinter | ||
# The release version of this gem | ||
VERSION = '0.11.1' | ||
VERSION = '0.12.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
testing/cucumber/features/linters/element_with_common_tags.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Feature: Element with common tags linter | ||
|
||
As a writer of documentation | ||
I want taggable elements to not needlessly have the same tags | ||
So that redundancy is minimized | ||
|
||
|
||
Scenario: Linting | ||
|
||
Note: Also works on outlines that have common tags on their examples | ||
|
||
Given a linter for elements with common tags | ||
And the following feature: | ||
""" | ||
Feature: | ||
@same_tag | ||
Scenario: | ||
* a step | ||
@same_tag | ||
Scenario: | ||
* a step | ||
""" | ||
When it is linted | ||
Then an error is reported: | ||
| linter | problem | location | | ||
| ElementWithCommonTagsLinter | All tests in Feature have tag '@same_tag'. Move tag to Feature level. | <path_to_file>:1 | |
Oops, something went wrong.