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
53 changed files
with
1,849 additions
and
734 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Development | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake cuke_linter:test_everything` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
|
||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/enkessler/cuke_linter. | ||
|
||
1. Fork it | ||
2. Create your feature branch **(off of the development branch)** | ||
`git checkout -b my-new-feature dev` | ||
3. Commit your changes | ||
`git commit -am 'Add some feature'` | ||
4. Push to the branch | ||
`git push origin my-new-feature` | ||
5. Create new Pull Request | ||
|
||
|
||
### Adding a new linter | ||
|
||
Some guidelines when adding a new linter | ||
* Inherit from the base linter class. It will handle almost all of the functional requirements of a linter. | ||
* Existing linters should provide decent examples of how to create new linters and how to test them. A copy/paste/tweak approach is perfectly valid. | ||
* Keep linters simple. Rather than have one linter that has different behaviors depending on context, create a different linter class for each context. | ||
* Keep things alphabetical. There are going to be lots of linters and things will be easier to find if lists of them in the code base (e.g. `require` statments, documentation, etc.) are in an intuitive order. |
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
38 changes: 38 additions & 0 deletions
38
lib/cuke_linter/linters/feature_with_too_many_different_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,38 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects features that contain too many different tags | ||
|
||
class FeatureWithTooManyDifferentTagsLinter < Linter | ||
|
||
# Changes the linting settings on the linter using the provided configuration | ||
def configure(options) | ||
@tag_threshold = options['TagCountThreshold'] | ||
end | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Feature) | ||
|
||
tags = model.tags | ||
|
||
model.each_descendant do |descendant_model| | ||
if descendant_model.respond_to?(:tags) | ||
tags.concat(descendant_model.tags) | ||
end | ||
end | ||
|
||
tags = tags.collect(&:name).uniq | ||
|
||
@linted_tag_threshold = @tag_threshold || 10 | ||
@linted_tag_count = tags.count | ||
|
||
@linted_tag_count > @linted_tag_threshold | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
"Feature contains too many different tags. #{@linted_tag_count} tags found (max #{@linted_tag_threshold})." | ||
end | ||
|
||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/cuke_linter/linters/test_should_use_background_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,28 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects scenarios and outlines within a feature that all share common beginning steps | ||
|
||
class TestShouldUseBackgroundLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline) | ||
|
||
model_steps = model.steps || [] | ||
parent_feature_model = model.get_ancestor(:feature) | ||
|
||
return false unless parent_feature_model.tests.count > 1 | ||
|
||
parent_feature_model.tests.all? do |test| | ||
test_steps = test.steps || [] | ||
test_steps.first == model_steps.first | ||
end | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
'Test shares steps with all other tests in feature. Use a background.' | ||
end | ||
|
||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/cuke_linter/linters/test_with_action_step_as_final_step_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,23 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects scenarios and outlines that have an action step as their final step | ||
|
||
class TestWithActionStepAsFinalStepLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline) | ||
|
||
model_steps = model.steps || [] | ||
return false unless model_steps.last | ||
|
||
model_steps.last.keyword == 'When' | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
"Test has 'When' as the final step." | ||
end | ||
|
||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/cuke_linter/linters/test_with_setup_step_after_action_step_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,31 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects scenarios and outlines that have a setup step that comes after an action step | ||
|
||
class TestWithSetupStepAfterActionStepLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline) | ||
|
||
model_steps = model.steps || [] | ||
action_step_found = false | ||
|
||
model_steps.each do |step| | ||
if action_step_found | ||
return true if step.keyword == 'Given' | ||
else | ||
action_step_found = step.keyword == 'When' | ||
end | ||
end | ||
|
||
false | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
"Test has 'Given' step after 'When' step." | ||
end | ||
|
||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/cuke_linter/linters/test_with_setup_step_after_verification_step_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,31 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects scenarios and outlines that have a setup step that comes after a verification step | ||
|
||
class TestWithSetupStepAfterVerificationStepLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline) | ||
|
||
model_steps = model.steps || [] | ||
verification_step_found = false | ||
|
||
model_steps.each do |step| | ||
if verification_step_found | ||
return true if step.keyword == 'Given' | ||
else | ||
verification_step_found = step.keyword == 'Then' | ||
end | ||
end | ||
|
||
false | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
"Test has 'Given' step after 'Then' step." | ||
end | ||
|
||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/cuke_linter/linters/test_with_setup_step_as_final_step_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,23 @@ | ||
module CukeLinter | ||
|
||
# A linter that detects scenarios and outlines that have a setup step as their final step | ||
|
||
class TestWithSetupStepAsFinalStepLinter < Linter | ||
|
||
# The rule used to determine if a model has a problem | ||
def rule(model) | ||
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline) | ||
|
||
model_steps = model.steps || [] | ||
return false unless model_steps.last | ||
|
||
model_steps.last.keyword == 'Given' | ||
end | ||
|
||
# The message used to describe the problem that has been found | ||
def message | ||
"Test has 'Given' as the final step." | ||
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.9.0" | ||
VERSION = '0.10.0' | ||
end |
Oops, something went wrong.