cuke_linter 0.12.0 → 1.1.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 +41 -1
- data/README.md +12 -8
- data/cuke_linter.gemspec +25 -21
- data/exe/cuke_linter +3 -1
- data/lib/cuke_linter.rb +119 -176
- data/lib/cuke_linter/configuration.rb +45 -0
- data/lib/cuke_linter/default_linters.rb +32 -0
- data/lib/cuke_linter/formatters/pretty_formatter.rb +63 -35
- data/lib/cuke_linter/gherkin.rb +10 -0
- data/lib/cuke_linter/linter_registration.rb +32 -0
- data/lib/cuke_linter/linters/background_does_more_than_setup_linter.rb +17 -1
- data/lib/cuke_linter/linters/element_with_common_tags_linter.rb +23 -14
- data/lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb +18 -13
- data/lib/cuke_linter/linters/element_with_too_many_tags_linter.rb +17 -11
- data/lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb +1 -3
- data/lib/cuke_linter/linters/feature_without_description_linter.rb +1 -1
- data/lib/cuke_linter/linters/linter.rb +17 -13
- data/lib/cuke_linter/linters/step_with_too_many_characters_linter.rb +2 -2
- data/lib/cuke_linter/linters/test_should_use_background_linter.rb +56 -4
- data/lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb +12 -1
- data/lib/cuke_linter/linters/test_with_bad_name_linter.rb +4 -4
- data/lib/cuke_linter/linters/test_with_no_action_step_linter.rb +12 -1
- data/lib/cuke_linter/linters/test_with_no_verification_step_linter.rb +12 -1
- data/lib/cuke_linter/linters/test_with_setup_step_after_action_step_linter.rb +18 -2
- data/lib/cuke_linter/linters/test_with_setup_step_after_verification_step_linter.rb +18 -2
- data/lib/cuke_linter/linters/test_with_setup_step_as_final_step_linter.rb +12 -1
- data/lib/cuke_linter/version.rb +1 -1
- data/testing/cucumber/features/linters/background_does_more_than_setup.feature +34 -0
- data/testing/cucumber/features/linters/test_with_action_as_final_step.feature +25 -3
- data/testing/cucumber/features/linters/test_with_no_action_step.feature +27 -1
- data/testing/cucumber/features/linters/test_with_no_verification_step.feature +28 -1
- data/testing/cucumber/features/linters/test_with_setup_step_after_action_step.feature +28 -1
- data/testing/cucumber/features/linters/test_with_setup_step_after_verification_step.feature +28 -1
- data/testing/cucumber/features/linters/test_with_setup_step_as_final_step.feature +25 -3
- metadata +88 -106
- data/.gitignore +0 -19
- data/.simplecov +0 -8
- data/.travis.yml +0 -23
- data/CONTRIBUTING.md +0 -26
- data/Gemfile +0 -6
- data/Rakefile +0 -63
- data/appveyor.yml +0 -43
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/environments/common_env.rb +0 -12
- data/environments/cucumber_env.rb +0 -22
- data/environments/rspec_env.rb +0 -50
- data/testing/cucumber/step_definitions/action_steps.rb +0 -84
- data/testing/cucumber/step_definitions/setup_steps.rb +0 -230
- data/testing/cucumber/step_definitions/verification_steps.rb +0 -94
- data/testing/file_helper.rb +0 -41
- data/testing/formatter_factory.rb +0 -15
- data/testing/gemfiles/cuke_modeler1.gemfile +0 -8
- data/testing/gemfiles/cuke_modeler2.gemfile +0 -8
- data/testing/linter_factory.rb +0 -60
- data/testing/model_factory.rb +0 -109
- data/testing/rspec/spec/integration/cli_integration_spec.rb +0 -556
- data/testing/rspec/spec/integration/configuration_spec.rb +0 -811
- data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +0 -243
- data/testing/rspec/spec/integration/formatters/formatter_integration_specs.rb +0 -5
- data/testing/rspec/spec/integration/formatters/pretty_formatter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/background_does_more_than_setup_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/element_with_common_tags_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/element_with_duplicate_tags_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/element_with_too_many_tags_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/example_without_name_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_file_with_invalid_name_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_file_with_mismatched_name_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_with_too_many_different_tags_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_without_description_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_without_name_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/feature_without_scenarios_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/linter_integration_specs.rb +0 -7
- data/testing/rspec/spec/integration/linters/outline_with_single_example_row_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/single_test_background_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/step_with_end_period_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/step_with_too_many_characters_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_should_use_background_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_action_step_as_final_step_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_bad_name_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_no_action_step_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_no_name_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_no_verification_step_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_setup_step_after_action_step_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_setup_step_after_verification_step_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_setup_step_as_final_step_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/integration/linters/test_with_too_many_steps_linter_integration_spec.rb +0 -8
- data/testing/rspec/spec/unit/cuke_linter_unit_spec.rb +0 -102
- data/testing/rspec/spec/unit/formatters/formatter_unit_specs.rb +0 -11
- data/testing/rspec/spec/unit/formatters/pretty_formatter_unit_spec.rb +0 -115
- data/testing/rspec/spec/unit/linters/background_does_more_than_setup_linter_unit_spec.rb +0 -77
- data/testing/rspec/spec/unit/linters/configurable_linter_unit_specs.rb +0 -11
- data/testing/rspec/spec/unit/linters/element_with_common_tags_linter_unit_spec.rb +0 -248
- data/testing/rspec/spec/unit/linters/element_with_duplicate_tags_linter_unit_spec.rb +0 -203
- data/testing/rspec/spec/unit/linters/element_with_too_many_tags_linter_unit_spec.rb +0 -296
- data/testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb +0 -81
- data/testing/rspec/spec/unit/linters/feature_file_with_invalid_name_linter_unit_spec.rb +0 -106
- data/testing/rspec/spec/unit/linters/feature_file_with_mismatched_name_linter_unit_spec.rb +0 -124
- data/testing/rspec/spec/unit/linters/feature_with_too_many_different_tags_linter_unit_spec.rb +0 -293
- data/testing/rspec/spec/unit/linters/feature_without_description_linter_unit_spec.rb +0 -80
- data/testing/rspec/spec/unit/linters/feature_without_name_linter_unit_spec.rb +0 -84
- data/testing/rspec/spec/unit/linters/feature_without_scenarios_linter_unit_spec.rb +0 -102
- data/testing/rspec/spec/unit/linters/linter_unit_spec.rb +0 -197
- data/testing/rspec/spec/unit/linters/linter_unit_specs.rb +0 -57
- data/testing/rspec/spec/unit/linters/outline_with_single_example_row_linter_unit_spec.rb +0 -184
- data/testing/rspec/spec/unit/linters/single_test_background_linter_unit_spec.rb +0 -89
- data/testing/rspec/spec/unit/linters/step_with_end_period_linter_unit_spec.rb +0 -54
- data/testing/rspec/spec/unit/linters/step_with_too_many_characters_linter_unit_spec.rb +0 -155
- data/testing/rspec/spec/unit/linters/test_should_use_background_linter_unit_spec.rb +0 -226
- data/testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb +0 -98
- data/testing/rspec/spec/unit/linters/test_with_bad_name_linter_unit_spec.rb +0 -81
- data/testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb +0 -176
- data/testing/rspec/spec/unit/linters/test_with_no_name_linter_unit_spec.rb +0 -88
- data/testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb +0 -179
- data/testing/rspec/spec/unit/linters/test_with_setup_step_after_action_step_linter_unit_spec.rb +0 -124
- data/testing/rspec/spec/unit/linters/test_with_setup_step_after_verification_step_linter_unit_spec.rb +0 -125
- data/testing/rspec/spec/unit/linters/test_with_setup_step_as_final_step_linter_unit_spec.rb +0 -98
- data/testing/rspec/spec/unit/linters/test_with_too_many_steps_linter_unit_spec.rb +0 -192
@@ -4,6 +4,9 @@ module CukeLinter
|
|
4
4
|
|
5
5
|
class Linter
|
6
6
|
|
7
|
+
# Returns the name of the linter
|
8
|
+
attr_reader :name
|
9
|
+
|
7
10
|
# Creates a new linter object
|
8
11
|
def initialize(name: nil, message: nil, rule: nil)
|
9
12
|
@name = name || self.class.name.split('::').last
|
@@ -11,27 +14,28 @@ module CukeLinter
|
|
11
14
|
@rule = rule
|
12
15
|
end
|
13
16
|
|
14
|
-
# Returns the name of the linter
|
15
|
-
def name
|
16
|
-
@name
|
17
|
-
end
|
18
|
-
|
19
17
|
# Lints the given model and returns linting data about said model
|
20
18
|
def lint(model)
|
21
19
|
raise 'No linting rule provided!' unless @rule || respond_to?(:rule)
|
22
20
|
|
23
21
|
problem_found = respond_to?(:rule) ? rule(model) : @rule.call(model)
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
return nil unless problem_found
|
24
|
+
|
25
|
+
build_problem(model)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
|
32
|
+
def build_problem(model)
|
33
|
+
problem_message = respond_to?(:message) ? message : @message
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
{ problem: problem_message, location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }
|
32
|
-
end
|
35
|
+
if model.is_a?(CukeModeler::FeatureFile)
|
36
|
+
{ problem: problem_message, location: model.path }
|
33
37
|
else
|
34
|
-
|
38
|
+
{ problem: problem_message, location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -15,8 +15,8 @@ module CukeLinter
|
|
15
15
|
# The rule used to determine if a model has a problem
|
16
16
|
def rule(model)
|
17
17
|
return false unless model.is_a?(CukeModeler::Step)
|
18
|
-
|
19
|
-
@linted_step_length = model.text
|
18
|
+
|
19
|
+
@linted_step_length = model.text.nil? ? 0 : model.text.length
|
20
20
|
|
21
21
|
@linted_step_length > step_length_threshold
|
22
22
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module CukeLinter
|
2
2
|
|
3
|
+
# TODO: Make a new class that it is from the POV of a Feature model instead
|
3
4
|
# A linter that detects scenarios and outlines within a feature that all share common beginning steps
|
4
5
|
|
5
6
|
class TestShouldUseBackgroundLinter < Linter
|
@@ -13,10 +14,10 @@ module CukeLinter
|
|
13
14
|
|
14
15
|
return false unless parent_feature_model.tests.count > 1
|
15
16
|
|
16
|
-
parent_feature_model
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
matching_steps = all_first_steps_match?(parent_feature_model, model_steps)
|
18
|
+
none_parameterized = no_parameterized_steps?(parent_feature_model)
|
19
|
+
|
20
|
+
matching_steps && none_parameterized
|
20
21
|
end
|
21
22
|
|
22
23
|
# The message used to describe the problem that has been found
|
@@ -24,5 +25,56 @@ module CukeLinter
|
|
24
25
|
'Test shares steps with all other tests in feature. Use a background.'
|
25
26
|
end
|
26
27
|
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
|
32
|
+
def all_first_steps_match?(feature_model, model_steps)
|
33
|
+
feature_model.tests.all? do |test|
|
34
|
+
test_steps = test.steps || []
|
35
|
+
test_steps.first == model_steps.first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def no_parameterized_steps?(feature_model)
|
40
|
+
feature_model.tests.none? do |test|
|
41
|
+
next false if test.is_a?(CukeModeler::Scenario)
|
42
|
+
|
43
|
+
test_steps = test.steps || []
|
44
|
+
params_used_by_test = test.examples.map(&:parameters).flatten.uniq
|
45
|
+
|
46
|
+
next false unless test_steps.any?
|
47
|
+
|
48
|
+
parameterized_step?(test_steps.first, parameters: params_used_by_test)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parameterized_step?(step_model, parameters:)
|
53
|
+
parameters.any? do |parameter|
|
54
|
+
parameter_string = "<#{parameter}>"
|
55
|
+
|
56
|
+
parameterized_text?(step_model, parameter_string) ||
|
57
|
+
parameterized_doc_string?(step_model, parameter_string) ||
|
58
|
+
parameterized_table?(step_model, parameter_string)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def parameterized_text?(step_model, parameter)
|
63
|
+
step_model.text.include?(parameter)
|
64
|
+
end
|
65
|
+
|
66
|
+
def parameterized_doc_string?(step_model, parameter)
|
67
|
+
return false unless step_model.block.is_a?(CukeModeler::DocString)
|
68
|
+
|
69
|
+
step_model.block.content.include?(parameter)
|
70
|
+
end
|
71
|
+
|
72
|
+
def parameterized_table?(step_model, parameter)
|
73
|
+
return false unless step_model.block.is_a?(CukeModeler::Table)
|
74
|
+
|
75
|
+
step_model.block.rows.map(&:cells).flatten.map(&:value).any? { |cell_text| cell_text.include?(parameter) }
|
76
|
+
end
|
77
|
+
|
27
78
|
end
|
79
|
+
|
28
80
|
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
|
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
|
@@ -9,10 +9,10 @@ module CukeLinter
|
|
9
9
|
return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
|
10
10
|
|
11
11
|
lowercase_name = model.name.downcase
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
lowercase_name.include?('test') ||
|
14
|
+
lowercase_name.include?('verif') ||
|
15
|
+
lowercase_name.include?('check')
|
16
16
|
end
|
17
17
|
|
18
18
|
# The message used to describe the problem that has been found
|
@@ -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
|
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
|
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
|
22
|
+
return true if given_keywords.include?(step.keyword)
|
17
23
|
else
|
18
|
-
action_step_found = step.keyword
|
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
|
22
|
+
return true if given_keywords.include?(step.keyword)
|
17
23
|
else
|
18
|
-
verification_step_found = step.keyword
|
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
|
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
|
data/lib/cuke_linter/version.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
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
|
-
|
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 |
|