cuke_linter 0.12.1 → 1.2.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 +40 -1
- data/README.md +12 -8
- data/cuke_linter.gemspec +26 -22
- data/exe/cuke_linter +4 -2
- 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 +23 -15
- 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 +101 -117
- data/.gitignore +0 -19
- data/.simplecov +0 -8
- data/.travis.yml +0 -33
- 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 -464
- 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
@@ -1,80 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::FeatureWithoutDescriptionLinter do
|
5
|
-
|
6
|
-
let(:model_file_path) { 'some_file_path' }
|
7
|
-
|
8
|
-
it_should_behave_like 'a linter at the unit level'
|
9
|
-
|
10
|
-
|
11
|
-
it 'has a name' do
|
12
|
-
expect(subject.name).to eq('FeatureWithoutDescriptionLinter')
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'linting' do
|
16
|
-
|
17
|
-
context 'a feature with no description' do
|
18
|
-
|
19
|
-
context 'because the description is empty' do
|
20
|
-
|
21
|
-
let(:test_model) do
|
22
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
23
|
-
model.description = ''
|
24
|
-
|
25
|
-
model
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a linter linting a bad model'
|
29
|
-
|
30
|
-
|
31
|
-
it 'records a problem' do
|
32
|
-
result = subject.lint(test_model)
|
33
|
-
|
34
|
-
expect(result[:problem]).to eq('Feature has no description')
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'because the description is nil' do
|
40
|
-
|
41
|
-
let(:test_model) do
|
42
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
43
|
-
model.description = nil
|
44
|
-
|
45
|
-
model
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'records a problem' do
|
49
|
-
result = subject.lint(test_model)
|
50
|
-
|
51
|
-
expect(result[:problem]).to eq('Feature has no description')
|
52
|
-
end
|
53
|
-
|
54
|
-
it_should_behave_like 'a linter linting a bad model'
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'a feature with a description' do
|
60
|
-
|
61
|
-
let(:test_model) do
|
62
|
-
model_source = "Feature:\n This feature has a description"
|
63
|
-
CukeLinter::ModelFactory.generate_feature_model(source_text: model_source,
|
64
|
-
parent_file_path: 'path_to_file')
|
65
|
-
end
|
66
|
-
|
67
|
-
it_should_behave_like 'a linter linting a good model'
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'a non-feature model' do
|
72
|
-
|
73
|
-
let(:test_model) { CukeModeler::Model.new }
|
74
|
-
|
75
|
-
it_should_behave_like 'a linter linting a good model'
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::FeatureWithoutNameLinter do
|
5
|
-
|
6
|
-
let(:model_file_path) { 'some_file_path' }
|
7
|
-
|
8
|
-
it_should_behave_like 'a linter at the unit level'
|
9
|
-
|
10
|
-
|
11
|
-
it 'has a name' do
|
12
|
-
expect(subject.name).to eq('FeatureWithoutNameLinter')
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'linting' do
|
16
|
-
|
17
|
-
context 'with a feature that has no name' do
|
18
|
-
|
19
|
-
context 'because its name is empty' do
|
20
|
-
|
21
|
-
let(:test_model) do
|
22
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
23
|
-
model.name = ''
|
24
|
-
|
25
|
-
model
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a linter linting a bad model'
|
29
|
-
|
30
|
-
|
31
|
-
it 'records a problem' do
|
32
|
-
result = subject.lint(test_model)
|
33
|
-
|
34
|
-
expect(result[:problem]).to eq('Feature does not have a name.')
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'because its name is nil' do
|
40
|
-
|
41
|
-
let(:test_model) do
|
42
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
43
|
-
model.name = nil
|
44
|
-
|
45
|
-
model
|
46
|
-
end
|
47
|
-
|
48
|
-
it_should_behave_like 'a linter linting a bad model'
|
49
|
-
|
50
|
-
it 'records a problem' do
|
51
|
-
result = subject.lint(test_model)
|
52
|
-
|
53
|
-
expect(result[:problem]).to eq('Feature does not have a name.')
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with a feature that does have a name' do
|
61
|
-
|
62
|
-
let(:test_model) do
|
63
|
-
model = CukeLinter::ModelFactory.generate_feature_model
|
64
|
-
model.name = 'foo'
|
65
|
-
|
66
|
-
model
|
67
|
-
end
|
68
|
-
|
69
|
-
it_should_behave_like 'a linter linting a good model'
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
context 'a non-feature model' do
|
75
|
-
|
76
|
-
let(:test_model) { CukeModeler::Model.new }
|
77
|
-
|
78
|
-
it_should_behave_like 'a linter linting a good model'
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
|
5
|
-
|
6
|
-
let(:model_file_path) { 'some_file_path' }
|
7
|
-
|
8
|
-
it_should_behave_like 'a linter at the unit level'
|
9
|
-
|
10
|
-
|
11
|
-
it 'has a name' do
|
12
|
-
expect(subject.name).to eq('FeatureWithoutScenariosLinter')
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'linting' do
|
16
|
-
|
17
|
-
context 'a feature with no tests' do
|
18
|
-
|
19
|
-
context 'because the tests are empty' do
|
20
|
-
|
21
|
-
let(:test_model) do
|
22
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
23
|
-
model.tests = []
|
24
|
-
|
25
|
-
model
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a linter linting a bad model'
|
29
|
-
|
30
|
-
it 'records a problem' do
|
31
|
-
result = subject.lint(test_model)
|
32
|
-
|
33
|
-
expect(result[:problem]).to eq('Feature has no scenarios')
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'because the tests are nil' do
|
39
|
-
|
40
|
-
let(:test_model) do
|
41
|
-
model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
|
42
|
-
model.tests = nil
|
43
|
-
|
44
|
-
model
|
45
|
-
end
|
46
|
-
|
47
|
-
it_should_behave_like 'a linter linting a bad model'
|
48
|
-
|
49
|
-
it 'records a problem' do
|
50
|
-
result = subject.lint(test_model)
|
51
|
-
|
52
|
-
expect(result[:problem]).to eq('Feature has no scenarios')
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'a feature with tests' do
|
60
|
-
|
61
|
-
context 'with a scenario' do
|
62
|
-
|
63
|
-
let(:test_model) do
|
64
|
-
gherkin = 'Feature:
|
65
|
-
|
66
|
-
Scenario:'
|
67
|
-
|
68
|
-
CukeLinter::ModelFactory.generate_feature_model(source_text: gherkin)
|
69
|
-
end
|
70
|
-
|
71
|
-
it_should_behave_like 'a linter linting a good model'
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'with an outline' do
|
76
|
-
|
77
|
-
let(:test_model) do
|
78
|
-
gherkin = 'Feature:
|
79
|
-
|
80
|
-
Scenario Outline:
|
81
|
-
* a step
|
82
|
-
Examples:
|
83
|
-
| param |'
|
84
|
-
|
85
|
-
CukeLinter::ModelFactory.generate_feature_model(source_text: gherkin)
|
86
|
-
end
|
87
|
-
|
88
|
-
it_should_behave_like 'a linter linting a good model'
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'a non-feature model' do
|
95
|
-
|
96
|
-
let(:test_model) { CukeModeler::Model.new }
|
97
|
-
|
98
|
-
it_should_behave_like 'a linter linting a good model'
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::Linter do
|
5
|
-
|
6
|
-
let(:model_file_path) { 'some_file_path' }
|
7
|
-
|
8
|
-
let(:linter_name) { 'FooLinter' }
|
9
|
-
let(:linter_message) { 'Foo!' }
|
10
|
-
let(:linter_rule) { lambda { |model| !model.is_a?(CukeModeler::Example) } }
|
11
|
-
let(:linter_options) { { name: linter_name, message: linter_message, rule: linter_rule } }
|
12
|
-
|
13
|
-
let(:good_data) { CukeLinter::ModelFactory.generate_example_model }
|
14
|
-
let(:bad_data) { CukeLinter::ModelFactory.generate_outline_model }
|
15
|
-
|
16
|
-
|
17
|
-
it_should_behave_like 'a linter at the unit level'
|
18
|
-
|
19
|
-
context 'with a linting rule' do
|
20
|
-
|
21
|
-
subject { CukeLinter::Linter.new(linter_options.merge({ rule: linter_rule })) }
|
22
|
-
|
23
|
-
context 'with a good model' do
|
24
|
-
|
25
|
-
let(:test_model) { CukeLinter::ModelFactory.generate_example_model }
|
26
|
-
|
27
|
-
it_should_behave_like 'a linter linting a good model'
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with a bad model' do
|
32
|
-
|
33
|
-
let(:test_model) { CukeLinter::ModelFactory.generate_outline_model(parent_file_path: model_file_path) }
|
34
|
-
|
35
|
-
it_should_behave_like 'a linter linting a bad model'
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
context 'with custom values' do
|
43
|
-
|
44
|
-
subject { CukeLinter::Linter.new(linter_options) }
|
45
|
-
|
46
|
-
it 'uses the provided name' do
|
47
|
-
expect(subject.name).to eq(linter_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'uses the provided rule' do
|
51
|
-
expect(subject.lint(good_data)).to be_nil
|
52
|
-
expect(subject.lint(bad_data)).to_not be_nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'uses the provided message' do
|
56
|
-
result = subject.lint(bad_data)
|
57
|
-
|
58
|
-
expect(result[:problem]).to eq(linter_message)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'with custom methods' do
|
64
|
-
|
65
|
-
subject { linter = CukeLinter::Linter.new
|
66
|
-
|
67
|
-
linter.define_singleton_method('rule') do |model|
|
68
|
-
!model.is_a?(CukeModeler::Example)
|
69
|
-
end
|
70
|
-
|
71
|
-
linter.define_singleton_method('name') do
|
72
|
-
'FooLinter'
|
73
|
-
end
|
74
|
-
|
75
|
-
linter.define_singleton_method('message') do
|
76
|
-
'Foo!'
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
linter }
|
81
|
-
|
82
|
-
|
83
|
-
it 'uses the provided #name' do
|
84
|
-
expect(subject.name).to eq(linter_name)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'uses the provided #rule' do
|
88
|
-
expect(subject.lint(good_data)).to be_nil
|
89
|
-
expect(subject.lint(bad_data)).to_not be_nil
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'uses the provided #message' do
|
93
|
-
result = subject.lint(bad_data)
|
94
|
-
|
95
|
-
expect(result[:problem]).to eq(linter_message)
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'with both custom values and methods' do
|
101
|
-
|
102
|
-
let(:good_data) do
|
103
|
-
CukeLinter::ModelFactory.generate_outline_model
|
104
|
-
end
|
105
|
-
|
106
|
-
let(:bad_data) do
|
107
|
-
CukeLinter::ModelFactory.generate_example_model
|
108
|
-
end
|
109
|
-
|
110
|
-
subject { linter = CukeLinter::Linter.new(linter_options)
|
111
|
-
|
112
|
-
linter.define_singleton_method('rule') do |model|
|
113
|
-
model.is_a?(CukeModeler::Example)
|
114
|
-
end
|
115
|
-
|
116
|
-
linter.define_singleton_method('name') do
|
117
|
-
'Method Linter'
|
118
|
-
end
|
119
|
-
|
120
|
-
linter.define_singleton_method('message') do
|
121
|
-
'Method Foo!'
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
linter }
|
126
|
-
|
127
|
-
|
128
|
-
it 'uses #name instead of the provided name' do
|
129
|
-
expect(subject.name).to eq('Method Linter')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'uses #rule instead of the provided rule' do
|
133
|
-
expect(subject.lint(good_data)).to be_nil
|
134
|
-
expect(subject.lint(bad_data)).to_not be_nil
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'uses #message instead of the provided message' do
|
138
|
-
result = subject.lint(bad_data)
|
139
|
-
|
140
|
-
expect(result[:problem]).to eq('Method Foo!')
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'with neither custom values nor methods' do
|
146
|
-
|
147
|
-
subject { CukeLinter::Linter.new }
|
148
|
-
|
149
|
-
|
150
|
-
it 'complains if not provided with a rule' do
|
151
|
-
expect { subject.lint('Anything') }.to raise_error('No linting rule provided!')
|
152
|
-
end
|
153
|
-
|
154
|
-
|
155
|
-
it 'has a default name based on its class' do
|
156
|
-
expect(subject.name).to eq('Linter')
|
157
|
-
|
158
|
-
class CustomLinter < CukeLinter::Linter;
|
159
|
-
end
|
160
|
-
|
161
|
-
expect(CustomLinter.new.name).to eq('CustomLinter')
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'has a default message based on its name' do
|
165
|
-
linter_options[:message] = nil
|
166
|
-
|
167
|
-
# Default name
|
168
|
-
linter_options[:name] = nil
|
169
|
-
linter = CukeLinter::Linter.new(linter_options)
|
170
|
-
result = linter.lint(bad_data)
|
171
|
-
|
172
|
-
expect(result[:problem]).to eq('Linter problem detected')
|
173
|
-
|
174
|
-
# Value name
|
175
|
-
linter_options[:name] = 'Value name'
|
176
|
-
linter = CukeLinter::Linter.new(linter_options)
|
177
|
-
result = linter.lint(bad_data)
|
178
|
-
|
179
|
-
expect(result[:problem]).to eq('Value name problem detected')
|
180
|
-
|
181
|
-
# Method name
|
182
|
-
class CustomLinter < CukeLinter::Linter;
|
183
|
-
def name
|
184
|
-
'Method name'
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
linter_options[:name] = nil
|
189
|
-
linter = CustomLinter.new(linter_options)
|
190
|
-
result = linter.lint(bad_data)
|
191
|
-
|
192
|
-
expect(result[:problem]).to eq('Method name problem detected')
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|