reek 3.2.1 → 3.3.0
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/CHANGELOG.md +5 -0
- data/Rakefile +0 -1
- data/config/defaults.reek +1 -1
- data/features/samples.feature +17 -16
- data/lib/reek.rb +0 -1
- data/lib/reek/ast/ast_node_class_map.rb +5 -1
- data/lib/reek/ast/node.rb +10 -3
- data/lib/reek/ast/object_refs.rb +11 -5
- data/lib/reek/ast/reference_collector.rb +6 -2
- data/lib/reek/ast/sexp_extensions.rb +42 -1
- data/lib/reek/ast/sexp_formatter.rb +2 -1
- data/lib/reek/cli/application.rb +12 -9
- data/lib/reek/cli/command.rb +6 -0
- data/lib/reek/cli/input.rb +4 -4
- data/lib/reek/cli/option_interpreter.rb +11 -7
- data/lib/reek/cli/options.rb +42 -40
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/silencer.rb +12 -3
- data/lib/reek/cli/warning_collector.rb +8 -3
- data/lib/reek/code_comment.rb +6 -1
- data/lib/reek/configuration/app_configuration.rb +65 -100
- data/lib/reek/configuration/configuration_file_finder.rb +4 -13
- data/lib/reek/configuration/configuration_validator.rb +35 -0
- data/lib/reek/configuration/default_directive.rb +12 -0
- data/lib/reek/configuration/directory_directives.rb +54 -0
- data/lib/reek/configuration/excluded_paths.rb +18 -0
- data/lib/reek/context/code_context.rb +19 -17
- data/lib/reek/examiner.rb +9 -7
- data/lib/reek/rake/task.rb +12 -22
- data/lib/reek/report/formatter.rb +6 -1
- data/lib/reek/report/report.rb +22 -13
- data/lib/reek/smells/attribute.rb +6 -53
- data/lib/reek/smells/control_parameter.rb +21 -13
- data/lib/reek/smells/data_clump.rb +17 -9
- data/lib/reek/smells/duplicate_method_call.rb +12 -6
- data/lib/reek/smells/long_parameter_list.rb +2 -2
- data/lib/reek/smells/long_yield_list.rb +4 -4
- data/lib/reek/smells/nested_iterators.rb +4 -2
- data/lib/reek/smells/nil_check.rb +6 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_configuration.rb +17 -7
- data/lib/reek/smells/smell_detector.rb +24 -11
- data/lib/reek/smells/smell_repository.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -6
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +4 -4
- data/lib/reek/smells/too_many_statements.rb +4 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
- data/lib/reek/smells/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +5 -1
- data/lib/reek/source/source_locator.rb +3 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +10 -5
- data/lib/reek/spec/should_reek_of.rb +9 -6
- data/lib/reek/spec/should_reek_only_of.rb +13 -8
- data/lib/reek/tree_dresser.rb +6 -2
- data/lib/reek/tree_walker.rb +40 -32
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +1 -1
- data/spec/reek/ast/node_spec.rb +1 -2
- data/spec/reek/ast/object_refs_spec.rb +40 -42
- data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
- data/spec/reek/cli/warning_collector_spec.rb +8 -12
- data/spec/reek/code_comment_spec.rb +3 -5
- data/spec/reek/configuration/app_configuration_spec.rb +43 -57
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
- data/spec/reek/configuration/default_directive_spec.rb +13 -0
- data/spec/reek/configuration/directory_directives_spec.rb +89 -0
- data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
- data/spec/reek/context/code_context_spec.rb +63 -62
- data/spec/reek/context/method_context_spec.rb +8 -12
- data/spec/reek/context/module_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +3 -7
- data/spec/reek/examiner_spec.rb +14 -25
- data/spec/reek/smells/attribute_spec.rb +2 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
- data/spec/reek/smells/class_variable_spec.rb +29 -44
- data/spec/reek/smells/control_parameter_spec.rb +7 -9
- data/spec/reek/smells/data_clump_spec.rb +25 -32
- data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
- data/spec/reek/smells/feature_envy_spec.rb +16 -17
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
- data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
- data/spec/reek/smells/long_yield_list_spec.rb +6 -9
- data/spec/reek/smells/nested_iterators_spec.rb +14 -16
- data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
- data/spec/reek/smells/smell_configuration_spec.rb +32 -27
- data/spec/reek/smells/smell_detector_shared.rb +12 -13
- data/spec/reek/smells/smell_warning_spec.rb +54 -58
- data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
- data/spec/reek/smells/too_many_methods_spec.rb +13 -14
- data/spec/reek/smells/too_many_statements_spec.rb +8 -10
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/source/source_code_spec.rb +6 -11
- data/spec/reek/spec/should_reek_of_spec.rb +19 -30
- data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
- data/spec/reek/tree_walker_spec.rb +14 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/test.rake +0 -5
- metadata +10 -6
- data/docs/Configuration-Files.md +0 -49
- data/spec/gem/updates_spec.rb +0 -25
- data/spec/gem/yard_spec.rb +0 -11
- data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -6,9 +6,10 @@ require_relative 'smell_detector_shared'
|
|
6
6
|
|
7
7
|
RSpec.describe Reek::Smells::DuplicateMethodCall do
|
8
8
|
context 'when a smell is reported' do
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
let(:detector) { build(:smell_detector, smell_type: :DuplicateMethodCall, source: source_name) }
|
10
|
+
let(:source_name) { 'dummy_source' }
|
11
|
+
|
12
|
+
let(:warning) do
|
12
13
|
src = <<-EOS
|
13
14
|
def double_thing(other)
|
14
15
|
other[@thing]
|
@@ -17,20 +18,20 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
|
|
17
18
|
end
|
18
19
|
EOS
|
19
20
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
20
|
-
smells =
|
21
|
+
smells = detector.examine_context(ctx)
|
21
22
|
expect(smells.length).to eq(1)
|
22
|
-
|
23
|
+
smells.first
|
23
24
|
end
|
24
25
|
|
25
26
|
it_should_behave_like 'SmellDetector'
|
26
27
|
it_should_behave_like 'common fields set correctly'
|
27
28
|
|
28
29
|
it 'reports the call' do
|
29
|
-
expect(
|
30
|
+
expect(warning.parameters[:name]).to eq('other[@thing]')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'reports the correct lines' do
|
33
|
-
expect(
|
34
|
+
expect(warning.lines).to eq([2, 4])
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -213,53 +213,52 @@ RSpec.describe Reek::Smells::FeatureEnvy do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
RSpec.describe Reek::Smells::FeatureEnvy do
|
216
|
-
|
217
|
-
|
218
|
-
@detector = build(:smell_detector, smell_type: :FeatureEnvy, source: @source_name)
|
219
|
-
end
|
216
|
+
let(:detector) { build(:smell_detector, smell_type: :FeatureEnvy, source: source_name) }
|
217
|
+
let(:source_name) { 'string' }
|
220
218
|
|
221
219
|
it_should_behave_like 'SmellDetector'
|
222
220
|
|
223
221
|
context 'when a smell is reported' do
|
224
|
-
|
225
|
-
|
222
|
+
let(:receiver) { 'other' }
|
223
|
+
|
224
|
+
let(:smells) do
|
226
225
|
src = <<-EOS
|
227
226
|
def envious(other)
|
228
|
-
#{
|
227
|
+
#{receiver}.call
|
229
228
|
self.do_nothing
|
230
|
-
#{
|
231
|
-
#{
|
229
|
+
#{receiver}.other
|
230
|
+
#{receiver}.fred
|
232
231
|
end
|
233
232
|
EOS
|
234
|
-
|
233
|
+
Reek::Examiner.new(src, ['FeatureEnvy']).smells
|
235
234
|
end
|
236
235
|
|
237
236
|
it 'reports only that smell' do
|
238
|
-
expect(
|
237
|
+
expect(smells.length).to eq(1)
|
239
238
|
end
|
240
239
|
|
241
240
|
it 'reports the source' do
|
242
|
-
expect(
|
241
|
+
expect(smells[0].source).to eq(source_name)
|
243
242
|
end
|
244
243
|
|
245
244
|
it 'reports the smell class' do
|
246
|
-
expect(
|
245
|
+
expect(smells[0].smell_category).to eq(described_class.smell_category)
|
247
246
|
end
|
248
247
|
|
249
248
|
it 'reports the smell sub class' do
|
250
|
-
expect(
|
249
|
+
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
251
250
|
end
|
252
251
|
|
253
252
|
it 'reports the envious receiver' do
|
254
|
-
expect(
|
253
|
+
expect(smells[0].parameters[:name]).to eq(receiver)
|
255
254
|
end
|
256
255
|
|
257
256
|
it 'reports the number of references' do
|
258
|
-
expect(
|
257
|
+
expect(smells[0].parameters[:count]).to eq(3)
|
259
258
|
end
|
260
259
|
|
261
260
|
it 'reports the referring lines' do
|
262
|
-
expect(
|
261
|
+
expect(smells[0].lines).to eq([2, 4, 5])
|
263
262
|
end
|
264
263
|
end
|
265
264
|
end
|
@@ -184,10 +184,8 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
|
|
184
184
|
end
|
185
185
|
|
186
186
|
context 'when a smell is reported' do
|
187
|
-
|
188
|
-
|
189
|
-
@detector = build(:smell_detector, smell_type: :IrresponsibleModule, source: @source_name)
|
190
|
-
end
|
187
|
+
let(:detector) { build(:smell_detector, smell_type: :IrresponsibleModule, source: source_name) }
|
188
|
+
let(:source_name) { 'dummy_source' }
|
191
189
|
|
192
190
|
it_should_behave_like 'SmellDetector'
|
193
191
|
end
|
@@ -74,15 +74,13 @@ RSpec.describe Reek::Smells::LongParameterList do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
RSpec.describe Reek::Smells::LongParameterList do
|
77
|
-
|
78
|
-
|
79
|
-
@detector = build(:smell_detector, smell_type: :LongParameterList, source: @source_name)
|
80
|
-
end
|
77
|
+
let(:detector) { build(:smell_detector, smell_type: :LongParameterList, source: source_name) }
|
78
|
+
let(:source_name) { 'dummy_source' }
|
81
79
|
|
82
80
|
it_should_behave_like 'SmellDetector'
|
83
81
|
|
84
82
|
context 'when a smell is reported' do
|
85
|
-
|
83
|
+
let(:warning) do
|
86
84
|
src = <<-EOS
|
87
85
|
def badguy(arga, argb, argc, argd)
|
88
86
|
f(3)
|
@@ -90,18 +88,17 @@ RSpec.describe Reek::Smells::LongParameterList do
|
|
90
88
|
end
|
91
89
|
EOS
|
92
90
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
93
|
-
|
94
|
-
@warning = @smells[0]
|
91
|
+
detector.examine_context(ctx).first
|
95
92
|
end
|
96
93
|
|
97
94
|
it_should_behave_like 'common fields set correctly'
|
98
95
|
|
99
96
|
it 'reports the number of parameters' do
|
100
|
-
expect(
|
97
|
+
expect(warning.parameters[:count]).to eq(4)
|
101
98
|
end
|
102
99
|
|
103
100
|
it 'reports the line number of the method' do
|
104
|
-
expect(
|
101
|
+
expect(warning.lines).to eq([1])
|
105
102
|
end
|
106
103
|
end
|
107
104
|
end
|
@@ -4,10 +4,8 @@ require_relative '../../../lib/reek/smells/long_yield_list'
|
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::LongYieldList do
|
7
|
-
|
8
|
-
|
9
|
-
@detector = build(:smell_detector, smell_type: :LongYieldList, source: @source_name)
|
10
|
-
end
|
7
|
+
let(:detector) { build(:smell_detector, smell_type: :LongYieldList, source: source_name) }
|
8
|
+
let(:source_name) { 'dummy_source' }
|
11
9
|
|
12
10
|
it_should_behave_like 'SmellDetector'
|
13
11
|
|
@@ -31,7 +29,7 @@ RSpec.describe Reek::Smells::LongYieldList do
|
|
31
29
|
end
|
32
30
|
|
33
31
|
context 'when a smells is reported' do
|
34
|
-
|
32
|
+
let(:warning) do
|
35
33
|
src = <<-EOS
|
36
34
|
def simple(arga, argb, &blk)
|
37
35
|
f(3)
|
@@ -39,15 +37,14 @@ RSpec.describe Reek::Smells::LongYieldList do
|
|
39
37
|
end
|
40
38
|
EOS
|
41
39
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
42
|
-
|
43
|
-
@warning = @smells[0]
|
40
|
+
detector.examine_context(ctx).first
|
44
41
|
end
|
45
42
|
|
46
43
|
it_should_behave_like 'common fields set correctly'
|
47
44
|
|
48
45
|
it 'reports the correct values' do
|
49
|
-
expect(
|
50
|
-
expect(
|
46
|
+
expect(warning.parameters[:count]).to eq(4)
|
47
|
+
expect(warning.lines).to eq([3])
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
@@ -123,11 +123,11 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
context 'when the allowed nesting depth is 3' do
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
let(:configuration) do
|
127
|
+
config = { Reek::Smells::NestedIterators =>
|
128
|
+
{ Reek::Smells::NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 } }
|
129
|
+
test_configuration_for(config)
|
129
130
|
end
|
130
|
-
let(:configuration) { test_configuration_for(@config) }
|
131
131
|
|
132
132
|
it 'should not report nested iterators 2 levels deep' do
|
133
133
|
src = <<-EOS
|
@@ -161,11 +161,11 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
context 'when ignoring iterators' do
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
let(:configuration) do
|
165
|
+
config = { Reek::Smells::NestedIterators =>
|
166
|
+
{ Reek::Smells::NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me'] } }
|
167
|
+
test_configuration_for(config)
|
167
168
|
end
|
168
|
-
let(:configuration) { test_configuration_for(@config) }
|
169
169
|
|
170
170
|
it 'should not report nesting the ignored iterator inside another' do
|
171
171
|
src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting} } end'
|
@@ -207,15 +207,13 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
207
207
|
end
|
208
208
|
|
209
209
|
RSpec.describe Reek::Smells::NestedIterators do
|
210
|
-
|
211
|
-
|
212
|
-
@detector = build(:smell_detector, smell_type: :NestedIterators, source: @source_name)
|
213
|
-
end
|
210
|
+
let(:detector) { build(:smell_detector, smell_type: :NestedIterators, source: source_name) }
|
211
|
+
let(:source_name) { 'dummy_source' }
|
214
212
|
|
215
213
|
it_should_behave_like 'SmellDetector'
|
216
214
|
|
217
215
|
context 'when a smell is reported' do
|
218
|
-
|
216
|
+
let(:warning) do
|
219
217
|
src = <<-EOS
|
220
218
|
def fred()
|
221
219
|
nothing.each do |item|
|
@@ -224,14 +222,14 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
224
222
|
end
|
225
223
|
EOS
|
226
224
|
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
227
|
-
|
225
|
+
detector.examine_context(ctx).first
|
228
226
|
end
|
229
227
|
|
230
228
|
it_should_behave_like 'common fields set correctly'
|
231
229
|
|
232
230
|
it 'reports correct values' do
|
233
|
-
expect(
|
234
|
-
expect(
|
231
|
+
expect(warning.parameters[:count]).to eq(2)
|
232
|
+
expect(warning.lines).to eq([3])
|
235
233
|
end
|
236
234
|
end
|
237
235
|
end
|
@@ -5,10 +5,8 @@ require_relative 'smell_detector_shared'
|
|
5
5
|
require_relative '../../../lib/reek/source/source_code'
|
6
6
|
|
7
7
|
RSpec.describe Reek::Smells::RepeatedConditional do
|
8
|
-
|
9
|
-
|
10
|
-
@detector = build(:smell_detector, smell_type: :RepeatedConditional, source: @source_name)
|
11
|
-
end
|
8
|
+
let(:detector) { build(:smell_detector, smell_type: :RepeatedConditional, source: source_name) }
|
9
|
+
let(:source_name) { 'dummy_source' }
|
12
10
|
|
13
11
|
it_should_behave_like 'SmellDetector'
|
14
12
|
|
@@ -16,7 +14,7 @@ RSpec.describe Reek::Smells::RepeatedConditional do
|
|
16
14
|
it 'gathers an empty hash' do
|
17
15
|
ast = Reek::Source::SourceCode.from('module Stable; end').syntax_tree
|
18
16
|
ctx = Reek::Context::CodeContext.new(nil, ast)
|
19
|
-
expect(
|
17
|
+
expect(detector.conditional_counts(ctx).length).to eq(0)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -24,7 +22,7 @@ RSpec.describe Reek::Smells::RepeatedConditional do
|
|
24
22
|
it 'does not record the condition' do
|
25
23
|
ast = Reek::Source::SourceCode.from('def fred() yield(3) if block_given?; end').syntax_tree
|
26
24
|
ctx = Reek::Context::CodeContext.new(nil, ast)
|
27
|
-
expect(
|
25
|
+
expect(detector.conditional_counts(ctx).length).to eq(0)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -32,53 +30,55 @@ RSpec.describe Reek::Smells::RepeatedConditional do
|
|
32
30
|
it 'does not record the condition' do
|
33
31
|
ast = Reek::Source::SourceCode.from('def fred() case; when 3; end; end').syntax_tree
|
34
32
|
ctx = Reek::Context::CodeContext.new(nil, ast)
|
35
|
-
expect(
|
33
|
+
expect(detector.conditional_counts(ctx).length).to eq(0)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
context 'with three identical conditionals' do
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
let(:cond) { '@field == :sym' }
|
39
|
+
let(:cond_expr) { Reek::Source::SourceCode.from(cond).syntax_tree }
|
40
|
+
|
41
|
+
let(:conds) do
|
43
42
|
src = <<-EOS
|
44
43
|
class Scrunch
|
45
44
|
def first
|
46
45
|
puts "hello" if @debug
|
47
|
-
return #{
|
46
|
+
return #{cond} ? 0 : 3;
|
48
47
|
end
|
49
48
|
def second
|
50
|
-
if #{
|
49
|
+
if #{cond}
|
51
50
|
@other += " quarts"
|
52
51
|
end
|
53
52
|
end
|
54
53
|
def third
|
55
|
-
raise 'flu!' unless #{
|
54
|
+
raise 'flu!' unless #{cond}
|
56
55
|
end
|
57
56
|
end
|
58
57
|
EOS
|
59
58
|
|
60
59
|
ast = Reek::Source::SourceCode.from(src).syntax_tree
|
61
|
-
|
62
|
-
|
60
|
+
ctx = Reek::Context::CodeContext.new(nil, ast)
|
61
|
+
detector.conditional_counts(ctx)
|
63
62
|
end
|
64
63
|
|
65
64
|
it 'finds both conditionals' do
|
66
|
-
expect(
|
65
|
+
expect(conds.length).to eq(2)
|
67
66
|
end
|
68
67
|
|
69
68
|
it 'returns the condition expr' do
|
70
|
-
expect(
|
69
|
+
expect(conds.keys[1]).to eq(cond_expr)
|
71
70
|
end
|
72
71
|
|
73
72
|
it 'knows there are three copies' do
|
74
|
-
expect(
|
73
|
+
expect(conds.values[1].length).to eq(3)
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
77
|
context 'with a matching if and case' do
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
let(:cond) { '@field == :sym' }
|
79
|
+
let(:cond_expr) { Reek::Source::SourceCode.from(cond).syntax_tree }
|
80
|
+
|
81
|
+
let(:conds) do
|
82
82
|
src = <<-EOS
|
83
83
|
class Scrunch
|
84
84
|
def alpha
|
@@ -95,19 +95,19 @@ RSpec.describe Reek::Smells::RepeatedConditional do
|
|
95
95
|
|
96
96
|
ast = Reek::Source::SourceCode.from(src).syntax_tree
|
97
97
|
ctx = Reek::Context::CodeContext.new(nil, ast)
|
98
|
-
|
98
|
+
detector.conditional_counts(ctx)
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'finds exactly one conditional' do
|
102
|
-
expect(
|
102
|
+
expect(conds.length).to eq(1)
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'returns the condition expr' do
|
106
|
-
expect(
|
106
|
+
expect(conds.keys[0]).to eq(cond_expr)
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'knows there are two copies' do
|
110
|
-
expect(
|
110
|
+
expect(conds.values[0].length).to eq(2)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -8,47 +8,52 @@ RSpec.describe Reek::Smells::SmellConfiguration do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'when overriding default configs' do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
let(:base_config) do
|
12
|
+
{
|
13
|
+
'accept' => ['_'],
|
14
|
+
'enabled' => true,
|
15
|
+
'exclude' => [],
|
16
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/]
|
17
|
+
}
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
it { expect(
|
21
|
-
it { expect(
|
20
|
+
let(:smell_config) { described_class.new(base_config) }
|
21
|
+
|
22
|
+
it { expect(smell_config.merge!({})).to eq(base_config) }
|
23
|
+
it { expect(smell_config.merge!('enabled' => true)).to eq(base_config) }
|
24
|
+
it { expect(smell_config.merge!('exclude' => [])).to eq(base_config) }
|
25
|
+
it { expect(smell_config.merge!('accept' => ['_'])).to eq(base_config) }
|
22
26
|
it do
|
23
|
-
|
24
|
-
expect(
|
27
|
+
updated = smell_config.merge!('reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
|
28
|
+
expect(updated).to eq(base_config)
|
25
29
|
end
|
26
30
|
it do
|
27
|
-
|
28
|
-
expect(
|
31
|
+
updated = smell_config.merge!('accept' => ['_'], 'enabled' => true)
|
32
|
+
expect(updated).to eq(base_config)
|
29
33
|
end
|
30
34
|
|
31
35
|
it 'should override single values' do
|
32
|
-
|
33
|
-
expect(
|
34
|
-
|
35
|
-
|
36
|
+
updated = smell_config.merge!('enabled' => false)
|
37
|
+
expect(updated).to eq('accept' => ['_'],
|
38
|
+
'enabled' => false,
|
39
|
+
'exclude' => [],
|
40
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
|
36
41
|
end
|
37
42
|
|
38
43
|
it 'should override arrays of values' do
|
39
|
-
|
40
|
-
expect(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
updated = smell_config.merge!('reject' => [/^.$/, /[3-9]$/])
|
45
|
+
expect(updated).to eq('accept' => ['_'],
|
46
|
+
'enabled' => true,
|
47
|
+
'exclude' => [],
|
48
|
+
'reject' => [/^.$/, /[3-9]$/])
|
44
49
|
end
|
45
50
|
|
46
51
|
it 'should override multiple values' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
updated = smell_config.merge!('accept' => [/[A-Z]$/], 'enabled' => false)
|
53
|
+
expect(updated).to eq('accept' => [/[A-Z]$/],
|
54
|
+
'enabled' => false,
|
55
|
+
'exclude' => [],
|
56
|
+
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|