cuke_linter 0.7.0 → 0.8.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 +10 -2
- data/environments/common_env.rb +1 -0
- data/exe/cuke_linter +5 -3
- data/lib/cuke_linter/version.rb +1 -1
- data/testing/cucumber/features/command_line.feature +8 -0
- data/testing/cucumber/step_definitions/action_steps.rb +45 -0
- data/testing/cucumber/step_definitions/verification_steps.rb +4 -0
- data/testing/rspec/spec/integration/cli_integration_spec.rb +57 -8
- data/testing/rspec/spec/integration/configuration_spec.rb +120 -0
- data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +0 -109
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef55f6c2d957526d16d14a9f9624fe5ea7638ba0f1b7ea2ea52244fe9805e60b
|
4
|
+
data.tar.gz: df6e881179035f9edb0f3c7b50a2826ff302049c2926399cee1e1570c0bcfad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62718d8b395cddf100152b9a6c6b63cc0c4349c2715fc0261ef985000047853753835ff7d341894ad0ce6eef37b032885c75a3a569b2afaf62a2b33809b9a99
|
7
|
+
data.tar.gz: 9b239647d5f4f45c7454f0cfbe9c31777b8fe56064c7f99b3cab9ac237551dccc71404afa1cc4e462c10295220f1c3bfd6de7cc60d88e71da7961a13fced62c9
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
|
9
9
|
Nothing yet...
|
10
10
|
|
11
|
+
## [0.8.0] - 2019-09-07
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- The exit codes used by the CLI have been changed in order to better facilitate taking additional actions based on them.
|
15
|
+
- 0 - No linting problems found
|
16
|
+
- 1 - Linting problems found
|
17
|
+
- 2 - Some other problem (e.g. incorrect CLI usage)
|
11
18
|
|
12
19
|
## [0.7.0] - 2019-07-12
|
13
20
|
|
@@ -78,8 +85,9 @@ Nothing yet...
|
|
78
85
|
- Custom linters, formatters, and command line usability
|
79
86
|
|
80
87
|
|
81
|
-
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.
|
82
|
-
[0.
|
88
|
+
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.8.0...HEAD
|
89
|
+
[0.8.0]: https://github.com/enkessler/cuke_linter/compare/v0.7.0...v0.8.0
|
90
|
+
[0.7.0]: https://github.com/enkessler/cuke_linter/compare/v0.6.0...v0.7.0
|
83
91
|
[0.6.0]: https://github.com/enkessler/cuke_linter/compare/v0.5.0...v0.6.0
|
84
92
|
[0.5.0]: https://github.com/enkessler/cuke_linter/compare/v0.4.0...v0.5.0
|
85
93
|
[0.4.0]: https://github.com/enkessler/cuke_linter/compare/v0.3.1...v0.4.0
|
data/environments/common_env.rb
CHANGED
data/exe/cuke_linter
CHANGED
@@ -51,7 +51,7 @@ parser = OptionParser.new do |options|
|
|
51
51
|
|
52
52
|
if params[:config]
|
53
53
|
puts 'Cannot specify more than one configuration file!'
|
54
|
-
exit(
|
54
|
+
exit(2)
|
55
55
|
end
|
56
56
|
|
57
57
|
params[:config] = file_path
|
@@ -75,7 +75,7 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
75
75
|
puts e.message
|
76
76
|
puts parser.help
|
77
77
|
|
78
|
-
exit(
|
78
|
+
exit(2)
|
79
79
|
end
|
80
80
|
|
81
81
|
|
@@ -105,4 +105,6 @@ elsif File.exist?("#{Dir.pwd}/.cuke_linter")
|
|
105
105
|
CukeLinter.load_configuration
|
106
106
|
end
|
107
107
|
|
108
|
-
CukeLinter.lint(options)
|
108
|
+
results = CukeLinter.lint(options)
|
109
|
+
|
110
|
+
exit(1) unless results.empty?
|
data/lib/cuke_linter/version.rb
CHANGED
@@ -189,3 +189,11 @@ Feature: Using cuke_linter on the command line
|
|
189
189
|
"""
|
190
190
|
0 issues found
|
191
191
|
"""
|
192
|
+
|
193
|
+
Scenario: Interpreting exit codes
|
194
|
+
When the executable finds no linting problems
|
195
|
+
Then the exit code is "0"
|
196
|
+
When the executable finds linting problems
|
197
|
+
Then the exit code is "1"
|
198
|
+
When the executable has a problem
|
199
|
+
Then the exit code is "2"
|
@@ -37,3 +37,48 @@ end
|
|
37
37
|
When(/^"([^"]*)" is the current directory$/) do |directory|
|
38
38
|
@working_directory = "#{@root_test_directory}/#{directory}"
|
39
39
|
end
|
40
|
+
|
41
|
+
When(/^the executable finds no linting problems$/) do
|
42
|
+
# Linting an empty directory doesn't (currently) find and problems
|
43
|
+
command = "bundle exec ruby #{PROJECT_ROOT}/exe/cuke_linter"
|
44
|
+
|
45
|
+
std_out, std_err, status = [nil, nil, nil]
|
46
|
+
|
47
|
+
Dir.chdir(@root_test_directory) do
|
48
|
+
std_out, std_err, status = Open3.capture3(command)
|
49
|
+
end
|
50
|
+
|
51
|
+
@results = { std_out: std_out, std_err: std_err, status: status }
|
52
|
+
end
|
53
|
+
|
54
|
+
When(/^the executable finds linting problems$/) do
|
55
|
+
# This should be a problematic feature file
|
56
|
+
CukeLinter::FileHelper.create_file(directory: @root_test_directory,
|
57
|
+
name: 'pretty_empty',
|
58
|
+
extension: '.feature',
|
59
|
+
text: 'Feature: ')
|
60
|
+
|
61
|
+
|
62
|
+
command = "bundle exec ruby #{PROJECT_ROOT}/exe/cuke_linter"
|
63
|
+
|
64
|
+
std_out, std_err, status = [nil, nil, nil]
|
65
|
+
|
66
|
+
Dir.chdir(@root_test_directory) do
|
67
|
+
std_out, std_err, status = Open3.capture3(command)
|
68
|
+
end
|
69
|
+
|
70
|
+
@results = { std_out: std_out, std_err: std_err, status: status }
|
71
|
+
end
|
72
|
+
|
73
|
+
When(/^the executable has a problem$/) do
|
74
|
+
# Missing a required argument for a flag should be a problem
|
75
|
+
command = "bundle exec ruby #{PROJECT_ROOT}/exe/cuke_linter -r"
|
76
|
+
|
77
|
+
std_out, std_err, status = [nil, nil, nil]
|
78
|
+
|
79
|
+
Dir.chdir(@root_test_directory) do
|
80
|
+
std_out, std_err, status = Open3.capture3(command)
|
81
|
+
end
|
82
|
+
|
83
|
+
@results = { std_out: std_out, std_err: std_err, status: status }
|
84
|
+
end
|
@@ -4,6 +4,9 @@ require 'open3'
|
|
4
4
|
|
5
5
|
RSpec.describe 'the Command Line Interface' do
|
6
6
|
|
7
|
+
# Exit codes that are expected during normal use of the CLI
|
8
|
+
let(:normal_exit_codes) { [0, 1] }
|
9
|
+
|
7
10
|
# A minimal fake test suite that should be available for every spec
|
8
11
|
let!(:test_directory) { CukeLinter::FileHelper.create_directory }
|
9
12
|
let!(:linted_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
|
@@ -18,6 +21,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
18
21
|
let(:executable_directory) { "#{PROJECT_ROOT}/exe" }
|
19
22
|
let(:executable_name) { 'cuke_linter' }
|
20
23
|
let(:executable_path) { "#{executable_directory}/#{executable_name}" }
|
24
|
+
let(:command) { "bundle exec ruby #{executable_path}" }
|
21
25
|
let(:results) { std_out, std_err, status = [nil, nil, nil]
|
22
26
|
|
23
27
|
Dir.chdir(test_directory) do
|
@@ -53,7 +57,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
53
57
|
let(:command) { "bundle exec ruby #{executable_path}" }
|
54
58
|
|
55
59
|
it 'can run cleanly by default' do
|
56
|
-
expect(results[:status].exitstatus)
|
60
|
+
expect(normal_exit_codes).to include(results[:status].exitstatus)
|
57
61
|
end
|
58
62
|
|
59
63
|
context 'when the default configuration file exists' do
|
@@ -81,13 +85,58 @@ RSpec.describe 'the Command Line Interface' do
|
|
81
85
|
end
|
82
86
|
|
83
87
|
it 'can still run cleanly' do
|
88
|
+
expect(normal_exit_codes).to include(results[:status].exitstatus)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'exit codes' do
|
96
|
+
|
97
|
+
context 'when no problems are found' do
|
98
|
+
# This file does not have any problems with the current linter set
|
99
|
+
let!(:linted_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
|
100
|
+
name: 'nothing_wrong',
|
101
|
+
extension: '.feature',
|
102
|
+
text: 'Feature: A name
|
103
|
+
A description
|
104
|
+
Scenario: A scenario
|
105
|
+
When a step
|
106
|
+
Then a step') }
|
107
|
+
|
108
|
+
it 'returns a zero exit code' do
|
84
109
|
expect(results[:status].exitstatus).to eq(0)
|
85
110
|
end
|
86
111
|
|
87
112
|
end
|
88
113
|
|
114
|
+
context 'when linting problems are found' do
|
115
|
+
# This should be a problematic feature file
|
116
|
+
let!(:linted_file) { CukeLinter::FileHelper.create_file(directory: test_directory,
|
117
|
+
name: 'pretty_empty',
|
118
|
+
extension: '.feature',
|
119
|
+
text: 'Feature: ') }
|
120
|
+
|
121
|
+
it 'returns a non-zero exit code' do
|
122
|
+
expect(results[:status].exitstatus).to eq(1)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when something else goes wrong' do
|
128
|
+
|
129
|
+
# Bad CLI usage due to missing required flag arguments
|
130
|
+
let(:command) { "bundle exec ruby #{executable_path} -r" }
|
131
|
+
|
132
|
+
it 'returns a different non-zero exit code' do
|
133
|
+
expect(results[:status].exitstatus).to eq(2)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
89
137
|
end
|
90
138
|
|
139
|
+
|
91
140
|
describe 'option flags' do
|
92
141
|
|
93
142
|
context 'with a path flag' do
|
@@ -143,7 +192,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
143
192
|
end
|
144
193
|
|
145
194
|
it 'exits with an error' do
|
146
|
-
expect(results[:status].exitstatus).to eq(
|
195
|
+
expect(results[:status].exitstatus).to eq(2)
|
147
196
|
end
|
148
197
|
|
149
198
|
end
|
@@ -207,7 +256,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
207
256
|
end
|
208
257
|
|
209
258
|
it 'exits with an error' do
|
210
|
-
expect(results[:status].exitstatus).to eq(
|
259
|
+
expect(results[:status].exitstatus).to eq(2)
|
211
260
|
end
|
212
261
|
|
213
262
|
end
|
@@ -324,7 +373,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
324
373
|
end
|
325
374
|
|
326
375
|
it 'exits with an error' do
|
327
|
-
expect(results[:status].exitstatus).to eq(
|
376
|
+
expect(results[:status].exitstatus).to eq(2)
|
328
377
|
end
|
329
378
|
|
330
379
|
end
|
@@ -371,7 +420,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
371
420
|
end
|
372
421
|
|
373
422
|
it 'exits with an error' do
|
374
|
-
expect(results[:status].exitstatus).to eq(
|
423
|
+
expect(results[:status].exitstatus).to eq(2)
|
375
424
|
end
|
376
425
|
|
377
426
|
end
|
@@ -410,7 +459,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
410
459
|
end
|
411
460
|
|
412
461
|
it 'exits with an error' do
|
413
|
-
expect(results[:status].exitstatus).to eq(
|
462
|
+
expect(results[:status].exitstatus).to eq(2)
|
414
463
|
end
|
415
464
|
|
416
465
|
end
|
@@ -429,7 +478,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
429
478
|
end
|
430
479
|
|
431
480
|
it 'exits with an error' do
|
432
|
-
expect(results[:status].exitstatus).to eq(
|
481
|
+
expect(results[:status].exitstatus).to eq(2)
|
433
482
|
end
|
434
483
|
|
435
484
|
end
|
@@ -496,7 +545,7 @@ RSpec.describe 'the Command Line Interface' do
|
|
496
545
|
end
|
497
546
|
|
498
547
|
it 'exits with an error' do
|
499
|
-
expect(results[:status].exitstatus).to eq(
|
548
|
+
expect(results[:status].exitstatus).to eq(2)
|
500
549
|
end
|
501
550
|
|
502
551
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative '../../../../environments/rspec_env'
|
2
|
+
|
3
|
+
RSpec.describe CukeLinter do
|
4
|
+
|
5
|
+
describe 'configuration' do
|
6
|
+
|
7
|
+
let(:test_model_tree) { CukeLinter::ModelFactory.generate_lintable_model }
|
8
|
+
let(:test_linters) { [CukeLinter::LinterFactory.generate_fake_linter] }
|
9
|
+
let(:test_formatters) { [[CukeLinter::FormatterFactory.generate_fake_formatter, "#{CukeLinter::FileHelper::create_directory}/junk_output_file.txt"]] }
|
10
|
+
let(:linting_options) { { model_trees: [test_model_tree], linters: test_linters, formatters: test_formatters } }
|
11
|
+
|
12
|
+
|
13
|
+
it 'unregisters disabled linters' do
|
14
|
+
config = { 'FakeLinter1' => { 'Enabled' => false } }
|
15
|
+
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
16
|
+
|
17
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
18
|
+
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
19
|
+
|
20
|
+
subject.load_configuration(config_file_path: configuration_file)
|
21
|
+
|
22
|
+
expect(subject.registered_linters['FakeLinter1']).to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can apply a property to all linters' do
|
26
|
+
configuration = { 'AllLinters' => { 'Enabled' => false } }
|
27
|
+
|
28
|
+
# Restore the default linters
|
29
|
+
CukeLinter.reset_linters
|
30
|
+
|
31
|
+
# Also add some custom ones
|
32
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'Foo')
|
33
|
+
|
34
|
+
|
35
|
+
subject.load_configuration(config: configuration)
|
36
|
+
|
37
|
+
expect(subject.registered_linters).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'uses linter specific properties over general properties' do
|
41
|
+
configuration = { 'AllLinters' => { 'Enabled' => false },
|
42
|
+
'FakeLinter1' => { 'Enabled' => true } }
|
43
|
+
|
44
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'FakeLinter1')
|
45
|
+
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
46
|
+
|
47
|
+
subject.load_configuration(config: configuration)
|
48
|
+
|
49
|
+
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'even unregisters non-configurable disabled linters' do
|
53
|
+
config = { 'FakeLinter' => { 'Enabled' => false } }
|
54
|
+
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
55
|
+
non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
|
56
|
+
non_configurable_linter.instance_eval('undef :configure')
|
57
|
+
|
58
|
+
CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
|
59
|
+
expect(subject.registered_linters['FakeLinter']).to_not be nil
|
60
|
+
|
61
|
+
subject.load_configuration(config_file_path: configuration_file)
|
62
|
+
|
63
|
+
expect(subject.registered_linters['FakeLinter']).to be nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'uses the default configuration file in the current directory if no configuration file is provided' do
|
67
|
+
config = { 'FakeLinter1' => { 'Enabled' => false } }
|
68
|
+
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
69
|
+
|
70
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
71
|
+
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
72
|
+
|
73
|
+
Dir.chdir(File.dirname(configuration_file)) do
|
74
|
+
subject.load_configuration
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(subject.registered_linters['FakeLinter1']).to be nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'raises an exception if no default configuration file is found and no configuration or file is provided' do
|
81
|
+
some_empty_directory = CukeLinter::FileHelper.create_directory
|
82
|
+
|
83
|
+
Dir.chdir(File.dirname(some_empty_directory)) do
|
84
|
+
expect { subject.load_configuration }.to raise_error('No configuration or configuration file given and no .cuke_linter file found')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'configures every linter for which it has a configuration' do
|
89
|
+
config = { 'FakeLinter1' => { 'Problem' => 'My custom message for FakeLinter1' },
|
90
|
+
'FakeLinter2' => { 'Problem' => 'My custom message for FakeLinter2' } }
|
91
|
+
|
92
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
93
|
+
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter2'), name: 'FakeLinter2')
|
94
|
+
linting_options.delete(:linters)
|
95
|
+
|
96
|
+
subject.load_configuration(config: config)
|
97
|
+
results = subject.lint(linting_options)
|
98
|
+
|
99
|
+
expect(results).to match_array([{ linter: 'FakeLinter1', location: 'path_to_file:1', problem: 'My custom message for FakeLinter1' },
|
100
|
+
{ linter: 'FakeLinter2', location: 'path_to_file:1', problem: 'My custom message for FakeLinter2' }])
|
101
|
+
end
|
102
|
+
|
103
|
+
it "does not try to configure linters that don't know how to be configured" do
|
104
|
+
config = { 'FakeLinter' => { 'Problem' => 'My custom message for FakeLinter' } }
|
105
|
+
non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
|
106
|
+
non_configurable_linter.instance_eval('undef :configure')
|
107
|
+
|
108
|
+
CukeLinter.clear_registered_linters
|
109
|
+
CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
|
110
|
+
linting_options.delete(:linters)
|
111
|
+
|
112
|
+
subject.load_configuration(config: config)
|
113
|
+
results = subject.lint(linting_options)
|
114
|
+
|
115
|
+
expect(results).to match_array([{ linter: 'FakeLinter', location: 'path_to_file:1', problem: 'FakeLinter problem' }])
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -232,113 +232,4 @@ RSpec.describe CukeLinter do
|
|
232
232
|
expect { subject.lint(linting_options) }.to_not raise_error
|
233
233
|
end
|
234
234
|
|
235
|
-
describe 'configuration' do
|
236
|
-
|
237
|
-
it 'unregisters disabled linters' do
|
238
|
-
config = { 'FakeLinter1' => { 'Enabled' => false } }
|
239
|
-
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
240
|
-
|
241
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
242
|
-
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
243
|
-
|
244
|
-
subject.load_configuration(config_file_path: configuration_file)
|
245
|
-
|
246
|
-
expect(subject.registered_linters['FakeLinter1']).to be nil
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'can apply a property to all linters' do
|
250
|
-
configuration = { 'AllLinters' => { 'Enabled' => false } }
|
251
|
-
|
252
|
-
# Restore the default linters
|
253
|
-
CukeLinter.reset_linters
|
254
|
-
|
255
|
-
# Also add some custom ones
|
256
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'Foo')
|
257
|
-
|
258
|
-
|
259
|
-
subject.load_configuration(config: configuration)
|
260
|
-
|
261
|
-
expect(subject.registered_linters).to be_empty
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'uses linter specific properties over general properties' do
|
265
|
-
configuration = { 'AllLinters' => { 'Enabled' => false },
|
266
|
-
'FakeLinter1' => { 'Enabled' => true } }
|
267
|
-
|
268
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter, name: 'FakeLinter1')
|
269
|
-
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
270
|
-
|
271
|
-
subject.load_configuration(config: configuration)
|
272
|
-
|
273
|
-
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'even unregisters non-configurable disabled linters' do
|
277
|
-
config = { 'FakeLinter' => { 'Enabled' => false } }
|
278
|
-
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
279
|
-
non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
|
280
|
-
non_configurable_linter.instance_eval('undef :configure')
|
281
|
-
|
282
|
-
CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
|
283
|
-
expect(subject.registered_linters['FakeLinter']).to_not be nil
|
284
|
-
|
285
|
-
subject.load_configuration(config_file_path: configuration_file)
|
286
|
-
|
287
|
-
expect(subject.registered_linters['FakeLinter']).to be nil
|
288
|
-
end
|
289
|
-
|
290
|
-
it 'uses the default configuration file in the current directory if no configuration file is provided' do
|
291
|
-
config = { 'FakeLinter1' => { 'Enabled' => false } }
|
292
|
-
configuration_file = CukeLinter::FileHelper.create_file(name: '.cuke_linter', extension: '', text: config.to_yaml)
|
293
|
-
|
294
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
295
|
-
expect(subject.registered_linters['FakeLinter1']).to_not be nil
|
296
|
-
|
297
|
-
Dir.chdir(File.dirname(configuration_file)) do
|
298
|
-
subject.load_configuration
|
299
|
-
end
|
300
|
-
|
301
|
-
expect(subject.registered_linters['FakeLinter1']).to be nil
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'raises an exception if no default configuration file is found and no configuration or file is provided' do
|
305
|
-
some_empty_directory = CukeLinter::FileHelper.create_directory
|
306
|
-
|
307
|
-
Dir.chdir(File.dirname(some_empty_directory)) do
|
308
|
-
expect { subject.load_configuration }.to raise_error('No configuration or configuration file given and no .cuke_linter file found')
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'configures every linter for which it has a configuration' do
|
313
|
-
config = { 'FakeLinter1' => { 'Problem' => 'My custom message for FakeLinter1' },
|
314
|
-
'FakeLinter2' => { 'Problem' => 'My custom message for FakeLinter2' } }
|
315
|
-
|
316
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter1'), name: 'FakeLinter1')
|
317
|
-
CukeLinter.register_linter(linter: CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter2'), name: 'FakeLinter2')
|
318
|
-
linting_options.delete(:linters)
|
319
|
-
|
320
|
-
subject.load_configuration(config: config)
|
321
|
-
results = subject.lint(linting_options)
|
322
|
-
|
323
|
-
expect(results).to match_array([{ linter: 'FakeLinter1', location: 'path_to_file:1', problem: 'My custom message for FakeLinter1' },
|
324
|
-
{ linter: 'FakeLinter2', location: 'path_to_file:1', problem: 'My custom message for FakeLinter2' }])
|
325
|
-
end
|
326
|
-
|
327
|
-
it "does not try to configure linters that don't know how to be configured" do
|
328
|
-
config = { 'FakeLinter' => { 'Problem' => 'My custom message for FakeLinter' } }
|
329
|
-
non_configurable_linter = CukeLinter::LinterFactory.generate_fake_linter(name: 'FakeLinter')
|
330
|
-
non_configurable_linter.instance_eval('undef :configure')
|
331
|
-
|
332
|
-
CukeLinter.clear_registered_linters
|
333
|
-
CukeLinter.register_linter(linter: non_configurable_linter, name: 'FakeLinter')
|
334
|
-
linting_options.delete(:linters)
|
335
|
-
|
336
|
-
subject.load_configuration(config: config)
|
337
|
-
results = subject.lint(linting_options)
|
338
|
-
|
339
|
-
expect(results).to match_array([{ linter: 'FakeLinter', location: 'path_to_file:1', problem: 'FakeLinter problem' }])
|
340
|
-
end
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
235
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuke_linter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07
|
11
|
+
date: 2019-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuke_modeler
|
@@ -220,6 +220,7 @@ files:
|
|
220
220
|
- testing/linter_factory.rb
|
221
221
|
- testing/model_factory.rb
|
222
222
|
- testing/rspec/spec/integration/cli_integration_spec.rb
|
223
|
+
- testing/rspec/spec/integration/configuration_spec.rb
|
223
224
|
- testing/rspec/spec/integration/cuke_linter_integration_spec.rb
|
224
225
|
- testing/rspec/spec/integration/formatters/formatter_integration_specs.rb
|
225
226
|
- testing/rspec/spec/integration/formatters/pretty_formatter_integration_spec.rb
|