reek 4.7.2 → 4.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -4
- data/.travis.yml +0 -5
- data/CHANGELOG.md +8 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +4 -4
- data/docs/How-To-Write-New-Detectors.md +6 -5
- data/docs/Unused-Private-Method.md +1 -1
- data/features/configuration_via_source_comments/erroneous_source_comments.feature +1 -1
- data/features/locales.feature +32 -0
- data/features/rake_task/rake_task.feature +46 -6
- data/features/rspec_matcher.feature +32 -0
- data/features/step_definitions/reek_steps.rb +0 -4
- data/features/support/env.rb +0 -9
- data/lib/reek/ast/builder.rb +1 -1
- data/lib/reek/ast/sexp_extensions/send.rb +0 -4
- data/lib/reek/cli/options.rb +2 -2
- data/lib/reek/configuration/app_configuration.rb +3 -2
- data/lib/reek/configuration/configuration_file_finder.rb +3 -3
- data/lib/reek/context/ghost_context.rb +0 -2
- data/lib/reek/context/module_context.rb +0 -3
- data/lib/reek/context_builder.rb +2 -4
- data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +2 -2
- data/lib/reek/errors/bad_detector_in_comment_error.rb +2 -2
- data/lib/reek/errors/encoding_error.rb +38 -0
- data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +3 -3
- data/lib/reek/errors/incomprehensible_source_error.rb +4 -4
- data/lib/reek/examiner.rb +15 -11
- data/lib/reek/rake/task.rb +5 -1
- data/lib/reek/smell_detectors/attribute.rb +6 -11
- data/lib/reek/smell_detectors/base_detector.rb +9 -1
- data/lib/reek/smell_detectors/boolean_parameter.rb +4 -5
- data/lib/reek/smell_detectors/class_variable.rb +5 -6
- data/lib/reek/smell_detectors/control_parameter.rb +3 -3
- data/lib/reek/smell_detectors/data_clump.rb +13 -6
- data/lib/reek/smell_detectors/duplicate_method_call.rb +18 -11
- data/lib/reek/smell_detectors/feature_envy.rb +9 -7
- data/lib/reek/smell_detectors/instance_variable_assumption.rb +14 -14
- data/lib/reek/smell_detectors/irresponsible_module.rb +6 -12
- data/lib/reek/smell_detectors/long_parameter_list.rb +10 -6
- data/lib/reek/smell_detectors/long_yield_list.rb +9 -5
- data/lib/reek/smell_detectors/manual_dispatch.rb +3 -4
- data/lib/reek/smell_detectors/module_initialize.rb +4 -5
- data/lib/reek/smell_detectors/nested_iterators.rb +11 -19
- data/lib/reek/smell_detectors/nil_check.rb +9 -15
- data/lib/reek/smell_detectors/prima_donna_method.rb +17 -16
- data/lib/reek/smell_detectors/repeated_conditional.rb +11 -8
- data/lib/reek/smell_detectors/subclassed_from_core_class.rb +8 -8
- data/lib/reek/smell_detectors/too_many_constants.rb +10 -8
- data/lib/reek/smell_detectors/too_many_instance_variables.rb +10 -5
- data/lib/reek/smell_detectors/too_many_methods.rb +11 -6
- data/lib/reek/smell_detectors/too_many_statements.rb +10 -5
- data/lib/reek/smell_detectors/uncommunicative_method_name.rb +8 -8
- data/lib/reek/smell_detectors/uncommunicative_module_name.rb +12 -15
- data/lib/reek/smell_detectors/uncommunicative_parameter_name.rb +10 -13
- data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +23 -23
- data/lib/reek/smell_detectors/unused_parameters.rb +5 -6
- data/lib/reek/smell_detectors/unused_private_method.rb +11 -18
- data/lib/reek/smell_detectors/utility_function.rb +12 -15
- data/lib/reek/source/source_code.rb +27 -6
- data/lib/reek/source/source_locator.rb +1 -1
- data/lib/reek/spec.rb +1 -1
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +0 -2
- data/spec/reek/ast/sexp_extensions_spec.rb +12 -32
- data/spec/reek/cli/application_spec.rb +4 -6
- data/spec/reek/configuration/configuration_file_finder_spec.rb +0 -2
- data/spec/reek/examiner_spec.rb +38 -1
- data/spec/reek/rake/task_spec.rb +25 -2
- data/spec/reek/smell_detectors/base_detector_spec.rb +4 -5
- data/spec/reek/smell_detectors/prima_donna_method_spec.rb +3 -3
- data/spec/reek/source/source_code_spec.rb +28 -1
- data/spec/reek/spec/should_reek_of_spec.rb +18 -18
- data/spec/reek/spec/should_reek_spec.rb +5 -5
- data/spec/reek/spec/smell_matcher_spec.rb +20 -20
- data/spec/spec_helper.rb +1 -1
- metadata +6 -3
@@ -7,9 +7,10 @@ end
|
|
7
7
|
require_relative '../tree_dresser'
|
8
8
|
require_relative '../ast/node'
|
9
9
|
require_relative '../ast/builder'
|
10
|
+
require_relative '../errors/encoding_error'
|
10
11
|
|
11
12
|
# Opt in to new way of representing lambdas
|
12
|
-
|
13
|
+
Reek::AST::Builder.emit_lambda = true
|
13
14
|
|
14
15
|
module Reek
|
15
16
|
module Source
|
@@ -20,7 +21,7 @@ module Reek
|
|
20
21
|
IO_IDENTIFIER = 'STDIN'.freeze
|
21
22
|
STRING_IDENTIFIER = 'string'.freeze
|
22
23
|
|
23
|
-
attr_reader :origin
|
24
|
+
attr_reader :origin
|
24
25
|
|
25
26
|
# Initializer.
|
26
27
|
#
|
@@ -30,7 +31,8 @@ module Reek
|
|
30
31
|
def initialize(code:, origin:, parser: default_parser)
|
31
32
|
@origin = origin
|
32
33
|
@diagnostics = []
|
33
|
-
@
|
34
|
+
@parser = parser
|
35
|
+
@code = code
|
34
36
|
end
|
35
37
|
|
36
38
|
# Initializes an instance of SourceCode given a source.
|
@@ -54,11 +56,24 @@ module Reek
|
|
54
56
|
|
55
57
|
# @return [true|false] Returns true if parsed file does not have any syntax errors.
|
56
58
|
def valid_syntax?
|
57
|
-
|
59
|
+
diagnostics.none? { |diagnostic| [:error, :fatal].include?(diagnostic.level) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def diagnostics
|
63
|
+
parse_if_needed
|
64
|
+
@diagnostics
|
65
|
+
end
|
66
|
+
|
67
|
+
def syntax_tree
|
68
|
+
parse_if_needed
|
58
69
|
end
|
59
70
|
|
60
71
|
private
|
61
72
|
|
73
|
+
def parse_if_needed
|
74
|
+
@syntax_tree ||= parse(@parser, @code)
|
75
|
+
end
|
76
|
+
|
62
77
|
attr_reader :source
|
63
78
|
|
64
79
|
# Parses the given source into an AST and associates the source code comments with it.
|
@@ -94,9 +109,15 @@ module Reek
|
|
94
109
|
# @param source [String] - Ruby code
|
95
110
|
# @return [Anonymous subclass of Reek::AST::Node] the AST presentation
|
96
111
|
# for the given source
|
112
|
+
# :reek:TooManyStatements { max_statements: 8 }
|
97
113
|
def parse(parser, source)
|
98
|
-
|
99
|
-
|
114
|
+
begin
|
115
|
+
buffer = Parser::Source::Buffer.new(origin, 1)
|
116
|
+
source.force_encoding(Encoding::UTF_8)
|
117
|
+
buffer.source = source
|
118
|
+
rescue EncodingError => exception
|
119
|
+
raise Errors::EncodingError, origin: origin, original_exception: exception
|
120
|
+
end
|
100
121
|
begin
|
101
122
|
ast, comments = parser.parse_with_comments(buffer)
|
102
123
|
rescue Parser::SyntaxError # rubocop:disable Lint/HandleExceptions
|
data/lib/reek/spec.rb
CHANGED
@@ -114,7 +114,7 @@ module Reek
|
|
114
114
|
# @public
|
115
115
|
#
|
116
116
|
# :reek:UtilityFunction
|
117
|
-
def reek(configuration = Configuration::AppConfiguration.
|
117
|
+
def reek(configuration = Configuration::AppConfiguration.from_path)
|
118
118
|
ShouldReek.new(configuration: configuration)
|
119
119
|
end
|
120
120
|
end
|
data/lib/reek/version.rb
CHANGED
data/reek.gemspec
CHANGED
@@ -303,12 +303,8 @@ RSpec.describe Reek::AST::SexpExtensions::SendNode do
|
|
303
303
|
context 'with no parameters' do
|
304
304
|
let(:node) { sexp(:send, nil, :hello) }
|
305
305
|
|
306
|
-
it 'has no argument names' do
|
307
|
-
expect(node.arg_names).to eq []
|
308
|
-
end
|
309
|
-
|
310
306
|
it 'is not considered to be a writable attr' do
|
311
|
-
expect(sexp(:send, nil, :attr)
|
307
|
+
expect(sexp(:send, nil, :attr)).not_to be_attr_with_writable_flag
|
312
308
|
end
|
313
309
|
end
|
314
310
|
|
@@ -316,15 +312,15 @@ RSpec.describe Reek::AST::SexpExtensions::SendNode do
|
|
316
312
|
let(:bare_new) { sexp(:send, nil, :new) }
|
317
313
|
|
318
314
|
it 'is not considered to be a module creation call' do
|
319
|
-
expect(bare_new
|
315
|
+
expect(bare_new).not_to be_module_creation_call
|
320
316
|
end
|
321
317
|
|
322
318
|
it 'is not considered to have a module creation receiver' do
|
323
|
-
expect(bare_new
|
319
|
+
expect(bare_new).not_to be_module_creation_receiver
|
324
320
|
end
|
325
321
|
|
326
322
|
it 'is considered to be an object creation call' do
|
327
|
-
expect(bare_new
|
323
|
+
expect(bare_new).to be_object_creation_call
|
328
324
|
end
|
329
325
|
end
|
330
326
|
|
@@ -332,31 +328,15 @@ RSpec.describe Reek::AST::SexpExtensions::SendNode do
|
|
332
328
|
let(:node) { Reek::Source::SourceCode.from('(foo ? bar : baz).new').syntax_tree }
|
333
329
|
|
334
330
|
it 'is not considered to be a module creation call' do
|
335
|
-
expect(node
|
331
|
+
expect(node).not_to be_module_creation_call
|
336
332
|
end
|
337
333
|
|
338
334
|
it 'is not considered to have a module creation receiver' do
|
339
|
-
expect(node
|
335
|
+
expect(node).not_to be_module_creation_receiver
|
340
336
|
end
|
341
337
|
|
342
338
|
it 'is considered to be an object creation call' do
|
343
|
-
expect(node
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
context 'with 1 literal parameter' do
|
348
|
-
let(:node) { sexp(:send, nil, :hello, sexp(:lit, :param)) }
|
349
|
-
|
350
|
-
it 'has 1 argument name' do
|
351
|
-
expect(node.arg_names).to eq [:param]
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
context 'with 2 literal parameters' do
|
356
|
-
let(:node) { sexp(:send, nil, :hello, sexp(:lit, :x), sexp(:lit, :y)) }
|
357
|
-
|
358
|
-
it 'has 2 argument names' do
|
359
|
-
expect(node.arg_names).to eq [:x, :y]
|
339
|
+
expect(node).to be_object_creation_call
|
360
340
|
end
|
361
341
|
end
|
362
342
|
end
|
@@ -466,14 +446,14 @@ RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
|
466
446
|
context 'with single assignment' do
|
467
447
|
it 'does not define a module' do
|
468
448
|
exp = sexp(:casgn, nil, :Foo)
|
469
|
-
expect(exp
|
449
|
+
expect(exp).not_to be_defines_module
|
470
450
|
end
|
471
451
|
end
|
472
452
|
|
473
453
|
context 'with implicit receiver to new' do
|
474
454
|
it 'does not define a module' do
|
475
455
|
exp = sexp(:casgn, nil, :Foo, sexp(:send, nil, :new))
|
476
|
-
expect(exp
|
456
|
+
expect(exp).not_to be_defines_module
|
477
457
|
end
|
478
458
|
end
|
479
459
|
|
@@ -481,7 +461,7 @@ RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
|
481
461
|
it 'does not define a module' do
|
482
462
|
exp = Reek::Source::SourceCode.from('Foo = Class.new(Bar)').syntax_tree
|
483
463
|
|
484
|
-
expect(exp
|
464
|
+
expect(exp).to be_defines_module
|
485
465
|
end
|
486
466
|
end
|
487
467
|
|
@@ -489,7 +469,7 @@ RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
|
489
469
|
it 'does not define a module' do
|
490
470
|
exp = Reek::Source::SourceCode.from('C = ->{}').syntax_tree
|
491
471
|
|
492
|
-
expect(exp
|
472
|
+
expect(exp).not_to be_defines_module
|
493
473
|
end
|
494
474
|
end
|
495
475
|
|
@@ -497,7 +477,7 @@ RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
|
497
477
|
it 'does not define a module' do
|
498
478
|
exp = Reek::Source::SourceCode.from('C = "hello"').syntax_tree
|
499
479
|
|
500
|
-
expect(exp
|
480
|
+
expect(exp).not_to be_defines_module
|
501
481
|
end
|
502
482
|
end
|
503
483
|
end
|
@@ -15,13 +15,11 @@ RSpec.describe Reek::CLI::Application do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
let(:path_excluded_in_configuration) do
|
19
|
-
SAMPLES_PATH.join('source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb')
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:configuration) { test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek')) }
|
23
|
-
|
24
18
|
describe '#execute' do
|
19
|
+
let(:path_excluded_in_configuration) do
|
20
|
+
SAMPLES_PATH.join('source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb')
|
21
|
+
end
|
22
|
+
let(:configuration) { test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek')) }
|
25
23
|
let(:command) { instance_double 'Reek::CLI::Command::ReportCommand' }
|
26
24
|
let(:app) { described_class.new [] }
|
27
25
|
|
data/spec/reek/examiner_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
require_lib 'reek/examiner'
|
3
|
+
require_lib 'reek/logging_error_handler'
|
3
4
|
|
4
5
|
RSpec.shared_examples_for 'no smells found' do
|
5
6
|
it 'is not smelly' do
|
@@ -107,7 +108,7 @@ RSpec.describe Reek::Examiner do
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
context 'with an incomprehensible source that causes
|
111
|
+
context 'with an incomprehensible source that causes the detectors to crash' do
|
111
112
|
let(:source) { 'class C; def does_crash_reek; end; end' }
|
112
113
|
|
113
114
|
let(:examiner) do
|
@@ -143,6 +144,42 @@ RSpec.describe Reek::Examiner do
|
|
143
144
|
end
|
144
145
|
end
|
145
146
|
|
147
|
+
context 'when the source causes the source buffer to crash' do
|
148
|
+
let(:source) { 'I make the buffer crash' }
|
149
|
+
|
150
|
+
before do
|
151
|
+
buffer = double
|
152
|
+
allow(buffer).to receive(:source=) { raise RuntimeError }
|
153
|
+
allow(Parser::Source::Buffer).to receive(:new).and_return(buffer)
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'if the error handler does not handle the error' do
|
157
|
+
let(:examiner) { described_class.new(source) }
|
158
|
+
|
159
|
+
it 'does not raise an error during initialization' do
|
160
|
+
expect { examiner }.not_to raise_error
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'raises an incomprehensible source error when asked for smells' do
|
164
|
+
expect { examiner.smells }.to raise_error Reek::Errors::IncomprehensibleSourceError
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'if the error handler handles the error' do
|
169
|
+
let(:handler) { instance_double(Reek::LoggingErrorHandler, handle: true) }
|
170
|
+
let(:examiner) { described_class.new(source, error_handler: handler) }
|
171
|
+
|
172
|
+
it 'does not raise an error when asked for smells' do
|
173
|
+
expect { examiner.smells }.not_to raise_error
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'passes the wrapped error to the handler' do
|
177
|
+
examiner.smells
|
178
|
+
expect(handler).to have_received(:handle).with(Reek::Errors::IncomprehensibleSourceError)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
146
183
|
describe 'bad comment config' do
|
147
184
|
let(:examiner) { described_class.new(source) }
|
148
185
|
|
data/spec/reek/rake/task_spec.rb
CHANGED
@@ -7,14 +7,37 @@ RSpec.describe Reek::Rake::Task do
|
|
7
7
|
task = described_class.new
|
8
8
|
expect(task.source_files).to eq FileList['lib/**/*.rb']
|
9
9
|
end
|
10
|
+
|
11
|
+
it 'is set to ENV["REEK_SRC"]' do
|
12
|
+
begin
|
13
|
+
ENV['REEK_SRC'] = '*.rb'
|
14
|
+
task = described_class.new
|
15
|
+
expect(task.source_files).to eq FileList['*.rb']
|
16
|
+
ensure
|
17
|
+
ENV['REEK_SRC'] = nil
|
18
|
+
end
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
describe '#source_files=' do
|
13
23
|
it 'sets source_files to a FileList when passed a string' do
|
14
|
-
task = described_class.new
|
15
|
-
|
24
|
+
task = described_class.new do |it|
|
25
|
+
it.source_files = '*.rb'
|
26
|
+
end
|
16
27
|
expect(task.source_files).to eq FileList['*.rb']
|
17
28
|
end
|
29
|
+
|
30
|
+
it 'has no effect when ENV["REEK_SRC"] is set' do
|
31
|
+
begin
|
32
|
+
ENV['REEK_SRC'] = '*.rb'
|
33
|
+
task = described_class.new do |it|
|
34
|
+
it.source_files = 'lib/*.rb'
|
35
|
+
end
|
36
|
+
expect(task.source_files).to eq FileList['*.rb']
|
37
|
+
ensure
|
38
|
+
ENV['REEK_SRC'] = nil
|
39
|
+
end
|
40
|
+
end
|
18
41
|
end
|
19
42
|
|
20
43
|
# SMELL: Testing a private method
|
@@ -21,16 +21,15 @@ RSpec.describe Reek::SmellDetectors::BaseDetector do
|
|
21
21
|
context 'with default exclusions present' do
|
22
22
|
let(:subclass) { Reek::SmellDetectors::TooManyStatements }
|
23
23
|
|
24
|
-
before do
|
25
|
-
expect(subclass.default_config['exclude']).to eq ['initialize']
|
26
|
-
end
|
27
|
-
|
28
24
|
it 'includes default exclusions' do
|
29
25
|
detector = subclass.new
|
30
26
|
smell = create(:smell_warning, smell_detector: detector, context: 'Foo#bar')
|
31
27
|
result = subclass.todo_configuration_for([smell])
|
32
28
|
|
33
|
-
|
29
|
+
aggregate_failures do
|
30
|
+
expect(subclass.default_config['exclude']).to eq ['initialize']
|
31
|
+
expect(result).to eq('TooManyStatements' => { 'exclude' => ['initialize', 'Foo#bar'] })
|
32
|
+
end
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -11,7 +11,7 @@ RSpec.describe Reek::SmellDetectors::PrimaDonnaMethod do
|
|
11
11
|
EOS
|
12
12
|
|
13
13
|
expect(src).to reek_of(:PrimaDonnaMethod,
|
14
|
-
lines: [
|
14
|
+
lines: [2],
|
15
15
|
context: 'Alfa',
|
16
16
|
message: "has prima donna method 'bravo!'",
|
17
17
|
source: 'string',
|
@@ -30,8 +30,8 @@ RSpec.describe Reek::SmellDetectors::PrimaDonnaMethod do
|
|
30
30
|
EOS
|
31
31
|
|
32
32
|
expect(src).
|
33
|
-
to reek_of(:PrimaDonnaMethod, lines: [
|
34
|
-
and reek_of(:PrimaDonnaMethod, lines: [
|
33
|
+
to reek_of(:PrimaDonnaMethod, lines: [2], name: 'bravo!').
|
34
|
+
and reek_of(:PrimaDonnaMethod, lines: [5], name: 'charlie!')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'reports nothing when method and bang counterpart exist' do
|
@@ -30,6 +30,33 @@ RSpec.describe Reek::Source::SourceCode do
|
|
30
30
|
result = source_code.syntax_tree
|
31
31
|
expect(result.children.first).to eq "\xFF"
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'returns a :lambda node for lambda expressions' do
|
35
|
+
source = '->() { }'
|
36
|
+
source_code = described_class.new(code: source, origin: '(string)')
|
37
|
+
result = source_code.syntax_tree
|
38
|
+
expect(result.children.first.type).to eq :lambda
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with a source that triggers an encoding error' do
|
43
|
+
let(:source_name) { 'Bad source' }
|
44
|
+
let(:code) do
|
45
|
+
<<-SRC.strip_heredoc
|
46
|
+
# encoding: US-ASCII
|
47
|
+
puts 'こんにちは世界'
|
48
|
+
SRC
|
49
|
+
end
|
50
|
+
let(:src) { described_class.new(code: code, origin: source_name) }
|
51
|
+
|
52
|
+
it 'raises an encoding error' do
|
53
|
+
expect { src.syntax_tree }.to raise_error Reek::Errors::EncodingError
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'explains the origin of the error' do
|
57
|
+
message = "Source '#{source_name}' cannot be processed by Reek due to an encoding error in the source file."
|
58
|
+
expect { src.syntax_tree }.to raise_error.with_message(/#{message}/)
|
59
|
+
end
|
33
60
|
end
|
34
61
|
|
35
62
|
context 'when the parser fails' do
|
@@ -58,7 +85,7 @@ RSpec.describe Reek::Source::SourceCode do
|
|
58
85
|
end
|
59
86
|
|
60
87
|
it 'raises the error' do
|
61
|
-
expect { src }.to raise_error error_class, error_message
|
88
|
+
expect { src.valid_syntax? }.to raise_error error_class, error_message
|
62
89
|
end
|
63
90
|
end
|
64
91
|
end
|
@@ -27,16 +27,16 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
27
27
|
let(:smelly_code) { 'def x() y = 4; end' }
|
28
28
|
|
29
29
|
it 'matches a smelly String' do
|
30
|
-
expect(matcher.
|
30
|
+
expect(matcher).to be_matches(smelly_code)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'doesnt match a fragrant String' do
|
34
|
-
expect(matcher.
|
34
|
+
expect(matcher).not_to be_matches(clean_code)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 're-calculates matches every time' do
|
38
38
|
matcher.matches? smelly_code
|
39
|
-
expect(matcher.
|
39
|
+
expect(matcher).not_to be_matches(clean_code)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -44,11 +44,11 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
44
44
|
let(:matcher) { described_class.new(:UncommunicativeMethodName, name: 'x') }
|
45
45
|
|
46
46
|
it 'matches a smelly file' do
|
47
|
-
expect(matcher.
|
47
|
+
expect(matcher).to be_matches(SMELLY_FILE)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'doesnt match a fragrant file' do
|
51
|
-
expect(matcher.
|
51
|
+
expect(matcher).not_to be_matches(CLEAN_FILE)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -68,7 +68,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
68
68
|
let(:smelly_code) { 'def x() y = 4; end' }
|
69
69
|
|
70
70
|
it 'is truthy' do
|
71
|
-
expect(matcher.
|
71
|
+
expect(matcher).to be_matches(smelly_code)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -79,7 +79,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
79
79
|
let(:truthy_matcher) { described_class.new(:UncommunicativeVariableName, name: 'y') }
|
80
80
|
|
81
81
|
it 'is falsey' do
|
82
|
-
expect(falsey_matcher.
|
82
|
+
expect(falsey_matcher).not_to be_matches(smelly_code)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'sets the proper error message' do
|
@@ -102,7 +102,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
102
102
|
let(:matcher) { described_class.new(:DuplicateMethodCall, name: 'foo', count: 15) }
|
103
103
|
|
104
104
|
it 'is falsey' do
|
105
|
-
expect(matcher.
|
105
|
+
expect(matcher).not_to be_matches(smelly_code)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'sets the proper error message' do
|
@@ -130,14 +130,14 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
context 'for a smell that is disabled by default' do
|
133
|
-
before do
|
134
|
-
default_config = Reek::SmellDetectors::UnusedPrivateMethod.default_config
|
135
|
-
expect(default_config[Reek::SmellConfiguration::ENABLED_KEY]).to be_falsy
|
136
|
-
end
|
137
|
-
|
138
133
|
it 'enables the smell detector to match automatically' do
|
134
|
+
default_config = Reek::SmellDetectors::UnusedPrivateMethod.default_config
|
139
135
|
src = 'class C; private; def foo; end; end'
|
140
|
-
|
136
|
+
|
137
|
+
aggregate_failures do
|
138
|
+
expect(default_config[Reek::SmellConfiguration::ENABLED_KEY]).to be_falsy
|
139
|
+
expect(src).to reek_of(:UnusedPrivateMethod)
|
140
|
+
end
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -146,13 +146,13 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
146
146
|
let(:configured_matcher) { matcher.with_config('accept' => 'x') }
|
147
147
|
|
148
148
|
it 'uses the passed-in configuration for matching' do
|
149
|
-
expect(configured_matcher.
|
150
|
-
expect(configured_matcher.
|
149
|
+
expect(configured_matcher).to be_matches('def foo; q = 2; end')
|
150
|
+
expect(configured_matcher).not_to be_matches('def foo; x = 2; end')
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'leaves the original matcher intact' do
|
154
|
-
expect(configured_matcher.
|
155
|
-
expect(matcher.
|
154
|
+
expect(configured_matcher).not_to be_matches('def foo; x = 2; end')
|
155
|
+
expect(matcher).to be_matches('def foo; x = 2; end')
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|