reek 4.7.3 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -12
- data/.rubocop.yml +1 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -3
- data/README.md +19 -4
- data/lib/reek/ast/node.rb +37 -49
- data/lib/reek/ast/reference_collector.rb +2 -4
- data/lib/reek/ast/sexp_extensions/case.rb +1 -1
- data/lib/reek/ast/sexp_extensions/if.rb +8 -1
- data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -1
- data/lib/reek/ast/sexp_extensions/methods.rb +3 -5
- data/lib/reek/configuration/configuration_file_finder.rb +3 -3
- data/lib/reek/context/code_context.rb +4 -7
- data/lib/reek/context/method_context.rb +5 -10
- data/lib/reek/context/module_context.rb +3 -3
- data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +9 -9
- data/lib/reek/errors/bad_detector_in_comment_error.rb +7 -7
- data/lib/reek/errors/base_error.rb +3 -0
- data/lib/reek/errors/encoding_error.rb +16 -11
- data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +7 -7
- data/lib/reek/errors/incomprehensible_source_error.rb +20 -22
- data/lib/reek/examiner.rb +18 -14
- data/lib/reek/logging_error_handler.rb +7 -5
- data/lib/reek/smell_detectors/class_variable.rb +3 -10
- data/lib/reek/smell_detectors/duplicate_method_call.rb +1 -1
- data/lib/reek/smell_detectors/instance_variable_assumption.rb +1 -9
- data/lib/reek/smell_detectors/manual_dispatch.rb +1 -1
- data/lib/reek/smell_detectors/module_initialize.rb +1 -1
- data/lib/reek/smell_detectors/nested_iterators.rb +2 -1
- data/lib/reek/smell_detectors/too_many_constants.rb +1 -1
- data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +2 -2
- data/lib/reek/smell_detectors/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +9 -23
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +2 -2
- data/spec/factories/factories.rb +2 -13
- data/spec/reek/ast/node_spec.rb +98 -5
- data/spec/reek/ast/reference_collector_spec.rb +1 -1
- data/spec/reek/ast/sexp_extensions_spec.rb +2 -2
- data/spec/reek/cli/application_spec.rb +39 -41
- data/spec/reek/cli/command/todo_list_command_spec.rb +2 -2
- data/spec/reek/code_comment_spec.rb +32 -32
- data/spec/reek/configuration/app_configuration_spec.rb +3 -3
- data/spec/reek/configuration/configuration_file_finder_spec.rb +1 -1
- data/spec/reek/configuration/directory_directives_spec.rb +3 -3
- data/spec/reek/configuration/excluded_paths_spec.rb +1 -1
- data/spec/reek/context/code_context_spec.rb +59 -95
- data/spec/reek/context/ghost_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +1 -1
- data/spec/reek/errors/base_error_spec.rb +13 -0
- data/spec/reek/examiner_spec.rb +72 -29
- data/spec/reek/report/code_climate/code_climate_fingerprint_spec.rb +82 -80
- data/spec/reek/report/code_climate/code_climate_formatter_spec.rb +6 -6
- data/spec/reek/report/xml_report_spec.rb +2 -2
- data/spec/reek/smell_detectors/boolean_parameter_spec.rb +2 -2
- data/spec/reek/smell_detectors/class_variable_spec.rb +26 -32
- data/spec/reek/smell_detectors/control_parameter_spec.rb +34 -4
- data/spec/reek/smell_detectors/duplicate_method_call_spec.rb +3 -3
- data/spec/reek/smell_detectors/module_initialize_spec.rb +14 -0
- data/spec/reek/smell_detectors/nested_iterators_spec.rb +1 -1
- data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +3 -3
- data/spec/reek/smell_detectors/unused_parameters_spec.rb +3 -3
- data/spec/reek/smell_detectors/unused_private_method_spec.rb +9 -9
- data/spec/reek/smell_detectors/utility_function_spec.rb +5 -5
- data/spec/reek/smell_warning_spec.rb +8 -8
- data/spec/reek/source/source_code_spec.rb +5 -25
- data/spec/reek/source/source_locator_spec.rb +6 -6
- data/spec/reek/spec/should_reek_of_spec.rb +7 -7
- data/spec/reek/spec/should_reek_spec.rb +2 -2
- data/spec/reek/spec/smell_matcher_spec.rb +3 -3
- data/spec/reek/tree_dresser_spec.rb +11 -12
- data/spec/spec_helper.rb +3 -12
- metadata +10 -9
@@ -223,7 +223,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
223
223
|
expect(src).not_to reek_of(:NestedIterators)
|
224
224
|
end
|
225
225
|
|
226
|
-
context 'setting the allowed nesting depth to 3' do
|
226
|
+
context 'when setting the allowed nesting depth to 3' do
|
227
227
|
let(:config) do
|
228
228
|
{ Reek::SmellDetectors::NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 }
|
229
229
|
end
|
@@ -29,7 +29,7 @@ RSpec.describe Reek::SmellDetectors::UncommunicativeVariableName do
|
|
29
29
|
and reek_of(:UncommunicativeVariableName, lines: [3], name: 'y')
|
30
30
|
end
|
31
31
|
|
32
|
-
context 'instance variables' do
|
32
|
+
context 'when examining instance variables' do
|
33
33
|
it 'does not report use of one-letter names' do
|
34
34
|
src = 'class Alfa; def bravo; @x; end; end'
|
35
35
|
expect(src).not_to reek_of(:UncommunicativeVariableName)
|
@@ -41,7 +41,7 @@ RSpec.describe Reek::SmellDetectors::UncommunicativeVariableName do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
context 'local variables' do
|
44
|
+
context 'when examining local variables' do
|
45
45
|
it 'does not report single underscore as a variable name' do
|
46
46
|
src = 'def alfa; _ = bravo(); end'
|
47
47
|
expect(src).not_to reek_of(:UncommunicativeVariableName)
|
@@ -78,7 +78,7 @@ RSpec.describe Reek::SmellDetectors::UncommunicativeVariableName do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
context 'block parameters' do
|
81
|
+
context 'when examining block parameters' do
|
82
82
|
it 'reports all relevant block parameters' do
|
83
83
|
src = <<-EOS
|
84
84
|
def alfa
|
@@ -61,7 +61,7 @@ RSpec.describe Reek::SmellDetectors::UnusedParameters do
|
|
61
61
|
expect(src).not_to reek_of(:UnusedParameters)
|
62
62
|
end
|
63
63
|
|
64
|
-
context 'using super' do
|
64
|
+
context 'when using super' do
|
65
65
|
it 'reports nothing with implicit arguments' do
|
66
66
|
src = 'def alfa(*bravo); super; end'
|
67
67
|
expect(src).not_to reek_of(:UnusedParameters)
|
@@ -83,7 +83,7 @@ RSpec.describe Reek::SmellDetectors::UnusedParameters do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
context 'anonymous parameters' do
|
86
|
+
context 'with anonymous parameters' do
|
87
87
|
it 'reports nothing for unused anonymous parameter' do
|
88
88
|
src = 'def alfa(_); end'
|
89
89
|
expect(src).not_to reek_of(:UnusedParameters)
|
@@ -95,7 +95,7 @@ RSpec.describe Reek::SmellDetectors::UnusedParameters do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
context 'splatted parameters' do
|
98
|
+
context 'with splatted parameters' do
|
99
99
|
it 'reports nothing for used splatted parameter' do
|
100
100
|
src = 'def alfa(*bravo); bravo; end'
|
101
101
|
expect(src).not_to reek_of(:UnusedParameters)
|
@@ -38,7 +38,7 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
38
38
|
and reek_of(:UnusedPrivateMethod, lines: [7], name: 'charlie')
|
39
39
|
end
|
40
40
|
|
41
|
-
context 'unused private methods' do
|
41
|
+
context 'when a class has unused private methods' do
|
42
42
|
it 'reports instance methods' do
|
43
43
|
source = <<-EOF
|
44
44
|
class Alfa
|
@@ -116,7 +116,7 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
context 'when the detector is configured via a source code comment' do
|
120
120
|
it 'does not report methods we excluded' do
|
121
121
|
source = <<-EOF
|
122
122
|
# :reek:UnusedPrivateMethod: { exclude: [ bravo ] }
|
@@ -133,8 +133,8 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
context 'used private methods' do
|
137
|
-
it '
|
136
|
+
context 'when a class has only used private methods' do
|
137
|
+
it 'reports nothing' do
|
138
138
|
source = <<-EOF
|
139
139
|
class Alfa
|
140
140
|
def bravo
|
@@ -150,8 +150,8 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
context 'unused protected methods' do
|
154
|
-
it '
|
153
|
+
context 'when a class has unused protected methods' do
|
154
|
+
it 'reports nothing' do
|
155
155
|
source = <<-EOF
|
156
156
|
class Alfa
|
157
157
|
protected
|
@@ -163,8 +163,8 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
context 'unused public methods' do
|
167
|
-
it '
|
166
|
+
context 'when a class has unused public methods' do
|
167
|
+
it 'reports nothing' do
|
168
168
|
source = <<-EOF
|
169
169
|
class Alfa
|
170
170
|
def bravo; end
|
@@ -175,7 +175,7 @@ RSpec.describe Reek::SmellDetectors::UnusedPrivateMethod do
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
describe '
|
178
|
+
describe 'preventing methods from being reported' do
|
179
179
|
let(:source) do
|
180
180
|
<<-EOF
|
181
181
|
class Alfa
|
@@ -98,7 +98,7 @@ RSpec.describe Reek::SmellDetectors::UtilityFunction do
|
|
98
98
|
expect(src).to reek_of(:UtilityFunction, context: 'simple')
|
99
99
|
end
|
100
100
|
|
101
|
-
context '
|
101
|
+
context 'when examining singleton methods' do
|
102
102
|
['class', 'module'].each do |scope|
|
103
103
|
it "does not report for #{scope} with `class << self` notation" do
|
104
104
|
src = "#{scope} Alfa; class << self; def bravo(charlie) charlie.to_s; end; end; end"
|
@@ -111,7 +111,7 @@ RSpec.describe Reek::SmellDetectors::UtilityFunction do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
context 'by using `module_function`' do
|
114
|
+
context 'when defined by using `module_function`' do
|
115
115
|
it 'does not report UtilityFunction also when using multiple arguments' do
|
116
116
|
src = <<-EOS
|
117
117
|
class Alfa
|
@@ -194,7 +194,7 @@ RSpec.describe Reek::SmellDetectors::UtilityFunction do
|
|
194
194
|
{ Reek::SmellDetectors::UtilityFunction::PUBLIC_METHODS_ONLY_KEY => true }
|
195
195
|
end
|
196
196
|
|
197
|
-
context 'public methods' do
|
197
|
+
context 'when examining public methods' do
|
198
198
|
it 'still reports UtilityFunction' do
|
199
199
|
src = <<-EOS
|
200
200
|
class Alfa
|
@@ -208,7 +208,7 @@ RSpec.describe Reek::SmellDetectors::UtilityFunction do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
context 'private methods' do
|
211
|
+
context 'when examining private methods' do
|
212
212
|
it 'does not report UtilityFunction' do
|
213
213
|
src = <<-EOS
|
214
214
|
class Alfa
|
@@ -235,7 +235,7 @@ RSpec.describe Reek::SmellDetectors::UtilityFunction do
|
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
|
-
context 'protected methods' do
|
238
|
+
context 'when examining protected methods' do
|
239
239
|
it 'does not report UtilityFunction' do
|
240
240
|
src = <<-EOS
|
241
241
|
class Alfa
|
@@ -7,7 +7,7 @@ RSpec.describe Reek::SmellWarning do
|
|
7
7
|
let(:utility_function_detector) { build(:smell_detector, smell_type: 'UtilityFunction') }
|
8
8
|
let(:uncommunicative_name_detector) { build(:smell_detector, smell_type: 'UncommunicativeVariableName') }
|
9
9
|
|
10
|
-
|
10
|
+
describe 'sort order' do
|
11
11
|
shared_examples_for 'first sorts ahead of second' do
|
12
12
|
it 'hash differently' do
|
13
13
|
expect(first.hash).not_to eq(second.hash)
|
@@ -26,21 +26,21 @@ RSpec.describe Reek::SmellWarning do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context 'smells
|
29
|
+
context 'when smells differ only by detector' do
|
30
30
|
let(:first) { build(:smell_warning, smell_detector: duplication_detector) }
|
31
31
|
let(:second) { build(:smell_warning, smell_detector: feature_envy_detector) }
|
32
32
|
|
33
33
|
it_behaves_like 'first sorts ahead of second'
|
34
34
|
end
|
35
35
|
|
36
|
-
context 'smells
|
36
|
+
context 'when smells differ only by lines' do
|
37
37
|
let(:first) { build(:smell_warning, smell_detector: feature_envy_detector, lines: [2]) }
|
38
38
|
let(:second) { build(:smell_warning, smell_detector: feature_envy_detector, lines: [3]) }
|
39
39
|
|
40
40
|
it_behaves_like 'first sorts ahead of second'
|
41
41
|
end
|
42
42
|
|
43
|
-
context 'smells
|
43
|
+
context 'when smells differ only by context' do
|
44
44
|
let(:first) { build(:smell_warning, smell_detector: duplication_detector, context: 'first') }
|
45
45
|
let(:second) do
|
46
46
|
build(:smell_warning, smell_detector: duplication_detector, context: 'second')
|
@@ -49,7 +49,7 @@ RSpec.describe Reek::SmellWarning do
|
|
49
49
|
it_behaves_like 'first sorts ahead of second'
|
50
50
|
end
|
51
51
|
|
52
|
-
context 'smells
|
52
|
+
context 'when smells differ only by message' do
|
53
53
|
let(:first) do
|
54
54
|
build(:smell_warning, smell_detector: duplication_detector,
|
55
55
|
context: 'ctx', message: 'first message')
|
@@ -62,7 +62,7 @@ RSpec.describe Reek::SmellWarning do
|
|
62
62
|
it_behaves_like 'first sorts ahead of second'
|
63
63
|
end
|
64
64
|
|
65
|
-
context '
|
65
|
+
context 'when smells differ by name and message' do
|
66
66
|
let(:first) do
|
67
67
|
build(:smell_warning, smell_detector: feature_envy_detector, message: 'second message')
|
68
68
|
end
|
@@ -73,7 +73,7 @@ RSpec.describe Reek::SmellWarning do
|
|
73
73
|
it_behaves_like 'first sorts ahead of second'
|
74
74
|
end
|
75
75
|
|
76
|
-
context 'smells
|
76
|
+
context 'when smells differ everywhere' do
|
77
77
|
let(:first) do
|
78
78
|
build(:smell_warning, smell_detector: duplication_detector,
|
79
79
|
context: 'Dirty#a',
|
@@ -97,7 +97,7 @@ RSpec.describe Reek::SmellWarning do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
describe '#yaml_hash' do
|
101
101
|
let(:context_name) { 'Module::Class#method/block' }
|
102
102
|
let(:lines) { [24, 513] }
|
103
103
|
let(:message) { 'test message' }
|
@@ -39,33 +39,13 @@ RSpec.describe Reek::Source::SourceCode do
|
|
39
39
|
end
|
40
40
|
end
|
41
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
|
60
|
-
end
|
61
|
-
|
62
42
|
context 'when the parser fails' do
|
63
43
|
let(:source_name) { 'Test source' }
|
64
|
-
let(:src) { described_class.new(code: code, origin: source_name, **
|
44
|
+
let(:src) { described_class.new(code: code, origin: source_name, **options) }
|
65
45
|
|
66
46
|
context 'with a Parser::SyntaxError' do
|
67
47
|
let(:code) { '== Invalid Syntax ==' }
|
68
|
-
let(:
|
48
|
+
let(:options) { {} }
|
69
49
|
|
70
50
|
it 'adds a diagnostic' do
|
71
51
|
expect(src.diagnostics.size).to eq 2
|
@@ -76,8 +56,8 @@ RSpec.describe Reek::Source::SourceCode do
|
|
76
56
|
let(:code) { '' }
|
77
57
|
let(:error_class) { RuntimeError }
|
78
58
|
let(:error_message) { 'An error' }
|
79
|
-
let(:
|
80
|
-
parser = instance_double('Parser::
|
59
|
+
let(:options) do
|
60
|
+
parser = instance_double('Parser::Ruby25')
|
81
61
|
allow(parser).to receive(:parse_with_comments).and_raise(error_class, error_message)
|
82
62
|
{
|
83
63
|
parser: parser
|
@@ -85,7 +65,7 @@ RSpec.describe Reek::Source::SourceCode do
|
|
85
65
|
end
|
86
66
|
|
87
67
|
it 'raises the error' do
|
88
|
-
expect { src.
|
68
|
+
expect { src.syntax_tree }.to raise_error error_class, error_message
|
89
69
|
end
|
90
70
|
end
|
91
71
|
end
|
@@ -5,7 +5,7 @@ require_lib 'reek/source/source_locator'
|
|
5
5
|
|
6
6
|
RSpec.describe Reek::Source::SourceLocator do
|
7
7
|
describe '#sources' do
|
8
|
-
context 'applied to hidden directories' do
|
8
|
+
context 'when applied to hidden directories' do
|
9
9
|
let(:path) { SAMPLES_PATH.join('source_with_hidden_directories') }
|
10
10
|
|
11
11
|
let(:expected_paths) do
|
@@ -30,7 +30,7 @@ RSpec.describe Reek::Source::SourceLocator do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# rubocop:disable RSpec/NestedGroups
|
33
|
-
context '
|
33
|
+
context 'with excluded paths' do
|
34
34
|
let(:configuration) do
|
35
35
|
test_configuration_for(CONFIG_PATH.join('with_excluded_paths.reek'))
|
36
36
|
end
|
@@ -44,7 +44,7 @@ RSpec.describe Reek::Source::SourceLocator do
|
|
44
44
|
'uncommunicative_method_name.rb').expand_path
|
45
45
|
end
|
46
46
|
|
47
|
-
context '
|
47
|
+
context 'when options.force_exclusion? is true' do
|
48
48
|
before do
|
49
49
|
allow(options).to receive(:force_exclusion?).and_return(true)
|
50
50
|
end
|
@@ -55,7 +55,7 @@ RSpec.describe Reek::Source::SourceLocator do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
context '
|
58
|
+
context 'when options.force_exclusion? is false' do
|
59
59
|
before do
|
60
60
|
allow(options).to receive(:force_exclusion?).and_return(false)
|
61
61
|
end
|
@@ -120,7 +120,7 @@ RSpec.describe Reek::Source::SourceLocator do
|
|
120
120
|
end
|
121
121
|
# rubocop:enable RSpec/NestedGroups
|
122
122
|
|
123
|
-
context 'non-Ruby paths' do
|
123
|
+
context 'with non-Ruby paths' do
|
124
124
|
let(:path) { SAMPLES_PATH.join('source_with_non_ruby_files') }
|
125
125
|
let(:expected_sources) do
|
126
126
|
[path.join('uncommunicative_parameter_name.rb')]
|
@@ -145,7 +145,7 @@ RSpec.describe Reek::Source::SourceLocator do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
context 'passing "." or "./" as argument' do
|
148
|
+
context 'when passing "." or "./" as argument' do
|
149
149
|
let(:expected_sources) do
|
150
150
|
[Pathname.new('spec/spec_helper.rb'), Pathname.new('lib/reek.rb')]
|
151
151
|
end
|
@@ -21,7 +21,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'different sources of input' do
|
24
|
-
context 'checking code in a string' do
|
24
|
+
context 'when checking code in a string' do
|
25
25
|
let(:clean_code) { 'def good() true; end' }
|
26
26
|
let(:matcher) { described_class.new(:UncommunicativeVariableName, name: 'y') }
|
27
27
|
let(:smelly_code) { 'def x() y = 4; end' }
|
@@ -40,7 +40,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context 'checking code in a File' do
|
43
|
+
context 'when checking code in a File' do
|
44
44
|
let(:matcher) { described_class.new(:UncommunicativeMethodName, name: 'x') }
|
45
45
|
|
46
46
|
it 'matches a smelly file' do
|
@@ -54,7 +54,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe 'smell types and smell details' do
|
57
|
-
context 'passing in smell_details with unknown parameter name' do
|
57
|
+
context 'when passing in smell_details with unknown parameter name' do
|
58
58
|
let(:matcher) { described_class.new(:UncommunicativeVariableName, foo: 'y') }
|
59
59
|
let(:smelly_code) { 'def x() y = 4; end' }
|
60
60
|
|
@@ -63,7 +63,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
context 'both are matching' do
|
66
|
+
context 'when both are matching' do
|
67
67
|
let(:matcher) { described_class.new(:UncommunicativeVariableName, name: 'y') }
|
68
68
|
let(:smelly_code) { 'def x() y = 4; end' }
|
69
69
|
|
@@ -72,7 +72,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context 'no smell_type is matching' do
|
75
|
+
context 'when no smell_type is matching' do
|
76
76
|
let(:smelly_code) { 'def dummy() y = 4; end' }
|
77
77
|
|
78
78
|
let(:falsey_matcher) { described_class.new(:FeatureEnvy, name: 'y') }
|
@@ -97,7 +97,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
context 'smell type is matching but smell details are not' do
|
100
|
+
context 'when smell type is matching but smell details are not' do
|
101
101
|
let(:smelly_code) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
|
102
102
|
let(:matcher) { described_class.new(:DuplicateMethodCall, name: 'foo', count: 15) }
|
103
103
|
|
@@ -129,7 +129,7 @@ RSpec.describe Reek::Spec::ShouldReekOf do
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
context '
|
132
|
+
context 'with a smell that is disabled by default' do
|
133
133
|
it 'enables the smell detector to match automatically' do
|
134
134
|
default_config = Reek::SmellDetectors::UnusedPrivateMethod.default_config
|
135
135
|
src = 'class C; private; def foo; end; end'
|
@@ -22,7 +22,7 @@ RSpec.describe Reek::Spec::ShouldReek do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'checking code in a File' do
|
25
|
-
context '
|
25
|
+
context 'without masking' do
|
26
26
|
let(:matcher) { described_class.new }
|
27
27
|
|
28
28
|
it 'matches a smelly File' do
|
@@ -39,7 +39,7 @@ RSpec.describe Reek::Spec::ShouldReek do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
context '
|
42
|
+
context 'with masking' do
|
43
43
|
let(:path) { CONFIG_PATH.join('full_mask.reek') }
|
44
44
|
let(:configuration) { test_configuration_for(path) }
|
45
45
|
let(:matcher) { described_class.new(configuration: configuration) }
|
@@ -10,7 +10,7 @@ RSpec.describe Reek::Spec::SmellMatcher do
|
|
10
10
|
end
|
11
11
|
let(:matcher) { described_class.new(smell_warning) }
|
12
12
|
|
13
|
-
|
13
|
+
describe '#matches?' do
|
14
14
|
it 'matches on class symbol' do
|
15
15
|
expect(matcher).to be_matches(:UncommunicativeVariableName)
|
16
16
|
end
|
@@ -50,7 +50,7 @@ RSpec.describe Reek::Spec::SmellMatcher do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
describe '#matches_smell_type?' do
|
54
54
|
it 'matches on class symbol' do
|
55
55
|
expect(matcher).to be_matches_smell_type(:UncommunicativeVariableName)
|
56
56
|
end
|
@@ -60,7 +60,7 @@ RSpec.describe Reek::Spec::SmellMatcher do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
describe '#matches_attributes?' do
|
64
64
|
it 'matches on params' do
|
65
65
|
expect(matcher).to be_matches_attributes(test: 'something')
|
66
66
|
end
|
@@ -7,11 +7,13 @@ require_relative '../spec_helper'
|
|
7
7
|
require_lib 'reek/tree_dresser'
|
8
8
|
|
9
9
|
RSpec.describe Reek::TreeDresser do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
describe '#dress' do
|
11
|
+
let(:dresser) { described_class.new }
|
12
|
+
let(:sexp) do
|
13
|
+
Parser::Ruby22.parse('class Klazz; def meth(argument); argument.call_me; end; end')
|
14
|
+
end
|
15
|
+
let(:dressed_ast) { dresser.dress(sexp, {}) }
|
16
|
+
|
15
17
|
# The dressed AST looks like this:
|
16
18
|
# (class
|
17
19
|
# (const nil :Klazz) nil
|
@@ -20,14 +22,11 @@ RSpec.describe Reek::TreeDresser do
|
|
20
22
|
# (arg :argument))
|
21
23
|
# (send
|
22
24
|
# (lvar :argument) :call_me)))
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
let(:args_node) { def_node.children[1] }
|
28
|
-
let(:send_node) { def_node.children[2] }
|
25
|
+
let(:const_node) { dressed_ast.children.first }
|
26
|
+
let(:def_node) { dressed_ast.children.last }
|
27
|
+
let(:args_node) { def_node.children[1] }
|
28
|
+
let(:send_node) { def_node.children[2] }
|
29
29
|
|
30
|
-
context 'dresses the given sexp' do
|
31
30
|
it 'dresses `const` nodes properly' do
|
32
31
|
expect(const_node).to be_a Reek::AST::SexpExtensions::ConstNode
|
33
32
|
end
|