cuke_linter 0.13.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +4 -4
  4. data/cuke_linter.gemspec +3 -3
  5. data/lib/cuke_linter.rb +5 -3
  6. data/lib/cuke_linter/version.rb +1 -1
  7. metadata +2 -86
  8. data/.gitignore +0 -19
  9. data/.simplecov +0 -8
  10. data/.travis.yml +0 -33
  11. data/CONTRIBUTING.md +0 -26
  12. data/Gemfile +0 -6
  13. data/Rakefile +0 -63
  14. data/appveyor.yml +0 -43
  15. data/bin/console +0 -14
  16. data/bin/setup +0 -8
  17. data/environments/common_env.rb +0 -12
  18. data/environments/cucumber_env.rb +0 -22
  19. data/environments/rspec_env.rb +0 -50
  20. data/testing/cucumber/step_definitions/action_steps.rb +0 -84
  21. data/testing/cucumber/step_definitions/setup_steps.rb +0 -258
  22. data/testing/cucumber/step_definitions/verification_steps.rb +0 -94
  23. data/testing/file_helper.rb +0 -41
  24. data/testing/formatter_factory.rb +0 -15
  25. data/testing/gemfiles/cuke_modeler1.gemfile +0 -8
  26. data/testing/gemfiles/cuke_modeler2.gemfile +0 -8
  27. data/testing/linter_factory.rb +0 -60
  28. data/testing/model_factory.rb +0 -109
  29. data/testing/rspec/spec/integration/cli_integration_spec.rb +0 -556
  30. data/testing/rspec/spec/integration/configuration_spec.rb +0 -811
  31. data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +0 -243
  32. data/testing/rspec/spec/integration/formatters/formatter_integration_specs.rb +0 -5
  33. data/testing/rspec/spec/integration/formatters/pretty_formatter_integration_spec.rb +0 -8
  34. data/testing/rspec/spec/integration/linters/background_does_more_than_setup_linter_integration_spec.rb +0 -8
  35. data/testing/rspec/spec/integration/linters/element_with_common_tags_linter_integration_spec.rb +0 -8
  36. data/testing/rspec/spec/integration/linters/element_with_duplicate_tags_linter_integration_spec.rb +0 -8
  37. data/testing/rspec/spec/integration/linters/element_with_too_many_tags_linter_integration_spec.rb +0 -8
  38. data/testing/rspec/spec/integration/linters/example_without_name_linter_integration_spec.rb +0 -8
  39. data/testing/rspec/spec/integration/linters/feature_file_with_invalid_name_integration_spec.rb +0 -8
  40. data/testing/rspec/spec/integration/linters/feature_file_with_mismatched_name_integration_spec.rb +0 -8
  41. data/testing/rspec/spec/integration/linters/feature_with_too_many_different_tags_linter_integration_spec.rb +0 -8
  42. data/testing/rspec/spec/integration/linters/feature_without_description_linter_integration_spec.rb +0 -8
  43. data/testing/rspec/spec/integration/linters/feature_without_name_linter_integration_spec.rb +0 -8
  44. data/testing/rspec/spec/integration/linters/feature_without_scenarios_linter_integration_spec.rb +0 -8
  45. data/testing/rspec/spec/integration/linters/linter_integration_spec.rb +0 -8
  46. data/testing/rspec/spec/integration/linters/linter_integration_specs.rb +0 -7
  47. data/testing/rspec/spec/integration/linters/outline_with_single_example_row_linter_integration_spec.rb +0 -8
  48. data/testing/rspec/spec/integration/linters/single_test_background_linter_integration_spec.rb +0 -8
  49. data/testing/rspec/spec/integration/linters/step_with_end_period_linter_integration_spec.rb +0 -8
  50. data/testing/rspec/spec/integration/linters/step_with_too_many_characters_linter_integration_spec.rb +0 -8
  51. data/testing/rspec/spec/integration/linters/test_should_use_background_linter_integration_spec.rb +0 -8
  52. data/testing/rspec/spec/integration/linters/test_with_action_step_as_final_step_linter_integration_spec.rb +0 -8
  53. data/testing/rspec/spec/integration/linters/test_with_bad_name_integration_spec.rb +0 -8
  54. data/testing/rspec/spec/integration/linters/test_with_no_action_step_integration_spec.rb +0 -8
  55. data/testing/rspec/spec/integration/linters/test_with_no_name_integration_spec.rb +0 -8
  56. data/testing/rspec/spec/integration/linters/test_with_no_verification_step_integration_spec.rb +0 -8
  57. data/testing/rspec/spec/integration/linters/test_with_setup_step_after_action_step_linter_integration_spec.rb +0 -8
  58. data/testing/rspec/spec/integration/linters/test_with_setup_step_after_verification_step_linter_integration_spec.rb +0 -8
  59. data/testing/rspec/spec/integration/linters/test_with_setup_step_as_final_step_linter_integration_spec.rb +0 -8
  60. data/testing/rspec/spec/integration/linters/test_with_too_many_steps_linter_integration_spec.rb +0 -8
  61. data/testing/rspec/spec/unit/cuke_linter_unit_spec.rb +0 -114
  62. data/testing/rspec/spec/unit/formatters/formatter_unit_specs.rb +0 -11
  63. data/testing/rspec/spec/unit/formatters/pretty_formatter_unit_spec.rb +0 -115
  64. data/testing/rspec/spec/unit/linters/background_does_more_than_setup_linter_unit_spec.rb +0 -186
  65. data/testing/rspec/spec/unit/linters/configurable_linter_unit_specs.rb +0 -11
  66. data/testing/rspec/spec/unit/linters/element_with_common_tags_linter_unit_spec.rb +0 -248
  67. data/testing/rspec/spec/unit/linters/element_with_duplicate_tags_linter_unit_spec.rb +0 -203
  68. data/testing/rspec/spec/unit/linters/element_with_too_many_tags_linter_unit_spec.rb +0 -296
  69. data/testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb +0 -81
  70. data/testing/rspec/spec/unit/linters/feature_file_with_invalid_name_linter_unit_spec.rb +0 -106
  71. data/testing/rspec/spec/unit/linters/feature_file_with_mismatched_name_linter_unit_spec.rb +0 -124
  72. data/testing/rspec/spec/unit/linters/feature_with_too_many_different_tags_linter_unit_spec.rb +0 -293
  73. data/testing/rspec/spec/unit/linters/feature_without_description_linter_unit_spec.rb +0 -80
  74. data/testing/rspec/spec/unit/linters/feature_without_name_linter_unit_spec.rb +0 -84
  75. data/testing/rspec/spec/unit/linters/feature_without_scenarios_linter_unit_spec.rb +0 -102
  76. data/testing/rspec/spec/unit/linters/linter_unit_spec.rb +0 -197
  77. data/testing/rspec/spec/unit/linters/linter_unit_specs.rb +0 -57
  78. data/testing/rspec/spec/unit/linters/outline_with_single_example_row_linter_unit_spec.rb +0 -184
  79. data/testing/rspec/spec/unit/linters/single_test_background_linter_unit_spec.rb +0 -89
  80. data/testing/rspec/spec/unit/linters/step_with_end_period_linter_unit_spec.rb +0 -54
  81. data/testing/rspec/spec/unit/linters/step_with_too_many_characters_linter_unit_spec.rb +0 -155
  82. data/testing/rspec/spec/unit/linters/test_should_use_background_linter_unit_spec.rb +0 -464
  83. data/testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb +0 -165
  84. data/testing/rspec/spec/unit/linters/test_with_bad_name_linter_unit_spec.rb +0 -81
  85. data/testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb +0 -244
  86. data/testing/rspec/spec/unit/linters/test_with_no_name_linter_unit_spec.rb +0 -88
  87. data/testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb +0 -246
  88. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_action_step_linter_unit_spec.rb +0 -233
  89. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_verification_step_linter_unit_spec.rb +0 -233
  90. data/testing/rspec/spec/unit/linters/test_with_setup_step_as_final_step_linter_unit_spec.rb +0 -164
  91. data/testing/rspec/spec/unit/linters/test_with_too_many_steps_linter_unit_spec.rb +0 -192
@@ -1,811 +0,0 @@
1
- require_relative '../../../../environments/rspec_env'
2
-
3
- RSpec.describe CukeLinter do
4
-
5
- describe 'configuration' do
6
-
7
- describe 'blanket linters' do
8
-
9
- let(:test_model_tree) { CukeLinter::ModelFactory.generate_lintable_model }
10
- let(:test_linters) { [CukeLinter::LinterFactory.generate_fake_linter] }
11
- let(:test_formatters) { [[CukeLinter::FormatterFactory.generate_fake_formatter, "#{CukeLinter::FileHelper::create_directory}/junk_output_file.txt"]] }
12
- let(:linting_options) { { model_trees: [test_model_tree], linters: test_linters, formatters: test_formatters } }
13
-
14
-
15
- it 'unregisters disabled linters' do
16
- config = { 'FakeLinter1' => { 'Enabled' => false } }
17
- configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
18
-
19
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
20
- expect(subject.registered_linters['FakeLinter1']).to_not be nil
21
-
22
- subject.load_configuration(config_file_path: configuration_file)
23
-
24
- expect(subject.registered_linters['FakeLinter1']).to be nil
25
- end
26
-
27
- it 'can apply a property to all linters' do
28
- configuration = { 'AllLinters' => { 'Enabled' => false } }
29
-
30
- # Restore the default linters
31
- CukeLinter.reset_linters
32
-
33
- # Also add some custom ones
34
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'Foo')
35
-
36
-
37
- subject.load_configuration(config: configuration)
38
-
39
- expect(subject.registered_linters).to be_empty
40
- end
41
-
42
- it 'uses linter specific properties over general properties' do
43
- configuration = { 'AllLinters' => { 'Enabled' => false },
44
- 'FakeLinter1' => { 'Enabled' => true } }
45
-
46
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'FakeLinter1')
47
- expect(subject.registered_linters['FakeLinter1']).to_not be nil
48
-
49
- subject.load_configuration(config: configuration)
50
-
51
- expect(subject.registered_linters['FakeLinter1']).to_not be nil
52
- end
53
-
54
- it 'even unregisters non-configurable disabled linters' do
55
- config = { 'FakeLinter' => { 'Enabled' => false } }
56
- configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
57
- non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
58
- non_configurable_linter.instance_eval('undef :configure')
59
-
60
- CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
61
- expect(subject.registered_linters['FakeLinter']).to_not be nil
62
-
63
- subject.load_configuration(config_file_path: configuration_file)
64
-
65
- expect(subject.registered_linters['FakeLinter']).to be nil
66
- end
67
-
68
- it 'uses the default configuration file in the current directory if no configuration file is provided' do
69
- config = { 'FakeLinter1' => { 'Enabled' => false } }
70
- configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
71
-
72
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
73
- expect(subject.registered_linters['FakeLinter1']).to_not be nil
74
-
75
- Dir.chdir(File.dirname(configuration_file)) do
76
- subject.load_configuration
77
- end
78
-
79
- expect(subject.registered_linters['FakeLinter1']).to be nil
80
- end
81
-
82
- it 'raises an exception if no default configuration file is found and no configuration or file is provided' do
83
- some_empty_directory = CukeLinter::FileHelper.create_directory
84
-
85
- Dir.chdir(File.dirname(some_empty_directory)) do
86
- expect { subject.load_configuration }.to raise_error('No configuration or configuration file given and no .cuke_linter file found')
87
- end
88
- end
89
-
90
- it 'configures every linter for which it has a configuration' do
91
- config = { 'FakeLinter1' => { 'Problem' => 'My custom message for FakeLinter1' },
92
- 'FakeLinter2' => { 'Problem' => 'My custom message for FakeLinter2' } }
93
-
94
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
95
- CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter2'), name: 'FakeLinter2')
96
- linting_options.delete(:linters)
97
-
98
- subject.load_configuration(config: config)
99
- results = subject.lint(linting_options)
100
-
101
- expect(results).to match_array([{ linter: 'FakeLinter1', location: 'path_to_file:1', problem: 'My custom message for FakeLinter1' },
102
- { linter: 'FakeLinter2', location: 'path_to_file:1', problem: 'My custom message for FakeLinter2' }])
103
- end
104
-
105
- it "does not try to configure linters that don't know how to be configured" do
106
- config = { 'FakeLinter' => { 'Problem' => 'My custom message for FakeLinter' } }
107
- non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
108
- non_configurable_linter.instance_eval('undef :configure')
109
-
110
- CukeLinter.clear_registered_linters
111
- CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
112
- linting_options.delete(:linters)
113
-
114
- subject.load_configuration(config: config)
115
- results = subject.lint(linting_options)
116
-
117
- expect(results).to match_array([{ linter: 'FakeLinter', location: 'path_to_file:1', problem: 'FakeLinter problem' }])
118
- end
119
-
120
- end
121
-
122
- describe 'targeted linters' do
123
-
124
- before(:all) do
125
- @targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(class_name: 'ATargetedLinterClass', name: 'ATargetedLinter')
126
- @another_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(class_name: 'AnotherTargetedLinterClass', name: 'AnotherTargetedLinter')
127
- @yet_another_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(class_name: 'YetAnotherTargetedLinterClass', name: 'YetAnotherTargetedLinter')
128
-
129
- @a_non_nested_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(module_name: nil, class_name: 'ANonNestedTargetedLinterClass', name: 'ANonNestedTargetedLinter')
130
- @another_non_nested_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(module_name: nil, class_name: 'AnotherNonNestedTargetedLinterClass', name: 'AnotherNonNestedTargetedLinter')
131
-
132
- @a_nested_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(module_name: 'Foo', class_name: 'ANestedTargetedLinterClass', name: 'ANestedTargetedLinter')
133
- @another_nested_targeted_linter_class = CukeLinter::LinterFactory.generate_fake_linter_class(module_name: 'Foo', class_name: 'AnotherNestedTargetedLinterClass', name: 'AnotherNestedTargetedLinter')
134
- end
135
-
136
-
137
- let(:linter_name) { 'ATargetedLinter' }
138
- let(:another_linter_name) { 'AnotherTargetedLinter' }
139
- let(:yet_another_linter_name) { 'YetAnotherTargetedLinter' }
140
-
141
- let(:non_nested_linter_name) { 'ANonNestedTargetedLinter' }
142
- let(:another_non_nested_linter_name) { 'AnotherNonNestedTargetedLinter' }
143
- let(:nested_linter_name) { 'ANestedTargetedLinter' }
144
- let(:another_nested_linter_name) { 'AnotherNestedTargetedLinter' }
145
-
146
- let(:linter_class_name) { 'ATargetedLinterClass' }
147
- let(:another_linter_class_name) { 'AnotherTargetedLinterClass' }
148
- let(:yet_another_linter_class_name) { 'YetAnotherTargetedLinterClass' }
149
- let(:non_nested_linter_class_name) { 'ANonNestedTargetedLinterClass' }
150
- let(:another_non_nested_linter_class_name) { 'AnotherNonNestedTargetedLinterClass' }
151
- let(:nested_linter_class_name) { 'Foo::ANestedTargetedLinterClass' }
152
- let(:another_nested_linter_class_name) { 'Foo::AnotherNestedTargetedLinterClass' }
153
-
154
- let(:targeted_linter) { @targeted_linter_class.new }
155
- let(:another_targeted_linter) { @another_targeted_linter_class.new }
156
- let(:yet_another_targeted_linter) { @yet_another_targeted_linter_class.new }
157
- let(:non_nested_targeted_linter) { @a_non_nested_targeted_linter_class.new }
158
- let(:nested_targeted_linter) { @a_nested_targeted_linter_class.new }
159
-
160
- let(:test_linters) { [targeted_linter] }
161
- let(:test_linter_names) { [linter_name] }
162
- let(:test_formatters) { [[CukeLinter::FormatterFactory.generate_fake_formatter, "#{CukeLinter::FileHelper::create_directory}/junk_output_file.txt"]] }
163
- let(:test_model_trees) { [CukeModeler::FeatureFile.new(linted_file)] }
164
-
165
- let(:test_directory) { CukeLinter::FileHelper.create_directory }
166
- let(:linted_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
167
- extension: '.feature',
168
- text: file_text) }
169
-
170
-
171
- [:provided, :registered].each do |linter_type|
172
-
173
- context "using #{linter_type} linters" do
174
-
175
- if linter_type == :provided
176
- let(:linting_options) { { model_trees: test_model_trees, linters: test_linters, formatters: test_formatters } }
177
- else
178
- let(:linting_options) { { model_trees: test_model_trees, formatters: test_formatters } }
179
-
180
- before(:each) do
181
- subject.clear_registered_linters
182
-
183
- test_linters.each_with_index { |linter, index| subject.register_linter(linter: linter, name: test_linter_names[index]) }
184
- end
185
- end
186
-
187
-
188
- context 'with non-nested class names' do
189
-
190
- let(:test_linters) { [non_nested_targeted_linter] }
191
- let(:test_linter_names) { [non_nested_linter_name] }
192
-
193
- let(:file_text) { "Feature:
194
-
195
- # cuke_linter:disable #{non_nested_linter_class_name}
196
- # cuke_linter:enable #{another_non_nested_linter_class_name}
197
- Scenario:" }
198
-
199
-
200
- it 'handles the directives correctly' do
201
- results = subject.lint(linting_options)
202
-
203
- expect(results).to match_array([{ linter: non_nested_linter_name, location: linted_file, problem: "#{non_nested_linter_name} problem" },
204
- { linter: non_nested_linter_name, location: "#{linted_file}:1", problem: "#{non_nested_linter_name} problem" },
205
- { linter: another_non_nested_linter_name, location: "#{linted_file}:5", problem: "#{another_non_nested_linter_name} problem" }])
206
- end
207
-
208
- end
209
-
210
- context 'with nested class names' do
211
-
212
- let(:test_linters) { [nested_targeted_linter] }
213
- let(:test_linter_names) { [nested_linter_name] }
214
-
215
- let(:file_text) { "Feature:
216
-
217
- # cuke_linter:disable #{nested_linter_class_name}
218
- # cuke_linter:enable #{another_nested_linter_class_name}
219
- Scenario:" }
220
-
221
-
222
- it 'handles the directives correctly' do
223
- results = subject.lint(linting_options)
224
-
225
- expect(results).to match_array([{ linter: nested_linter_name, location: linted_file, problem: "#{nested_linter_name} problem" },
226
- { linter: nested_linter_name, location: "#{linted_file}:1", problem: "#{nested_linter_name} problem" },
227
- { linter: another_nested_linter_name, location: "#{linted_file}:5", problem: "#{another_nested_linter_name} problem" }])
228
- end
229
-
230
- end
231
-
232
- context 'with multiple linters in the directive' do
233
-
234
- let(:commas_text) { "Feature:
235
-
236
- # cuke_linter:disable #{linter_class_name}, #{another_linter_class_name}, #{yet_another_linter_class_name}
237
- Scenario:" }
238
- let(:commas_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
239
- extension: '.feature',
240
- text: commas_text,
241
- name: 'commas_text') }
242
-
243
- let(:spaces_text) { "Feature:
244
-
245
- # cuke_linter:disable #{linter_class_name} #{another_linter_class_name} #{yet_another_linter_class_name}
246
- Scenario:" }
247
- let(:spaces_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
248
- extension: '.feature',
249
- text: spaces_text,
250
- name: 'spaces_text') }
251
-
252
- let(:test_model_trees) { [CukeModeler::FeatureFile.new(commas_file),
253
- CukeModeler::FeatureFile.new(spaces_file)] }
254
-
255
- let(:test_linters) { [targeted_linter, another_targeted_linter, yet_another_targeted_linter] }
256
- let(:test_linter_names) { [linter_name, another_linter_name, yet_another_linter_name] }
257
-
258
-
259
- it 'handles the directives correctly' do
260
- results = subject.lint(linting_options)
261
-
262
- expect(results).to match_array([{ linter: linter_name, location: spaces_file, problem: "#{linter_name} problem" },
263
- { linter: linter_name, location: "#{spaces_file}:1", problem: "#{linter_name} problem" },
264
- { linter: another_linter_name, location: spaces_file, problem: "#{another_linter_name} problem" },
265
- { linter: another_linter_name, location: "#{spaces_file}:1", problem: "#{another_linter_name} problem" },
266
- { linter: yet_another_linter_name, location: spaces_file, problem: "#{yet_another_linter_name} problem" },
267
- { linter: yet_another_linter_name, location: "#{spaces_file}:1", problem: "#{yet_another_linter_name} problem" },
268
-
269
- { linter: linter_name, location: commas_file, problem: "#{linter_name} problem" },
270
- { linter: linter_name, location: "#{commas_file}:1", problem: "#{linter_name} problem" },
271
- { linter: another_linter_name, location: commas_file, problem: "#{another_linter_name} problem" },
272
- { linter: another_linter_name, location: "#{commas_file}:1", problem: "#{another_linter_name} problem" },
273
- { linter: yet_another_linter_name, location: commas_file, problem: "#{yet_another_linter_name} problem" },
274
- { linter: yet_another_linter_name, location: "#{commas_file}:1", problem: "#{yet_another_linter_name} problem" }])
275
- end
276
-
277
- end
278
-
279
- context 'with multiple files' do
280
-
281
- let(:modified_text) { "Feature:
282
-
283
- # cuke_linter:disable #{linter_class_name}
284
- Scenario:" }
285
- let(:modified_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
286
- extension: '.feature',
287
- text: modified_text) }
288
- let(:unmodified_text) { "Feature:
289
-
290
- Scenario:" }
291
- let(:unmodified_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
292
- extension: '.feature',
293
- text: unmodified_text) }
294
-
295
- let(:test_model_trees) { [CukeModeler::FeatureFile.new(modified_file),
296
- CukeModeler::FeatureFile.new(unmodified_file)] }
297
-
298
- it 'does not use targeted linting changes outside of the file in which they occur' do
299
- results = subject.lint(linting_options)
300
-
301
- expect(results).to match_array([{ linter: linter_name, location: modified_file, problem: "#{linter_name} problem" },
302
- { linter: linter_name, location: "#{modified_file}:1", problem: "#{linter_name} problem" },
303
- { linter: linter_name, location: unmodified_file, problem: "#{linter_name} problem" },
304
- { linter: linter_name, location: "#{unmodified_file}:1", problem: "#{linter_name} problem" },
305
- { linter: linter_name, location: "#{unmodified_file}:3", problem: "#{linter_name} problem" }])
306
- end
307
-
308
- end
309
-
310
- context 'with other comments in the file' do
311
-
312
- let(:file_text) { "# I'm just a comment
313
- Feature:
314
-
315
- # cuke_linter:disable #{linter_class_name}
316
- #Me too
317
- Scenario:" }
318
-
319
-
320
- it 'handles the directive correctly' do
321
- results = subject.lint(linting_options)
322
-
323
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
324
- { linter: linter_name, location: "#{linted_file}:2", problem: "#{linter_name} problem" }])
325
- end
326
-
327
- end
328
-
329
- context 'with varying whitespace' do
330
-
331
- let(:extra_whitespace_text) { "Feature:
332
-
333
- # cuke_linter:disable #{linter_class_name}
334
- Scenario:" }
335
- let(:extra_whitespace_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
336
- extension: '.feature',
337
- text: extra_whitespace_text) }
338
- let(:minimal_whitespace_text) { "Feature:
339
-
340
- #cuke_linter:disable #{linter_class_name}
341
- Scenario:" }
342
- let(:minimal_whitespace_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
343
- extension: '.feature',
344
- text: minimal_whitespace_text) }
345
-
346
- let(:test_model_trees) { [CukeModeler::FeatureFile.new(extra_whitespace_file),
347
- CukeModeler::FeatureFile.new(minimal_whitespace_file)] }
348
-
349
-
350
- it 'handles the directives correctly' do
351
- results = subject.lint(linting_options)
352
-
353
- expect(results).to match_array([{ linter: linter_name, location: extra_whitespace_file, problem: "#{linter_name} problem" },
354
- { linter: linter_name, location: "#{extra_whitespace_file}:1", problem: "#{linter_name} problem" },
355
- { linter: linter_name, location: minimal_whitespace_file, problem: "#{linter_name} problem" },
356
- { linter: linter_name, location: "#{minimal_whitespace_file}:1", problem: "#{linter_name} problem" }])
357
- end
358
-
359
-
360
- context 'and multiple targeted linters' do
361
-
362
- let(:spaced_commas_text) { "Feature:
363
-
364
- # cuke_linter:disable #{linter_class_name} , #{another_linter_class_name} , #{yet_another_linter_class_name}
365
- Scenario:" }
366
- let(:spaced_commas_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
367
- extension: '.feature',
368
- text: spaced_commas_text,
369
- name: 'spaced_commas_text') }
370
-
371
- let(:compact_commas_text) { "Feature:
372
-
373
- # cuke_linter:disable #{linter_class_name},#{another_linter_class_name},#{yet_another_linter_class_name}
374
- Scenario:" }
375
- let(:compact_commas_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
376
- extension: '.feature',
377
- text: compact_commas_text,
378
- name: 'compact_commas_text') }
379
-
380
- let(:spaced_space_text) { "Feature:
381
-
382
- # cuke_linter:disable #{linter_class_name} #{another_linter_class_name} #{yet_another_linter_class_name}
383
- Scenario:" }
384
- let(:spaced_space_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
385
- extension: '.feature',
386
- text: spaced_space_text,
387
- name: 'spaced_space_text') }
388
-
389
- let(:compact_space_text) { "Feature:
390
-
391
- # cuke_linter:disable #{linter_class_name} #{another_linter_class_name} #{yet_another_linter_class_name}
392
- Scenario:" }
393
- let(:compact_space_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
394
- extension: '.feature',
395
- text: compact_space_text,
396
- name: 'compact_space_text') }
397
-
398
- let(:test_model_trees) { [CukeModeler::FeatureFile.new(spaced_commas_file),
399
- CukeModeler::FeatureFile.new(compact_commas_file),
400
- CukeModeler::FeatureFile.new(spaced_space_file),
401
- CukeModeler::FeatureFile.new(compact_space_file)] }
402
-
403
- let(:test_linters) { [targeted_linter, another_targeted_linter, yet_another_targeted_linter] }
404
- let(:test_linter_names) { [linter_name, another_linter_name, yet_another_linter_name] }
405
-
406
-
407
- it 'handles the directives correctly' do
408
- results = subject.lint(linting_options)
409
-
410
- expect(results).to match_array([{ linter: linter_name, location: spaced_commas_file, problem: "#{linter_name} problem" },
411
- { linter: linter_name, location: "#{spaced_commas_file}:1", problem: "#{linter_name} problem" },
412
- { linter: another_linter_name, location: spaced_commas_file, problem: "#{another_linter_name} problem" },
413
- { linter: another_linter_name, location: "#{spaced_commas_file}:1", problem: "#{another_linter_name} problem" },
414
- { linter: yet_another_linter_name, location: spaced_commas_file, problem: "#{yet_another_linter_name} problem" },
415
- { linter: yet_another_linter_name, location: "#{spaced_commas_file}:1", problem: "#{yet_another_linter_name} problem" },
416
-
417
- { linter: linter_name, location: compact_commas_file, problem: "#{linter_name} problem" },
418
- { linter: linter_name, location: "#{compact_commas_file}:1", problem: "#{linter_name} problem" },
419
- { linter: another_linter_name, location: compact_commas_file, problem: "#{another_linter_name} problem" },
420
- { linter: another_linter_name, location: "#{compact_commas_file}:1", problem: "#{another_linter_name} problem" },
421
- { linter: yet_another_linter_name, location: compact_commas_file, problem: "#{yet_another_linter_name} problem" },
422
- { linter: yet_another_linter_name, location: "#{compact_commas_file}:1", problem: "#{yet_another_linter_name} problem" },
423
-
424
- { linter: linter_name, location: spaced_space_file, problem: "#{linter_name} problem" },
425
- { linter: linter_name, location: "#{spaced_space_file}:1", problem: "#{linter_name} problem" },
426
- { linter: another_linter_name, location: spaced_space_file, problem: "#{another_linter_name} problem" },
427
- { linter: another_linter_name, location: "#{spaced_space_file}:1", problem: "#{another_linter_name} problem" },
428
- { linter: yet_another_linter_name, location: spaced_space_file, problem: "#{yet_another_linter_name} problem" },
429
- { linter: yet_another_linter_name, location: "#{spaced_space_file}:1", problem: "#{yet_another_linter_name} problem" },
430
-
431
- { linter: linter_name, location: compact_space_file, problem: "#{linter_name} problem" },
432
- { linter: linter_name, location: "#{compact_space_file}:1", problem: "#{linter_name} problem" },
433
- { linter: another_linter_name, location: compact_space_file, problem: "#{another_linter_name} problem" },
434
- { linter: another_linter_name, location: "#{compact_space_file}:1", problem: "#{another_linter_name} problem" },
435
- { linter: yet_another_linter_name, location: compact_space_file, problem: "#{yet_another_linter_name} problem" },
436
- { linter: yet_another_linter_name, location: "#{compact_space_file}:1", problem: "#{yet_another_linter_name} problem" }])
437
- end
438
-
439
- end
440
-
441
- end
442
-
443
- context 'with a disabled(i.e. unregistered)/not provided linter' do
444
-
445
- if linter_type == :provided
446
- before(:each) do
447
- test_linters.delete(targeted_linter)
448
- end
449
- else
450
- before(:each) do
451
- subject.unregister_linter(linter_name)
452
- end
453
- end
454
-
455
-
456
- context 'that is explicitly disabled' do
457
-
458
- # Used so that the linting process is not entirely bypassed due to no other linters being registered/provided
459
- let(:baseline_linter_name) { 'BaselineLinter' }
460
- let(:baseline_linter) { CukeLinter::LinterFactory.generate_fake_linter(name: baseline_linter_name) }
461
-
462
- let(:test_linters) { [baseline_linter, targeted_linter] }
463
- let(:test_linter_names) { [baseline_linter_name, linter_name] }
464
-
465
-
466
- let(:file_text) { "Feature:
467
-
468
- # cuke_linter:disable #{linter_class_name}
469
- Scenario:" }
470
-
471
- let(:baseline_linter_results) { [{ linter: baseline_linter_name, location: linted_file, problem: "#{baseline_linter_name} problem" },
472
- { linter: baseline_linter_name, location: "#{linted_file}:1", problem: "#{baseline_linter_name} problem" },
473
- { linter: baseline_linter_name, location: "#{linted_file}:4", problem: "#{baseline_linter_name} problem" }] }
474
-
475
-
476
- it 'does not use the linter' do
477
- results = subject.lint(linting_options)
478
-
479
- expect(results).to match_array(baseline_linter_results + [])
480
- end
481
-
482
-
483
- context 'multiple times' do
484
-
485
- context 'with separate targetings' do
486
-
487
- let(:file_text) { "Feature:
488
- # cuke_linter:disable #{linter_class_name}
489
- # cuke_linter:disable #{linter_class_name}
490
- Scenario:" }
491
-
492
-
493
- it 'does not use the linter' do
494
- results = subject.lint(linting_options)
495
-
496
- expect(results).to match_array(baseline_linter_results + [])
497
- end
498
-
499
- end
500
-
501
- context 'with the same targeting' do
502
-
503
- let(:file_text) { "Feature:
504
-
505
- # cuke_linter:disable #{linter_class_name}, #{linter_class_name}
506
- Scenario:" }
507
-
508
- it 'does not use the linter' do
509
- results = subject.lint(linting_options)
510
-
511
- expect(results).to match_array(baseline_linter_results + [])
512
- end
513
-
514
- end
515
-
516
- end
517
-
518
- end
519
-
520
- context 'that is explicitly enabled' do
521
-
522
- let(:file_text) { "Feature:
523
-
524
- # cuke_linter:enable #{linter_class_name}
525
- Scenario:" }
526
-
527
- it 'uses the linter' do
528
- results = subject.lint(linting_options)
529
-
530
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
531
- end
532
-
533
- context 'multiple times' do
534
-
535
- context 'with separate targetings' do
536
-
537
- let(:file_text) { "Feature:
538
- # cuke_linter:enable #{linter_class_name}
539
- # cuke_linter:enable #{linter_class_name}
540
- Scenario:" }
541
-
542
- it 'uses the linter' do
543
- results = subject.lint(linting_options)
544
-
545
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
546
- end
547
-
548
- it 'does not include redundant linting results' do
549
- results = subject.lint(linting_options)
550
-
551
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
552
- end
553
-
554
- end
555
-
556
- context 'with the same targeting' do
557
-
558
- let(:file_text) { "Feature:
559
-
560
- # cuke_linter:enable #{linter_class_name}, #{linter_class_name}
561
- Scenario:" }
562
-
563
- it 'uses the linter' do
564
- results = subject.lint(linting_options)
565
-
566
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
567
- end
568
-
569
- it 'does not include redundant linting results' do
570
- results = subject.lint(linting_options)
571
-
572
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
573
- end
574
-
575
- end
576
-
577
- end
578
-
579
- context 'and then re-disabled' do
580
-
581
- let(:file_text) { "Feature:
582
-
583
- # cuke_linter:enable #{linter_class_name}
584
- Scenario:
585
- # cuke_linter:disable #{linter_class_name}
586
- Scenario:" }
587
-
588
- it 'ceases using the linter' do
589
- results = subject.lint(linting_options)
590
-
591
- expect(results).to match_array([{ linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
592
- end
593
-
594
- end
595
-
596
- end
597
-
598
- end
599
-
600
- context 'with an enabled(i.e. registered)/provided linter' do
601
-
602
- if linter_type == :provided
603
- before(:each) do
604
- test_linters << targeted_linter unless test_linters.include?(targeted_linter)
605
- end
606
- else
607
- before(:each) do
608
- subject.register_linter(linter: targeted_linter, name: linter_name)
609
- end
610
- end
611
-
612
-
613
- context 'that is explicitly disabled' do
614
-
615
- let(:file_text) { "Feature:
616
-
617
- # cuke_linter:disable #{linter_class_name}
618
- Scenario:" }
619
-
620
-
621
- it 'does not use the linter' do
622
- results = subject.lint(linting_options)
623
-
624
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
625
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" }])
626
- end
627
-
628
- context 'multiple times' do
629
-
630
- context 'with separate targetings' do
631
-
632
- let(:file_text) { "Feature:
633
- # cuke_linter:disable #{linter_class_name}
634
- # cuke_linter:disable #{linter_class_name}
635
- Scenario:" }
636
-
637
-
638
- it 'does not use the linter' do
639
- results = subject.lint(linting_options)
640
-
641
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
642
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" }])
643
- end
644
-
645
- end
646
-
647
- context 'with the same targeting' do
648
-
649
- let(:file_text) { "Feature:
650
-
651
- # cuke_linter:disable #{linter_class_name}, #{linter_class_name}
652
- Scenario:" }
653
-
654
- it 'does not use the linter' do
655
- results = subject.lint(linting_options)
656
-
657
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
658
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" }])
659
- end
660
- end
661
-
662
- end
663
-
664
- context 'and then re-enabled' do
665
-
666
- let(:file_text) { "Feature:
667
-
668
- # cuke_linter:disable #{linter_class_name}
669
- Scenario:
670
- # cuke_linter:enable #{linter_class_name}
671
- Scenario:" }
672
-
673
-
674
- it 'resumes using the linter' do
675
- results = subject.lint(linting_options)
676
-
677
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
678
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
679
- { linter: linter_name, location: "#{linted_file}:6", problem: "#{linter_name} problem" }])
680
- end
681
-
682
- it 'does not include redundant linting results' do
683
- results = subject.lint(linting_options)
684
-
685
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
686
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
687
- { linter: linter_name, location: "#{linted_file}:6", problem: "#{linter_name} problem" }])
688
- end
689
-
690
- end
691
-
692
- end
693
-
694
- context 'that is explicitly enabled' do
695
-
696
- let(:file_text) { "Feature:
697
-
698
- # cuke_linter:enable #{linter_class_name}
699
- Scenario:" }
700
-
701
-
702
- it 'uses the linter' do
703
- results = subject.lint(linting_options)
704
-
705
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
706
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
707
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
708
- end
709
-
710
- it 'does not include redundant linting results' do
711
- results = subject.lint(linting_options)
712
-
713
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
714
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
715
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
716
- end
717
-
718
- it 'prefers the provided (or registered) linter over having to make a new one' do
719
-
720
- # Tweaking the linter objects that will already exist so that any linter created from the same class will be noticeably different
721
- provided_linter = test_linters.find { |linter| linter.is_a?(Kernel.const_get(linter_class_name)) }
722
- registered_linter = CukeLinter.registered_linters.values.find { |linter| linter.is_a?(Kernel.const_get(linter_class_name)) }
723
-
724
- if provided_linter
725
- def provided_linter.name
726
- 'Pre-existing Linter'
727
- end
728
- end
729
-
730
- if registered_linter
731
- def registered_linter.name
732
- 'Pre-existing Linter'
733
- end
734
- end
735
-
736
-
737
- results = subject.lint(linting_options)
738
-
739
- expect(results).to match_array([{ linter: 'Pre-existing Linter', location: linted_file, problem: "#{linter_name} problem" },
740
- { linter: 'Pre-existing Linter', location: "#{linted_file}:1", problem: "#{linter_name} problem" },
741
- { linter: 'Pre-existing Linter', location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
742
- end
743
-
744
-
745
- context 'multiple times' do
746
-
747
- context 'with separate targetings' do
748
-
749
- let(:file_text) { "Feature:
750
- # cuke_linter:enable #{linter_class_name}
751
- # cuke_linter:enable #{linter_class_name}
752
- Scenario:" }
753
-
754
- it 'uses the linter' do
755
- results = subject.lint(linting_options)
756
-
757
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
758
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
759
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
760
- end
761
-
762
- it 'does not include redundant linting results' do
763
- results = subject.lint(linting_options)
764
-
765
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
766
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
767
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
768
- end
769
-
770
- end
771
-
772
- context 'with the same targeting' do
773
-
774
- let(:file_text) { "Feature:
775
-
776
- # cuke_linter:enable #{linter_class_name}, #{linter_class_name}
777
- Scenario:" }
778
-
779
- it 'uses the linter' do
780
- results = subject.lint(linting_options)
781
-
782
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
783
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
784
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
785
- end
786
-
787
- it 'does not include redundant linting results' do
788
- results = subject.lint(linting_options)
789
-
790
- expect(results).to match_array([{ linter: linter_name, location: linted_file, problem: "#{linter_name} problem" },
791
- { linter: linter_name, location: "#{linted_file}:1", problem: "#{linter_name} problem" },
792
- { linter: linter_name, location: "#{linted_file}:4", problem: "#{linter_name} problem" }])
793
- end
794
-
795
- end
796
-
797
- end
798
-
799
- end
800
-
801
- end
802
-
803
- end
804
-
805
- end
806
-
807
- end
808
-
809
- end
810
-
811
- end