cuke_linter 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/lib/cuke_linter.rb +4 -0
  4. data/lib/cuke_linter/linters/background_does_more_than_setup_linter.rb +17 -1
  5. data/lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb +12 -1
  6. data/lib/cuke_linter/linters/test_with_no_action_step_linter.rb +12 -1
  7. data/lib/cuke_linter/linters/test_with_no_verification_step_linter.rb +12 -1
  8. data/lib/cuke_linter/linters/test_with_setup_step_after_action_step_linter.rb +18 -2
  9. data/lib/cuke_linter/linters/test_with_setup_step_after_verification_step_linter.rb +18 -2
  10. data/lib/cuke_linter/linters/test_with_setup_step_as_final_step_linter.rb +12 -1
  11. data/lib/cuke_linter/version.rb +1 -1
  12. data/testing/cucumber/features/linters/background_does_more_than_setup.feature +34 -0
  13. data/testing/cucumber/features/linters/test_with_action_as_final_step.feature +25 -3
  14. data/testing/cucumber/features/linters/test_with_no_action_step.feature +27 -1
  15. data/testing/cucumber/features/linters/test_with_no_verification_step.feature +28 -1
  16. data/testing/cucumber/features/linters/test_with_setup_step_after_action_step.feature +28 -1
  17. data/testing/cucumber/features/linters/test_with_setup_step_after_verification_step.feature +28 -1
  18. data/testing/cucumber/features/linters/test_with_setup_step_as_final_step.feature +25 -3
  19. data/testing/cucumber/step_definitions/setup_steps.rb +28 -0
  20. data/testing/rspec/spec/unit/cuke_linter_unit_spec.rb +12 -0
  21. data/testing/rspec/spec/unit/linters/background_does_more_than_setup_linter_unit_spec.rb +109 -0
  22. data/testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb +67 -0
  23. data/testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb +68 -0
  24. data/testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb +67 -0
  25. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_action_step_linter_unit_spec.rb +109 -0
  26. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_verification_step_linter_unit_spec.rb +108 -0
  27. data/testing/rspec/spec/unit/linters/test_with_setup_step_as_final_step_linter_unit_spec.rb +66 -0
  28. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 670cec37df02d865f45baf856baab441942d1dd54f8b39089b88fd4657afc098
4
- data.tar.gz: 840623e9e37f4f38ac3d5f1f28332b77f759b77a8dd3aa12a9554ede015ccddb
3
+ metadata.gz: 7669fb1b66c4e9c103aedb209961dbeca8b308f74bcc1159401fa21e1ffd5b05
4
+ data.tar.gz: 36ef3927bc68e7d52bde3c91f26ab0428d07b81c7163c0c31aaabf2847fa78db
5
5
  SHA512:
6
- metadata.gz: 96beaf4a96234000319d61976ee7b19de8fe0c4d5a83583d0cd3fa33579078cbfce40eac96e52302423c69266db8cc0d3582263a1b913674a741142ee044f0bc
7
- data.tar.gz: b21f8016215c971dcff8565232c3e078c9e2f0f6a4421c554e2479cb0a5d42d1abeb6b08ef5f6851d28d50b13b3a8362772d8ecbecfbcc6a66efa34681deaeb5
6
+ metadata.gz: 449a18606c23f574ffba7b5a2d80f9cc7170839daf9187e52404d31ca93e3fb20396860476d827125b6a85968d98985ba83e2ad92d127066a69322edee40459b
7
+ data.tar.gz: 407d387c3ce3c6eb3648179837757caa688b5b6bdab42b7cc684d3480054fadc0d7aa4c4ef555d241c77919ecb6e8ae7438736ba6b449e56c6ee76cfbdac07e4
data/CHANGELOG.md CHANGED
@@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  Nothing yet...
10
10
 
11
+ ## [0.13.0] - 2020-03-01
12
+
13
+ ### Added
14
+ - Added the ability to configure relevant keywords for linters whose behavior is impacted by the dialect in which feature files are written.
15
+ - BackgroundDoesMoreThanSetupLinter
16
+ - TestWithActionStepAsFinalStepLinter
17
+ - TestWithNoActionStepLinter
18
+ - TestWithNoVerificationStepLinter
19
+ - TestWithSetupStepAfterActionStepLinter
20
+ - TestWithSetupStepAfterVerificationStepLinter
21
+ - TestWithSetupStepAsFinalStepLinter
22
+
11
23
 
12
24
  ## [0.12.1] - 2020-02-15
13
25
 
@@ -135,7 +147,8 @@ Nothing yet...
135
147
  - Custom linters, formatters, and command line usability
136
148
 
137
149
 
138
- [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.12.1...HEAD
150
+ [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.13.0...HEAD
151
+ [0.13.0]: https://github.com/enkessler/cuke_linter/compare/v0.12.1...v0.13.0
139
152
  [0.12.1]: https://github.com/enkessler/cuke_linter/compare/v0.12.0...v0.12.1
140
153
  [0.12.0]: https://github.com/enkessler/cuke_linter/compare/v0.11.1...v0.12.0
141
154
  [0.11.1]: https://github.com/enkessler/cuke_linter/compare/v0.11.0...v0.11.1
data/lib/cuke_linter.rb CHANGED
@@ -35,6 +35,10 @@ require 'cuke_linter/linters/test_with_too_many_steps_linter'
35
35
 
36
36
  module CukeLinter
37
37
 
38
+ DEFAULT_GIVEN_KEYWORD = 'Given'.freeze
39
+ DEFAULT_WHEN_KEYWORD = 'When'.freeze
40
+ DEFAULT_THEN_KEYWORD = 'Then'.freeze
41
+
38
42
  @original_linters = { 'BackgroundDoesMoreThanSetupLinter' => BackgroundDoesMoreThanSetupLinter.new,
39
43
  'ElementWithCommonTagsLinter' => ElementWithCommonTagsLinter.new,
40
44
  'ElementWithDuplicateTagsLinter' => ElementWithDuplicateTagsLinter.new,
@@ -4,11 +4,17 @@ module CukeLinter
4
4
 
5
5
  class BackgroundDoesMoreThanSetupLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @when_keywords = options['When']
10
+ @then_keywords = options['Then']
11
+ end
12
+
7
13
  # The rule used to determine if a model has a problem
8
14
  def rule(model)
9
15
  return false unless model.is_a?(CukeModeler::Background)
10
16
 
11
- model.steps.collect(&:keyword).any? { |keyword| (keyword == 'When') || (keyword == 'Then') }
17
+ model.steps.collect(&:keyword).any? { |keyword| when_keywords.include?(keyword) || then_keywords.include?(keyword) }
12
18
  end
13
19
 
14
20
  # The message used to describe the problem that has been found
@@ -16,5 +22,15 @@ module CukeLinter
16
22
  'Background has non-setup steps'
17
23
  end
18
24
 
25
+ private
26
+
27
+ def when_keywords
28
+ @when_keywords || [DEFAULT_WHEN_KEYWORD]
29
+ end
30
+
31
+ def then_keywords
32
+ @then_keywords || [DEFAULT_THEN_KEYWORD]
33
+ end
34
+
19
35
  end
20
36
  end
@@ -4,6 +4,11 @@ module CukeLinter
4
4
 
5
5
  class TestWithActionStepAsFinalStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @when_keywords = options['When']
10
+ end
11
+
7
12
  # The rule used to determine if a model has a problem
8
13
  def rule(model)
9
14
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -11,7 +16,7 @@ module CukeLinter
11
16
  model_steps = model.steps || []
12
17
  return false unless model_steps.last
13
18
 
14
- model_steps.last.keyword == 'When'
19
+ when_keywords.include?(model_steps.last.keyword)
15
20
  end
16
21
 
17
22
  # The message used to describe the problem that has been found
@@ -19,5 +24,11 @@ module CukeLinter
19
24
  "Test has 'When' as the final step."
20
25
  end
21
26
 
27
+ private
28
+
29
+ def when_keywords
30
+ @when_keywords || [DEFAULT_WHEN_KEYWORD]
31
+ end
32
+
22
33
  end
23
34
  end
@@ -4,6 +4,11 @@ module CukeLinter
4
4
 
5
5
  class TestWithNoActionStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @when_keywords = options['When']
10
+ end
11
+
7
12
  # The rule used to determine if a model has a problem
8
13
  def rule(model)
9
14
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -11,7 +16,7 @@ module CukeLinter
11
16
  model_steps = model.steps || []
12
17
  background_steps = model.parent_model.has_background? ? model.parent_model.background.steps || [] : []
13
18
  all_steps = model_steps + background_steps
14
- all_steps.none? { |step| step.keyword == 'When' }
19
+ all_steps.none? { |step| when_keywords.include?(step.keyword) }
15
20
  end
16
21
 
17
22
  # The message used to describe the problem that has been found
@@ -19,5 +24,11 @@ module CukeLinter
19
24
  "Test does not have a 'When' step."
20
25
  end
21
26
 
27
+ private
28
+
29
+ def when_keywords
30
+ @when_keywords || [DEFAULT_WHEN_KEYWORD]
31
+ end
32
+
22
33
  end
23
34
  end
@@ -4,6 +4,11 @@ module CukeLinter
4
4
 
5
5
  class TestWithNoVerificationStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @then_keywords = options['Then']
10
+ end
11
+
7
12
  # The rule used to determine if a model has a problem
8
13
  def rule(model)
9
14
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -11,7 +16,7 @@ module CukeLinter
11
16
  model_steps = model.steps || []
12
17
  background_steps = model.parent_model.has_background? ? model.parent_model.background.steps || [] : []
13
18
  all_steps = model_steps + background_steps
14
- all_steps.none? { |step| step.keyword == 'Then' }
19
+ all_steps.none? { |step| then_keywords.include?(step.keyword) }
15
20
  end
16
21
 
17
22
  # The message used to describe the problem that has been found
@@ -19,5 +24,11 @@ module CukeLinter
19
24
  "Test does not have a 'Then' step."
20
25
  end
21
26
 
27
+ private
28
+
29
+ def then_keywords
30
+ @then_keywords || [DEFAULT_THEN_KEYWORD]
31
+ end
32
+
22
33
  end
23
34
  end
@@ -4,6 +4,12 @@ module CukeLinter
4
4
 
5
5
  class TestWithSetupStepAfterActionStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @given_keywords = options['Given']
10
+ @when_keywords = options['When']
11
+ end
12
+
7
13
  # The rule used to determine if a model has a problem
8
14
  def rule(model)
9
15
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -13,9 +19,9 @@ module CukeLinter
13
19
 
14
20
  model_steps.each do |step|
15
21
  if action_step_found
16
- return true if step.keyword == 'Given'
22
+ return true if given_keywords.include?(step.keyword)
17
23
  else
18
- action_step_found = step.keyword == 'When'
24
+ action_step_found = when_keywords.include?(step.keyword)
19
25
  end
20
26
  end
21
27
 
@@ -27,5 +33,15 @@ module CukeLinter
27
33
  "Test has 'Given' step after 'When' step."
28
34
  end
29
35
 
36
+ private
37
+
38
+ def given_keywords
39
+ @given_keywords || [DEFAULT_GIVEN_KEYWORD]
40
+ end
41
+
42
+ def when_keywords
43
+ @when_keywords || [DEFAULT_WHEN_KEYWORD]
44
+ end
45
+
30
46
  end
31
47
  end
@@ -4,6 +4,12 @@ module CukeLinter
4
4
 
5
5
  class TestWithSetupStepAfterVerificationStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @given_keywords = options['Given']
10
+ @then_keywords = options['Then']
11
+ end
12
+
7
13
  # The rule used to determine if a model has a problem
8
14
  def rule(model)
9
15
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -13,9 +19,9 @@ module CukeLinter
13
19
 
14
20
  model_steps.each do |step|
15
21
  if verification_step_found
16
- return true if step.keyword == 'Given'
22
+ return true if given_keywords.include?(step.keyword)
17
23
  else
18
- verification_step_found = step.keyword == 'Then'
24
+ verification_step_found = then_keywords.include?(step.keyword)
19
25
  end
20
26
  end
21
27
 
@@ -27,5 +33,15 @@ module CukeLinter
27
33
  "Test has 'Given' step after 'Then' step."
28
34
  end
29
35
 
36
+ private
37
+
38
+ def given_keywords
39
+ @given_keywords || [DEFAULT_GIVEN_KEYWORD]
40
+ end
41
+
42
+ def then_keywords
43
+ @then_keywords || [DEFAULT_THEN_KEYWORD]
44
+ end
45
+
30
46
  end
31
47
  end
@@ -4,6 +4,11 @@ module CukeLinter
4
4
 
5
5
  class TestWithSetupStepAsFinalStepLinter < Linter
6
6
 
7
+ # Changes the linting settings on the linter using the provided configuration
8
+ def configure(options)
9
+ @given_keywords = options['Given']
10
+ end
11
+
7
12
  # The rule used to determine if a model has a problem
8
13
  def rule(model)
9
14
  return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
@@ -11,7 +16,7 @@ module CukeLinter
11
16
  model_steps = model.steps || []
12
17
  return false unless model_steps.last
13
18
 
14
- model_steps.last.keyword == 'Given'
19
+ given_keywords.include?(model_steps.last.keyword)
15
20
  end
16
21
 
17
22
  # The message used to describe the problem that has been found
@@ -19,5 +24,11 @@ module CukeLinter
19
24
  "Test has 'Given' as the final step."
20
25
  end
21
26
 
27
+ private
28
+
29
+ def given_keywords
30
+ @given_keywords || [DEFAULT_GIVEN_KEYWORD]
31
+ end
32
+
22
33
  end
23
34
  end
@@ -1,4 +1,4 @@
1
1
  module CukeLinter
2
2
  # The release version of this gem
3
- VERSION = '0.12.1'
3
+ VERSION = '0.13.0'
4
4
  end
@@ -48,3 +48,37 @@ Feature: Background does more than setup linter
48
48
  """
49
49
  When it is linted
50
50
  Then no error is reported
51
+
52
+ Scenario Outline: Configuration of keywords for different dialect
53
+ Given a linter for backgrounds that do more than setup has been registered
54
+ And the following configuration file:
55
+ """
56
+ BackgroundDoesMoreThanSetupLinter:
57
+ Given:
58
+ - Dado
59
+ When:
60
+ - Quando
61
+ Then:
62
+ - Então
63
+ - Entao
64
+ """
65
+ And the following feature:
66
+ """
67
+ # language:pt
68
+ Funcionalidade: Feature name
69
+
70
+ Contexto: A Background in pt dialect
71
+ Dado some setup in pt dialect
72
+ <step>
73
+ """
74
+ When the configuration file is loaded
75
+ And it is linted
76
+ Then an error is reported:
77
+ | linter | problem | location |
78
+ | BackgroundDoesMoreThanSetupLinter | Background has non-setup steps | <path_to_file>:4 |
79
+
80
+ Examples:
81
+ | step |
82
+ | Quando this is an action in pt dialect |
83
+ | Então this is a validation in pt dialect |
84
+ | Entao this is also a validation in pt dialect |
@@ -22,7 +22,29 @@ Feature: Test with action step as final step linter
22
22
  | linter | problem | location |
23
23
  | TestWithActionStepAsFinalStepLinter | Test has 'When' as the final step. | <path_to_file>:3 |
24
24
 
25
- @wip
26
- Scenario: Configuration
25
+ Scenario: Configuration of keywords for different dialect
26
+ Given a linter for tests with an action step as the final step has been registered
27
+ And the following configuration file:
28
+ """
29
+ TestWithActionStepAsFinalStepLinter:
30
+ Given:
31
+ - Dado
32
+ When:
33
+ - Quando
34
+ - '*'
35
+ Then:
36
+ - Então
37
+ """
38
+ And the following feature:
39
+ """
40
+ # language:pt
41
+ Funcionalidade: Feature name
27
42
 
28
- Configure the keyword(s) that count as action steps?
43
+ Cenário: scenario name
44
+ Quando this is an action in pt dialect
45
+ """
46
+ When the configuration file is loaded
47
+ And it is linted
48
+ Then an error is reported:
49
+ | linter | problem | location |
50
+ | TestWithActionStepAsFinalStepLinter | Test has 'When' as the final step. | <path_to_file>:4 |
@@ -23,8 +23,34 @@ Feature: Test with no action step linter
23
23
  | linter | problem | location |
24
24
  | TestWithNoActionStepLinter | Test does not have a 'When' step. | <path_to_file>:3 |
25
25
 
26
+ Scenario: Configuration of keywords for different dialect
27
+ Given a linter for tests with no action step has been registered
28
+ And the following configuration file:
29
+ """
30
+ TestWithNoActionStepLinter:
31
+ Given:
32
+ - Dado
33
+ When:
34
+ - Quando
35
+ Then:
36
+ - Então
37
+ """
38
+ And the following feature:
39
+ """
40
+ # language:pt
41
+ Funcionalidade: Feature name
42
+
43
+ Cenário: scenario name
44
+ Dado some setup in pt dialect
45
+ Então this is an validation in pt dialect
46
+ """
47
+ When the configuration file is loaded
48
+ And it is linted
49
+ Then an error is reported:
50
+ | linter | problem | location |
51
+ | TestWithNoActionStepLinter | Test does not have a 'When' step. | <path_to_file>:4 |
52
+
26
53
  @wip
27
54
  Scenario: Configuration
28
55
 
29
56
  Ideas: Configure whether or not the linter triggers on tests with no steps at all?
30
- Configure the keyword(s) that count as an action step?
@@ -24,8 +24,35 @@ Feature: Test with no verification step linter
24
24
  | linter | problem | location |
25
25
  | TestWithNoVerificationStepLinter | Test does not have a 'Then' step. | <path_to_file>:3 |
26
26
 
27
+ Scenario: Configuration of keywords for different dialect
28
+ Given a linter for tests with no verification step has been registered
29
+ And the following configuration file:
30
+ """
31
+ TestWithNoVerificationStepLinter:
32
+ Given:
33
+ - Dado
34
+ When:
35
+ - Quando
36
+ Then:
37
+ - Então
38
+ """
39
+ And the following feature:
40
+ """
41
+ # language:pt
42
+ Funcionalidade: Feature name
43
+
44
+ Cenário: scenario name
45
+ Dado some setup in pt dialect
46
+ Quando this is an action in pt dialect
47
+ E this is and AND in pt dialect
48
+ """
49
+ When the configuration file is loaded
50
+ And it is linted
51
+ Then an error is reported:
52
+ | linter | problem | location |
53
+ | TestWithNoVerificationStepLinter | Test does not have a 'Then' step. | <path_to_file>:4 |
54
+
27
55
  @wip
28
56
  Scenario: Configuration
29
57
 
30
58
  Ideas: Configure whether or not the linter triggers on tests with no steps at all?
31
- Configure the keyword(s) that count as a verification step?