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
@@ -1,102 +0,0 @@
|
|
1
|
-
require_relative '../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe 'the gem' do
|
5
|
-
|
6
|
-
let(:gemspec) { eval(File.read "#{__dir__}/../../../../cuke_linter.gemspec") }
|
7
|
-
|
8
|
-
it 'has an executable' do
|
9
|
-
expect(gemspec.executables).to include('cuke_linter')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'validates cleanly' do
|
13
|
-
mock_ui = Gem::MockGemUi.new
|
14
|
-
Gem::DefaultUserInteraction.use_ui(mock_ui) { gemspec.validate }
|
15
|
-
|
16
|
-
expect(mock_ui.error).to_not match(/warn/i)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
RSpec.describe CukeLinter do
|
23
|
-
|
24
|
-
it "has a version number" do
|
25
|
-
expect(CukeLinter::VERSION).not_to be nil
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'can lint' do
|
29
|
-
expect(CukeLinter).to respond_to(:lint)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'lints the (optionally) given model trees and (optionally) file paths using the (optionally) provided set of linters and formats the output with the (optionally) provided formatters' do
|
33
|
-
expect(CukeLinter.method(:lint).arity).to eq(-1)
|
34
|
-
expect(CukeLinter.method(:lint).parameters).to match_array([[:key, :model_trees],
|
35
|
-
[:key, :linters],
|
36
|
-
[:key, :formatters],
|
37
|
-
[:key, :file_paths]])
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'can register a linter' do
|
41
|
-
expect(CukeLinter).to respond_to(:register_linter)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'can unregister a linter' do
|
45
|
-
expect(CukeLinter).to respond_to(:unregister_linter)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'registers a linter by name' do
|
49
|
-
expect(CukeLinter.method(:register_linter).arity).to eq(1)
|
50
|
-
expect(CukeLinter.method(:register_linter).parameters).to match_array([[:keyreq, :linter],
|
51
|
-
[:keyreq, :name]])
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'unregisters a linter by name' do
|
55
|
-
expect(CukeLinter.method(:unregister_linter).arity).to eq(1)
|
56
|
-
expect(CukeLinter.method(:unregister_linter).parameters).to match_array([[:req, :name]])
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'knows its currently registered linters' do
|
60
|
-
expect(CukeLinter).to respond_to(:registered_linters)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'correctly registers, unregisters, and tracks linters', :linter_registration do
|
64
|
-
CukeLinter.clear_registered_linters
|
65
|
-
CukeLinter.register_linter(name: 'foo', linter: :linter_1)
|
66
|
-
CukeLinter.register_linter(name: 'bar', linter: :linter_2)
|
67
|
-
CukeLinter.register_linter(name: 'baz', linter: :linter_3)
|
68
|
-
|
69
|
-
CukeLinter.unregister_linter('bar')
|
70
|
-
|
71
|
-
expect(CukeLinter.registered_linters).to eq({ 'foo' => :linter_1,
|
72
|
-
'baz' => :linter_3, })
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can clear all of its currently registered linters', :linter_registration do
|
76
|
-
expect(CukeLinter).to respond_to(:clear_registered_linters)
|
77
|
-
|
78
|
-
CukeLinter.register_linter(name: 'some_linter', linter: :the_linter)
|
79
|
-
CukeLinter.clear_registered_linters
|
80
|
-
|
81
|
-
expect(CukeLinter.registered_linters).to eq({})
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'can reset to its default set of linters' do
|
85
|
-
expect(CukeLinter).to respond_to(:reset_linters)
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'configuration' do
|
89
|
-
|
90
|
-
it 'can load a configuration' do
|
91
|
-
expect(CukeLinter).to respond_to(:load_configuration)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'is configured optionally via a file or a directly provided configuration' do
|
95
|
-
expect(CukeLinter.method(:load_configuration).arity).to eq(-1)
|
96
|
-
expect(CukeLinter.method(:load_configuration).parameters).to match_array([[:key, :config_file_path],
|
97
|
-
[:key, :config]])
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::PrettyFormatter do
|
5
|
-
|
6
|
-
it_should_behave_like 'a formatter at the unit level'
|
7
|
-
|
8
|
-
|
9
|
-
it 'formats linting data as pretty text' do
|
10
|
-
linting_data = [{ linter: 'SomeLinter',
|
11
|
-
problem: 'Some problem',
|
12
|
-
location: 'path/to/the_file:1' },
|
13
|
-
{ linter: 'SomeOtherLinter',
|
14
|
-
problem: 'Some other problem',
|
15
|
-
location: 'path/to/the_file:1' },
|
16
|
-
{ linter: 'YetAnotherLinter',
|
17
|
-
problem: 'Yet another problem',
|
18
|
-
location: 'path/to/the_file' }]
|
19
|
-
|
20
|
-
results = subject.format(linting_data)
|
21
|
-
|
22
|
-
expect(results).to eq(['SomeLinter',
|
23
|
-
' Some problem',
|
24
|
-
' path/to/the_file:1',
|
25
|
-
'SomeOtherLinter',
|
26
|
-
' Some other problem',
|
27
|
-
' path/to/the_file:1',
|
28
|
-
'YetAnotherLinter',
|
29
|
-
' Yet another problem',
|
30
|
-
' path/to/the_file',
|
31
|
-
'',
|
32
|
-
'3 issues found'].join("\n"))
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'groups data by linter and problem' do
|
36
|
-
linting_data = [{ linter: 'SomeLinter',
|
37
|
-
problem: 'Some problem',
|
38
|
-
location: 'path/to/the_file:1' },
|
39
|
-
{ linter: 'SomeOtherLinter',
|
40
|
-
problem: 'Some other problem',
|
41
|
-
location: 'path/to/the_file:1' },
|
42
|
-
{ linter: 'SomeLinter',
|
43
|
-
problem: 'Some problem',
|
44
|
-
location: 'path/to/the_file:11' }]
|
45
|
-
|
46
|
-
results = subject.format(linting_data)
|
47
|
-
|
48
|
-
expect(results).to eq(['SomeLinter',
|
49
|
-
' Some problem',
|
50
|
-
' path/to/the_file:1',
|
51
|
-
' path/to/the_file:11',
|
52
|
-
'SomeOtherLinter',
|
53
|
-
' Some other problem',
|
54
|
-
' path/to/the_file:1',
|
55
|
-
'',
|
56
|
-
'3 issues found'].join("\n"))
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'orders violations within the same problem category by file path' do
|
60
|
-
linting_data = [{ linter: 'SomeLinter',
|
61
|
-
problem: 'Some problem',
|
62
|
-
location: 'path/to/the_file:1' },
|
63
|
-
{ linter: 'SomeLinter',
|
64
|
-
problem: 'Some problem',
|
65
|
-
location: 'path/to/the_file:3' },
|
66
|
-
{ linter: 'SomeLinter',
|
67
|
-
problem: 'Some problem',
|
68
|
-
location: 'path/to/a_different_file:2' }]
|
69
|
-
|
70
|
-
results = subject.format(linting_data)
|
71
|
-
|
72
|
-
expect(results).to eq(['SomeLinter',
|
73
|
-
' Some problem',
|
74
|
-
' path/to/a_different_file:2',
|
75
|
-
' path/to/the_file:1',
|
76
|
-
' path/to/the_file:3',
|
77
|
-
'',
|
78
|
-
'3 issues found'].join("\n"))
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'orders violations in the same file by line number' do
|
82
|
-
linting_data = [{ linter: 'SomeLinter',
|
83
|
-
problem: 'Some problem',
|
84
|
-
location: 'path/to/the_file:2' },
|
85
|
-
{ linter: 'SomeLinter',
|
86
|
-
problem: 'Some problem',
|
87
|
-
location: 'path/to/the_file:3' },
|
88
|
-
{ linter: 'SomeLinter',
|
89
|
-
problem: 'Some problem',
|
90
|
-
location: 'path/to/the_file:11' }, # larger number that is alphabetically lower
|
91
|
-
{ linter: 'SomeLinter',
|
92
|
-
problem: 'Some problem',
|
93
|
-
location: 'path/to/the_file:3' }, # duplicate number
|
94
|
-
{ linter: 'SomeLinter',
|
95
|
-
problem: 'Some problem',
|
96
|
-
location: 'path/to/the_file' }, # no number
|
97
|
-
{ linter: 'SomeLinter',
|
98
|
-
problem: 'Some problem',
|
99
|
-
location: 'path/to/the_file:1' }]
|
100
|
-
|
101
|
-
results = subject.format(linting_data)
|
102
|
-
|
103
|
-
expect(results).to eq(['SomeLinter',
|
104
|
-
' Some problem',
|
105
|
-
' path/to/the_file',
|
106
|
-
' path/to/the_file:1',
|
107
|
-
' path/to/the_file:2',
|
108
|
-
' path/to/the_file:3',
|
109
|
-
' path/to/the_file:3',
|
110
|
-
' path/to/the_file:11',
|
111
|
-
'',
|
112
|
-
'6 issues found'].join("\n"))
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::BackgroundDoesMoreThanSetupLinter 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('BackgroundDoesMoreThanSetupLinter')
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'linting' do
|
16
|
-
|
17
|
-
context 'a background with action steps' do
|
18
|
-
|
19
|
-
let(:test_model) do
|
20
|
-
CukeLinter::ModelFactory.generate_background_model(parent_file_path: model_file_path,
|
21
|
-
source_text: 'Background:
|
22
|
-
When something')
|
23
|
-
end
|
24
|
-
|
25
|
-
it_should_behave_like 'a linter linting a bad model'
|
26
|
-
|
27
|
-
|
28
|
-
it 'records a problem' do
|
29
|
-
result = subject.lint(test_model)
|
30
|
-
|
31
|
-
expect(result[:problem]).to eq('Background has non-setup steps')
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'a background with verification steps' do
|
37
|
-
|
38
|
-
let(:test_model) do
|
39
|
-
CukeLinter::ModelFactory.generate_background_model(parent_file_path: model_file_path,
|
40
|
-
source_text: 'Background:
|
41
|
-
Then something')
|
42
|
-
end
|
43
|
-
|
44
|
-
it_should_behave_like 'a linter linting a bad model'
|
45
|
-
|
46
|
-
|
47
|
-
it 'records a problem' do
|
48
|
-
result = subject.lint(test_model)
|
49
|
-
|
50
|
-
expect(result[:problem]).to eq('Background has non-setup steps')
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'a background with only setup steps' do
|
56
|
-
|
57
|
-
let(:test_model) do
|
58
|
-
gherkin = 'Background:
|
59
|
-
Given something
|
60
|
-
* (plus something)'
|
61
|
-
|
62
|
-
CukeLinter::ModelFactory.generate_background_model(source_text: gherkin)
|
63
|
-
end
|
64
|
-
|
65
|
-
it_should_behave_like 'a linter linting a good model'
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'a non-background model' do
|
70
|
-
|
71
|
-
let(:test_model) { CukeModeler::Model.new }
|
72
|
-
|
73
|
-
it_should_behave_like 'a linter linting a good model'
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,248 +0,0 @@
|
|
1
|
-
require_relative '../../../../../environments/rspec_env'
|
2
|
-
|
3
|
-
|
4
|
-
RSpec.describe CukeLinter::ElementWithCommonTagsLinter 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('ElementWithCommonTagsLinter')
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'linting' do
|
16
|
-
|
17
|
-
ELEMENTS_WITH_TAGGABLE_CHILDREN.each do |model_type|
|
18
|
-
|
19
|
-
context "with a #{model_type} that has common tags on all of its children" do
|
20
|
-
|
21
|
-
let(:test_model) do
|
22
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
23
|
-
|
24
|
-
2.times do
|
25
|
-
child_model = CukeLinter::ModelFactory.generate_lintable_model
|
26
|
-
child_model.tags = [CukeLinter::ModelFactory.generate_tag_model(source_text: '@same')]
|
27
|
-
|
28
|
-
case model_type
|
29
|
-
when 'feature'
|
30
|
-
model.tests << child_model
|
31
|
-
when 'outline'
|
32
|
-
model.examples << child_model
|
33
|
-
else
|
34
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
model
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a linter linting a bad model'
|
43
|
-
|
44
|
-
|
45
|
-
it 'records a problem' do
|
46
|
-
result = subject.lint(test_model)
|
47
|
-
|
48
|
-
case model_type
|
49
|
-
when 'feature'
|
50
|
-
expect(result[:problem]).to match(/^All tests in Feature have tag '@\w+'\. Move tag to Feature level\.$/)
|
51
|
-
when 'outline'
|
52
|
-
expect(result[:problem]).to match(/^All Examples in Outline have tag '@\w+'\. Move tag to Outline level\.$/)
|
53
|
-
else
|
54
|
-
raise(ArgumentError, "Don't know how to verify a '#{model_type}'. Add a new case?")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'includes the name of the common tag found in the problem record' do
|
59
|
-
common_tag = test_model.children.first.tags.first.name
|
60
|
-
result = subject.lint(test_model)
|
61
|
-
expect(result[:problem]).to match(/have tag '#{common_tag}'\./)
|
62
|
-
|
63
|
-
test_model.children.first.tags = [CukeLinter::ModelFactory.generate_tag_model(source_text: '@still_same')]
|
64
|
-
test_model.children.last.tags = [CukeLinter::ModelFactory.generate_tag_model(source_text: '@still_same')]
|
65
|
-
|
66
|
-
common_tag = test_model.children.first.tags.first.name
|
67
|
-
result = subject.lint(test_model)
|
68
|
-
expect(result[:problem]).to match(/have tag '#{common_tag}'\./)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
context "with a #{model_type} that does not have common tags on all of its children" do
|
74
|
-
|
75
|
-
context 'because none of their tags are common' do
|
76
|
-
|
77
|
-
let(:test_model) do
|
78
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
79
|
-
|
80
|
-
2.times do |count|
|
81
|
-
child_model = CukeLinter::ModelFactory.generate_lintable_model
|
82
|
-
child_model.tags = [CukeLinter::ModelFactory.generate_tag_model(source_text: "@tag_#{count}")]
|
83
|
-
|
84
|
-
case model_type
|
85
|
-
when 'feature'
|
86
|
-
model.tests << child_model
|
87
|
-
when 'outline'
|
88
|
-
model.examples << child_model
|
89
|
-
else
|
90
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
model
|
96
|
-
end
|
97
|
-
|
98
|
-
it_should_behave_like 'a linter linting a good model'
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'because some of them have no tags' do
|
103
|
-
|
104
|
-
context 'because their tags are empty' do
|
105
|
-
|
106
|
-
let(:test_model) do
|
107
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
108
|
-
|
109
|
-
2.times do
|
110
|
-
child_model = CukeLinter::ModelFactory.generate_lintable_model
|
111
|
-
child_model.tags = []
|
112
|
-
|
113
|
-
case model_type
|
114
|
-
when 'feature'
|
115
|
-
model.tests << child_model
|
116
|
-
when 'outline'
|
117
|
-
model.examples << child_model
|
118
|
-
else
|
119
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
model
|
125
|
-
end
|
126
|
-
|
127
|
-
it_should_behave_like 'a linter linting a good model'
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'because their tags are nil' do
|
132
|
-
|
133
|
-
let(:test_model) do
|
134
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
135
|
-
|
136
|
-
2.times do
|
137
|
-
child_model = CukeLinter::ModelFactory.generate_lintable_model
|
138
|
-
child_model.tags = nil
|
139
|
-
|
140
|
-
case model_type
|
141
|
-
when 'feature'
|
142
|
-
model.tests << child_model
|
143
|
-
when 'outline'
|
144
|
-
model.examples << child_model
|
145
|
-
else
|
146
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
model
|
152
|
-
end
|
153
|
-
|
154
|
-
it_should_behave_like 'a linter linting a good model'
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
context 'because the model only has one child' do
|
161
|
-
|
162
|
-
let(:test_model) do
|
163
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
164
|
-
|
165
|
-
1.times do
|
166
|
-
child_model = CukeLinter::ModelFactory.generate_lintable_model
|
167
|
-
child_model.tags = [CukeLinter::ModelFactory.generate_tag_model(source_text: '@a_tag')]
|
168
|
-
|
169
|
-
case model_type
|
170
|
-
when 'feature'
|
171
|
-
model.tests << child_model
|
172
|
-
when 'outline'
|
173
|
-
model.examples << child_model
|
174
|
-
else
|
175
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
model
|
181
|
-
end
|
182
|
-
|
183
|
-
it_should_behave_like 'a linter linting a good model'
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'because the model has no children' do
|
188
|
-
|
189
|
-
context 'because the children are empty' do
|
190
|
-
|
191
|
-
let(:test_model) do
|
192
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
193
|
-
|
194
|
-
case model_type
|
195
|
-
when 'feature'
|
196
|
-
model.tests = []
|
197
|
-
when 'outline'
|
198
|
-
model.examples = []
|
199
|
-
else
|
200
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
201
|
-
end
|
202
|
-
|
203
|
-
model
|
204
|
-
end
|
205
|
-
|
206
|
-
it_should_behave_like 'a linter linting a good model'
|
207
|
-
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'because the children are nil' do
|
211
|
-
|
212
|
-
let(:test_model) do
|
213
|
-
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
|
214
|
-
|
215
|
-
case model_type
|
216
|
-
when 'feature'
|
217
|
-
model.tests = nil
|
218
|
-
when 'outline'
|
219
|
-
model.examples = nil
|
220
|
-
else
|
221
|
-
raise(ArgumentError, "Don't know how to setup a '#{model_type}'. Add a new case?")
|
222
|
-
end
|
223
|
-
|
224
|
-
model
|
225
|
-
end
|
226
|
-
|
227
|
-
it_should_behave_like 'a linter linting a good model'
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
context 'a model that is not a type that has taggable children' do
|
239
|
-
|
240
|
-
let(:test_model) { CukeModeler::Model.new }
|
241
|
-
|
242
|
-
it_should_behave_like 'a linter linting a good model'
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
end
|