Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
enkessler committed Mar 2, 2020
2 parents 04e3fcd + b1ed7bf commit 9b82bc4
Show file tree
Hide file tree
Showing 26 changed files with 949 additions and 21 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Nothing yet...

## [0.13.0] - 2020-03-01

### Added
- Added the ability to configure relevant keywords for linters whose behavior is impacted by the dialect in which feature files are written.
- BackgroundDoesMoreThanSetupLinter
- TestWithActionStepAsFinalStepLinter
- TestWithNoActionStepLinter
- TestWithNoVerificationStepLinter
- TestWithSetupStepAfterActionStepLinter
- TestWithSetupStepAfterVerificationStepLinter
- TestWithSetupStepAsFinalStepLinter


## [0.12.1] - 2020-02-15

Expand Down Expand Up @@ -135,7 +147,8 @@ Nothing yet...
- Custom linters, formatters, and command line usability


[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.12.1...HEAD
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.13.0...HEAD
[0.13.0]: https://github.com/enkessler/cuke_linter/compare/v0.12.1...v0.13.0
[0.12.1]: https://github.com/enkessler/cuke_linter/compare/v0.12.0...v0.12.1
[0.12.0]: https://github.com/enkessler/cuke_linter/compare/v0.11.1...v0.12.0
[0.11.1]: https://github.com/enkessler/cuke_linter/compare/v0.11.0...v0.11.1
Expand Down
4 changes: 4 additions & 0 deletions lib/cuke_linter.rb
Expand Up @@ -35,6 +35,10 @@

module CukeLinter

DEFAULT_GIVEN_KEYWORD = 'Given'.freeze
DEFAULT_WHEN_KEYWORD = 'When'.freeze
DEFAULT_THEN_KEYWORD = 'Then'.freeze

@original_linters = { 'BackgroundDoesMoreThanSetupLinter' => BackgroundDoesMoreThanSetupLinter.new,
'ElementWithCommonTagsLinter' => ElementWithCommonTagsLinter.new,
'ElementWithDuplicateTagsLinter' => ElementWithDuplicateTagsLinter.new,
Expand Down
Expand Up @@ -4,17 +4,33 @@ module CukeLinter

class BackgroundDoesMoreThanSetupLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@when_keywords = options['When']
@then_keywords = options['Then']
end

# The rule used to determine if a model has a problem
def rule(model)
return false unless model.is_a?(CukeModeler::Background)

model.steps.collect(&:keyword).any? { |keyword| (keyword == 'When') || (keyword == 'Then') }
model.steps.collect(&:keyword).any? { |keyword| when_keywords.include?(keyword) || then_keywords.include?(keyword) }
end

# The message used to describe the problem that has been found
def message
'Background has non-setup steps'
end

private

def when_keywords
@when_keywords || [DEFAULT_WHEN_KEYWORD]
end

def then_keywords
@then_keywords || [DEFAULT_THEN_KEYWORD]
end

end
end
Expand Up @@ -4,20 +4,31 @@ module CukeLinter

class TestWithActionStepAsFinalStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@when_keywords = options['When']
end

# 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'
when_keywords.include?(model_steps.last.keyword)
end

# The message used to describe the problem that has been found
def message
"Test has 'When' as the final step."
end

private

def when_keywords
@when_keywords || [DEFAULT_WHEN_KEYWORD]
end

end
end
13 changes: 12 additions & 1 deletion lib/cuke_linter/linters/test_with_no_action_step_linter.rb
Expand Up @@ -4,20 +4,31 @@ module CukeLinter

class TestWithNoActionStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@when_keywords = options['When']
end

# 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 || []
background_steps = model.parent_model.has_background? ? model.parent_model.background.steps || [] : []
all_steps = model_steps + background_steps
all_steps.none? { |step| step.keyword == 'When' }
all_steps.none? { |step| when_keywords.include?(step.keyword) }
end

# The message used to describe the problem that has been found
def message
"Test does not have a 'When' step."
end

private

def when_keywords
@when_keywords || [DEFAULT_WHEN_KEYWORD]
end

end
end
13 changes: 12 additions & 1 deletion lib/cuke_linter/linters/test_with_no_verification_step_linter.rb
Expand Up @@ -4,20 +4,31 @@ module CukeLinter

class TestWithNoVerificationStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@then_keywords = options['Then']
end

# 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 || []
background_steps = model.parent_model.has_background? ? model.parent_model.background.steps || [] : []
all_steps = model_steps + background_steps
all_steps.none? { |step| step.keyword == 'Then' }
all_steps.none? { |step| then_keywords.include?(step.keyword) }
end

# The message used to describe the problem that has been found
def message
"Test does not have a 'Then' step."
end

private

def then_keywords
@then_keywords || [DEFAULT_THEN_KEYWORD]
end

end
end
Expand Up @@ -4,6 +4,12 @@ module CukeLinter

class TestWithSetupStepAfterActionStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@given_keywords = options['Given']
@when_keywords = options['When']
end

# 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)
Expand All @@ -13,9 +19,9 @@ def rule(model)

model_steps.each do |step|
if action_step_found
return true if step.keyword == 'Given'
return true if given_keywords.include?(step.keyword)
else
action_step_found = step.keyword == 'When'
action_step_found = when_keywords.include?(step.keyword)
end
end

Expand All @@ -27,5 +33,15 @@ def message
"Test has 'Given' step after 'When' step."
end

private

def given_keywords
@given_keywords || [DEFAULT_GIVEN_KEYWORD]
end

def when_keywords
@when_keywords || [DEFAULT_WHEN_KEYWORD]
end

end
end
Expand Up @@ -4,6 +4,12 @@ module CukeLinter

class TestWithSetupStepAfterVerificationStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@given_keywords = options['Given']
@then_keywords = options['Then']
end

# 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)
Expand All @@ -13,9 +19,9 @@ def rule(model)

model_steps.each do |step|
if verification_step_found
return true if step.keyword == 'Given'
return true if given_keywords.include?(step.keyword)
else
verification_step_found = step.keyword == 'Then'
verification_step_found = then_keywords.include?(step.keyword)
end
end

Expand All @@ -27,5 +33,15 @@ def message
"Test has 'Given' step after 'Then' step."
end

private

def given_keywords
@given_keywords || [DEFAULT_GIVEN_KEYWORD]
end

def then_keywords
@then_keywords || [DEFAULT_THEN_KEYWORD]
end

end
end
Expand Up @@ -4,20 +4,31 @@ module CukeLinter

class TestWithSetupStepAsFinalStepLinter < Linter

# Changes the linting settings on the linter using the provided configuration
def configure(options)
@given_keywords = options['Given']
end

# 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'
given_keywords.include?(model_steps.last.keyword)
end

# The message used to describe the problem that has been found
def message
"Test has 'Given' as the final step."
end

private

def given_keywords
@given_keywords || [DEFAULT_GIVEN_KEYWORD]
end

end
end
2 changes: 1 addition & 1 deletion lib/cuke_linter/version.rb
@@ -1,4 +1,4 @@
module CukeLinter
# The release version of this gem
VERSION = '0.12.1'
VERSION = '0.13.0'
end
Expand Up @@ -48,3 +48,37 @@ Feature: Background does more than setup linter
"""
When it is linted
Then no error is reported

Scenario Outline: Configuration of keywords for different dialect
Given a linter for backgrounds that do more than setup has been registered
And the following configuration file:
"""
BackgroundDoesMoreThanSetupLinter:
Given:
- Dado
When:
- Quando
Then:
- Então
- Entao
"""
And the following feature:
"""
# language:pt
Funcionalidade: Feature name
Contexto: A Background in pt dialect
Dado some setup in pt dialect
<step>
"""
When the configuration file is loaded
And it is linted
Then an error is reported:
| linter | problem | location |
| BackgroundDoesMoreThanSetupLinter | Background has non-setup steps | <path_to_file>:4 |

Examples:
| step |
| Quando this is an action in pt dialect |
| Então this is a validation in pt dialect |
| Entao this is also a validation in pt dialect |
Expand Up @@ -22,7 +22,29 @@ Feature: Test with action step as final step linter
| linter | problem | location |
| TestWithActionStepAsFinalStepLinter | Test has 'When' as the final step. | <path_to_file>:3 |

@wip
Scenario: Configuration
Scenario: Configuration of keywords for different dialect
Given a linter for tests with an action step as the final step has been registered
And the following configuration file:
"""
TestWithActionStepAsFinalStepLinter:
Given:
- Dado
When:
- Quando
- '*'
Then:
- Então
"""
And the following feature:
"""
# language:pt
Funcionalidade: Feature name
Configure the keyword(s) that count as action steps?
Cenário: scenario name
Quando this is an action in pt dialect
"""
When the configuration file is loaded
And it is linted
Then an error is reported:
| linter | problem | location |
| TestWithActionStepAsFinalStepLinter | Test has 'When' as the final step. | <path_to_file>:4 |

0 comments on commit 9b82bc4

Please sign in to comment.