reek 4.4.1 → 4.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +46 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -1
- data/docs/Duplicate-Method-Call.md +96 -0
- data/docs/How-To-Write-New-Detectors.md +16 -0
- data/docs/Large-Class.md +2 -1
- data/docs/Simulated-Polymorphism.md +1 -1
- data/features/configuration_via_source_comments/erroneous_source_comments.feature +39 -0
- data/lib/reek/ast/node.rb +4 -0
- data/lib/reek/code_comment.rb +11 -3
- data/lib/reek/context/code_context.rb +3 -1
- data/lib/reek/context/module_context.rb +1 -1
- data/lib/reek/errors.rb +32 -0
- data/lib/reek/examiner.rb +6 -1
- data/lib/reek/rake/task.rb +0 -2
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/class_variable.rb +2 -2
- data/lib/reek/smells/instance_variable_assumption.rb +1 -1
- data/lib/reek/smells/prima_donna_method.rb +18 -17
- data/lib/reek/smells/smell_detector.rb +19 -2
- data/lib/reek/smells/unused_private_method.rb +1 -1
- data/lib/reek/spec/should_reek_of.rb +2 -0
- data/lib/reek/version.rb +1 -1
- data/spec/factories/factories.rb +11 -0
- data/spec/quality/reek_source_spec.rb +1 -1
- data/spec/reek/ast/node_spec.rb +40 -0
- data/spec/reek/ast/object_refs_spec.rb +20 -59
- data/spec/reek/ast/sexp_extensions_spec.rb +16 -19
- data/spec/reek/cli/application_spec.rb +25 -25
- data/spec/reek/cli/command/report_command_spec.rb +1 -2
- data/spec/reek/cli/command/todo_list_command_spec.rb +1 -1
- data/spec/reek/cli/options_spec.rb +7 -5
- data/spec/reek/code_comment_spec.rb +74 -44
- data/spec/reek/configuration/default_directive_spec.rb +3 -3
- data/spec/reek/configuration/directory_directives_spec.rb +10 -10
- data/spec/reek/configuration/excluded_paths_spec.rb +2 -2
- data/spec/reek/context/code_context_spec.rb +22 -26
- data/spec/reek/context/ghost_context_spec.rb +1 -1
- data/spec/reek/context/method_context_spec.rb +13 -7
- data/spec/reek/context/module_context_spec.rb +4 -4
- data/spec/reek/context/root_context_spec.rb +1 -1
- data/spec/reek/context_builder_spec.rb +34 -38
- data/spec/reek/examiner_spec.rb +43 -22
- data/spec/reek/rake/task_spec.rb +3 -3
- data/spec/reek/report/code_climate_formatter_spec.rb +42 -40
- data/spec/reek/report/code_climate_report_spec.rb +1 -1
- data/spec/reek/report/html_report_spec.rb +1 -1
- data/spec/reek/report/json_report_spec.rb +1 -1
- data/spec/reek/report/location_formatter_spec.rb +18 -16
- data/spec/reek/report/text_report_spec.rb +12 -8
- data/spec/reek/report/xml_report_spec.rb +1 -1
- data/spec/reek/report/yaml_report_spec.rb +1 -1
- data/spec/reek/report_spec.rb +4 -4
- data/spec/reek/smells/attribute_spec.rb +7 -10
- data/spec/reek/smells/boolean_parameter_spec.rb +14 -20
- data/spec/reek/smells/class_variable_spec.rb +6 -5
- data/spec/reek/smells/control_parameter_spec.rb +3 -2
- data/spec/reek/smells/data_clump_spec.rb +3 -6
- data/spec/reek/smells/duplicate_method_call_spec.rb +10 -14
- data/spec/reek/smells/feature_envy_spec.rb +34 -25
- data/spec/reek/smells/instance_variable_assumption_spec.rb +6 -9
- data/spec/reek/smells/irresponsible_module_spec.rb +3 -6
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -7
- data/spec/reek/smells/long_yield_list_spec.rb +3 -6
- data/spec/reek/smells/manual_dispatch_spec.rb +3 -6
- data/spec/reek/smells/nested_iterators_spec.rb +10 -8
- data/spec/reek/smells/nil_check_spec.rb +2 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -8
- data/spec/reek/smells/smell_configuration_spec.rb +3 -3
- data/spec/reek/smells/smell_detector_spec.rb +10 -0
- data/spec/reek/smells/smell_repository_spec.rb +6 -6
- data/spec/reek/smells/smell_warning_spec.rb +35 -39
- data/spec/reek/smells/subclassed_from_core_class_spec.rb +5 -5
- data/spec/reek/smells/too_many_constants_spec.rb +10 -10
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +1 -1
- data/spec/reek/smells/too_many_statements_spec.rb +3 -6
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +9 -6
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +6 -9
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +20 -24
- data/spec/reek/smells/unused_parameters_spec.rb +35 -24
- data/spec/reek/smells/unused_private_method_spec.rb +25 -33
- data/spec/reek/smells/utility_function_spec.rb +27 -14
- data/spec/reek/source/source_code_spec.rb +6 -6
- data/spec/reek/source/source_locator_spec.rb +34 -17
- data/spec/reek/spec/should_reek_of_spec.rb +17 -12
- data/spec/reek/spec/should_reek_only_of_spec.rb +5 -5
- data/spec/reek/spec/should_reek_spec.rb +3 -3
- data/spec/reek/tree_dresser_spec.rb +6 -4
- data/spec/spec_helper.rb +3 -0
- data/tasks/rubocop.rake +9 -3
- metadata +4 -2
@@ -17,7 +17,7 @@ RSpec.describe Reek::Smells::InstanceVariableAssumption do
|
|
17
17
|
context: 'Alfa',
|
18
18
|
message: "assumes too much for instance variable '@charlie'",
|
19
19
|
source: 'string',
|
20
|
-
assumption:
|
20
|
+
assumption: '@charlie')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'does count all occurences' do
|
@@ -34,15 +34,12 @@ RSpec.describe Reek::Smells::InstanceVariableAssumption do
|
|
34
34
|
|
35
35
|
EOS
|
36
36
|
|
37
|
-
expect(src).
|
38
|
-
|
39
|
-
|
40
|
-
expect(src).to reek_of(:InstanceVariableAssumption,
|
41
|
-
lines: [1],
|
42
|
-
assumption: :@echo)
|
37
|
+
expect(src).
|
38
|
+
to reek_of(:InstanceVariableAssumption, lines: [1], assumption: '@charlie').
|
39
|
+
and reek_of(:InstanceVariableAssumption, lines: [1], assumption: '@echo')
|
43
40
|
end
|
44
41
|
|
45
|
-
it '
|
42
|
+
it 'does not report an empty class' do
|
46
43
|
src = <<-EOS
|
47
44
|
class Alfa
|
48
45
|
end
|
@@ -76,7 +73,7 @@ RSpec.describe Reek::Smells::InstanceVariableAssumption do
|
|
76
73
|
end
|
77
74
|
EOS
|
78
75
|
|
79
|
-
expect(src).to reek_of(:InstanceVariableAssumption, assumption:
|
76
|
+
expect(src).to reek_of(:InstanceVariableAssumption, assumption: '@delta')
|
80
77
|
end
|
81
78
|
|
82
79
|
it 'reports inner class even if outer class initializes the variable' do
|
@@ -25,12 +25,9 @@ RSpec.describe Reek::Smells::IrresponsibleModule do
|
|
25
25
|
end
|
26
26
|
EOS
|
27
27
|
|
28
|
-
expect(src).
|
29
|
-
|
30
|
-
|
31
|
-
expect(src).to reek_of(:IrresponsibleModule,
|
32
|
-
lines: [4],
|
33
|
-
context: 'Alfa::Charlie')
|
28
|
+
expect(src).
|
29
|
+
to reek_of(:IrresponsibleModule, lines: [1], context: 'Alfa').
|
30
|
+
and reek_of(:IrresponsibleModule, lines: [4], context: 'Alfa::Charlie')
|
34
31
|
end
|
35
32
|
|
36
33
|
%w(class module).each do |scope|
|
@@ -29,16 +29,14 @@ RSpec.describe Reek::Smells::LongParameterList do
|
|
29
29
|
end
|
30
30
|
EOS
|
31
31
|
|
32
|
-
expect(src).
|
33
|
-
|
34
|
-
|
35
|
-
expect(src).to reek_of(:LongParameterList,
|
36
|
-
lines: [5],
|
37
|
-
context: 'Alfa#golf')
|
32
|
+
expect(src).
|
33
|
+
to reek_of(:LongParameterList, lines: [2], context: 'Alfa#bravo').
|
34
|
+
and reek_of(:LongParameterList, lines: [5], context: 'Alfa#golf')
|
38
35
|
end
|
39
36
|
|
40
37
|
it 'reports nothing for 3 parameters' do
|
41
|
-
|
38
|
+
src = 'def alfa(bravo, charlie, delta); end'
|
39
|
+
expect(src).not_to reek_of(:LongParameterList)
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'does not count an optional block' do
|
@@ -32,12 +32,9 @@ RSpec.describe Reek::Smells::LongYieldList do
|
|
32
32
|
end
|
33
33
|
EOS
|
34
34
|
|
35
|
-
expect(src).
|
36
|
-
|
37
|
-
|
38
|
-
expect(src).to reek_of(:LongYieldList,
|
39
|
-
lines: [7],
|
40
|
-
context: 'Alfa#golf')
|
35
|
+
expect(src).
|
36
|
+
to reek_of(:LongYieldList, lines: [3], context: 'Alfa#bravo').
|
37
|
+
and reek_of(:LongYieldList, lines: [7], context: 'Alfa#golf')
|
41
38
|
end
|
42
39
|
|
43
40
|
it 'does not report yield with 3 parameters' do
|
@@ -31,12 +31,9 @@ RSpec.describe Reek::Smells::ManualDispatch do
|
|
31
31
|
end
|
32
32
|
EOS
|
33
33
|
|
34
|
-
expect(src).
|
35
|
-
|
36
|
-
|
37
|
-
expect(src).to reek_of(:ManualDispatch,
|
38
|
-
lines: [7],
|
39
|
-
context: 'Alfa#delta')
|
34
|
+
expect(src).
|
35
|
+
to reek_of(:ManualDispatch, lines: [3], context: 'Alfa#bravo').
|
36
|
+
and reek_of(:ManualDispatch, lines: [7], context: 'Alfa#delta')
|
40
37
|
end
|
41
38
|
|
42
39
|
it 'reports manual dispatch smell when using #respond_to? on implicit self' do
|
@@ -34,8 +34,9 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
34
34
|
end
|
35
35
|
EOS
|
36
36
|
|
37
|
-
expect(src).
|
38
|
-
|
37
|
+
expect(src).
|
38
|
+
to reek_of(:NestedIterators, lines: [3], depth: 2).
|
39
|
+
and reek_of(:NestedIterators, lines: [8], depth: 3)
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'reports no smells with no iterators' do
|
@@ -53,7 +54,7 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
53
54
|
expect(src).not_to reek_of(:NestedIterators)
|
54
55
|
end
|
55
56
|
|
56
|
-
it '
|
57
|
+
it 'does not report nested iterators for Object#tap' do
|
57
58
|
src = <<-EOS
|
58
59
|
def alfa(bravo)
|
59
60
|
bravo.tap do |charlie|
|
@@ -65,7 +66,7 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
65
66
|
expect(src).not_to reek_of(:NestedIterators)
|
66
67
|
end
|
67
68
|
|
68
|
-
it '
|
69
|
+
it 'does not report method with successive iterators' do
|
69
70
|
src = <<-EOS
|
70
71
|
def alfa
|
71
72
|
@bravo.each { |charlie| charlie }
|
@@ -76,7 +77,7 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
76
77
|
expect(src).not_to reek_of(:NestedIterators)
|
77
78
|
end
|
78
79
|
|
79
|
-
it '
|
80
|
+
it 'does not report method with chained iterators' do
|
80
81
|
src = <<-EOS
|
81
82
|
def alfa
|
82
83
|
bravo.sort_by { |charlie| charlie }.each { |delta| delta }
|
@@ -123,8 +124,9 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
123
124
|
end
|
124
125
|
EOS
|
125
126
|
|
126
|
-
expect(src).
|
127
|
-
|
127
|
+
expect(src).
|
128
|
+
to not_reek_of(:NestedIterators, depth: 2).
|
129
|
+
and reek_of(:NestedIterators, depth: 3, lines: [4])
|
128
130
|
end
|
129
131
|
|
130
132
|
it 'reports all lines on which nested iterators occur' do
|
@@ -314,7 +316,7 @@ RSpec.describe Reek::Smells::NestedIterators do
|
|
314
316
|
expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
|
315
317
|
end
|
316
318
|
|
317
|
-
it '
|
319
|
+
it 'reports nested iterators with the ignored iterator between them' do
|
318
320
|
src = <<-EOS
|
319
321
|
def alfa(bravo)
|
320
322
|
bravo.each do |charlie|
|
@@ -30,7 +30,8 @@ RSpec.describe Reek::Smells::NilCheck do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'reports nothing when scope includes no nil checks' do
|
33
|
-
|
33
|
+
src = 'def alfa; end'
|
34
|
+
expect(src).not_to reek_of(:NilCheck)
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'reports when scope uses == nil' do
|
@@ -15,7 +15,7 @@ RSpec.describe Reek::Smells::PrimaDonnaMethod do
|
|
15
15
|
context: 'Alfa',
|
16
16
|
message: "has prima donna method 'bravo!'",
|
17
17
|
source: 'string',
|
18
|
-
name:
|
18
|
+
name: 'bravo!')
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does count all occurences' do
|
@@ -29,15 +29,12 @@ RSpec.describe Reek::Smells::PrimaDonnaMethod do
|
|
29
29
|
end
|
30
30
|
EOS
|
31
31
|
|
32
|
-
expect(src).
|
33
|
-
|
34
|
-
|
35
|
-
expect(src).to reek_of(:PrimaDonnaMethod,
|
36
|
-
lines: [1],
|
37
|
-
name: :charlie!)
|
32
|
+
expect(src).
|
33
|
+
to reek_of(:PrimaDonnaMethod, lines: [1], name: 'bravo!').
|
34
|
+
and reek_of(:PrimaDonnaMethod, lines: [1], name: 'charlie!')
|
38
35
|
end
|
39
36
|
|
40
|
-
it '
|
37
|
+
it 'reports nothing when method and bang counterpart exist' do
|
41
38
|
src = <<-EOS
|
42
39
|
class Alfa
|
43
40
|
def bravo
|
@@ -27,7 +27,7 @@ RSpec.describe Reek::Smells::SmellConfiguration do
|
|
27
27
|
expect(updated).to eq(base_config)
|
28
28
|
end
|
29
29
|
|
30
|
-
it '
|
30
|
+
it 'overrides single values' do
|
31
31
|
updated = smell_config.merge('enabled' => false)
|
32
32
|
expect(updated).to eq('accept' => ['_'],
|
33
33
|
'enabled' => false,
|
@@ -35,7 +35,7 @@ RSpec.describe Reek::Smells::SmellConfiguration do
|
|
35
35
|
'reject' => [/^.$/, /[0-9]$/, /[A-Z]/])
|
36
36
|
end
|
37
37
|
|
38
|
-
it '
|
38
|
+
it 'overrides arrays of values' do
|
39
39
|
updated = smell_config.merge('reject' => [/^.$/, /[3-9]$/])
|
40
40
|
expect(updated).to eq('accept' => ['_'],
|
41
41
|
'enabled' => true,
|
@@ -43,7 +43,7 @@ RSpec.describe Reek::Smells::SmellConfiguration do
|
|
43
43
|
'reject' => [/^.$/, /[3-9]$/])
|
44
44
|
end
|
45
45
|
|
46
|
-
it '
|
46
|
+
it 'overrides multiple values' do
|
47
47
|
updated = smell_config.merge('accept' => [/[A-Z]$/], 'enabled' => false)
|
48
48
|
expect(updated).to eq('accept' => [/[A-Z]$/],
|
49
49
|
'enabled' => false,
|
@@ -33,4 +33,14 @@ RSpec.describe Reek::Smells::SmellDetector do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
describe '.valid_detector?' do
|
38
|
+
it 'returns true for a valid detector' do
|
39
|
+
expect(described_class.valid_detector?('DuplicateMethodCall')).to be true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns false for an invalid detector' do
|
43
|
+
expect(described_class.valid_detector?('Unknown')).to be false
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
@@ -6,16 +6,16 @@ RSpec.describe Reek::Smells::SmellRepository do
|
|
6
6
|
describe '.smell_types' do
|
7
7
|
let(:smell_types) { described_class.smell_types }
|
8
8
|
|
9
|
-
it '
|
10
|
-
expect(smell_types).to include(Reek::Smells::IrresponsibleModule)
|
11
|
-
|
9
|
+
it 'includes existing smell_types' do
|
10
|
+
expect(smell_types).to include(Reek::Smells::IrresponsibleModule).
|
11
|
+
and include(Reek::Smells::TooManyStatements)
|
12
12
|
end
|
13
13
|
|
14
|
-
it '
|
15
|
-
expect(smell_types).
|
14
|
+
it 'excludes the smell detector base class' do
|
15
|
+
expect(smell_types).not_to include(Reek::Smells::SmellDetector)
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'returns the smell types in alphabetic order' do
|
19
19
|
expect(smell_types).to eq(smell_types.sort_by(&:name))
|
20
20
|
end
|
21
21
|
end
|
@@ -12,15 +12,17 @@ RSpec.describe Reek::Smells::SmellWarning do
|
|
12
12
|
it 'hash differently' do
|
13
13
|
expect(first.hash).not_to eq(second.hash)
|
14
14
|
end
|
15
|
+
|
15
16
|
it 'are not equal' do
|
16
17
|
expect(first).not_to eq(second)
|
17
18
|
end
|
19
|
+
|
18
20
|
it 'sort correctly' do
|
19
21
|
expect(first <=> second).to be < 0
|
20
22
|
end
|
23
|
+
|
21
24
|
it 'does not match using eql?' do
|
22
25
|
expect(first).not_to eql(second)
|
23
|
-
expect(second).not_to eql(first)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -96,52 +98,46 @@ RSpec.describe Reek::Smells::SmellWarning do
|
|
96
98
|
end
|
97
99
|
|
98
100
|
context '#yaml_hash' do
|
99
|
-
let(:class) { 'FeatureEnvy' }
|
100
101
|
let(:context_name) { 'Module::Class#method/block' }
|
101
102
|
let(:lines) { [24, 513] }
|
102
103
|
let(:message) { 'test message' }
|
104
|
+
let(:detector) { Reek::Smells::FeatureEnvy.new }
|
105
|
+
let(:parameters) { { 'one' => 34, 'two' => 'second' } }
|
106
|
+
let(:smell_type) { 'FeatureEnvy' }
|
107
|
+
let(:source) { 'a/ruby/source/file.rb' }
|
108
|
+
|
109
|
+
let(:yaml) do
|
110
|
+
warning = described_class.new(detector, source: source,
|
111
|
+
context: context_name,
|
112
|
+
lines: lines,
|
113
|
+
message: message,
|
114
|
+
parameters: parameters)
|
115
|
+
warning.yaml_hash
|
116
|
+
end
|
103
117
|
|
104
|
-
|
105
|
-
|
106
|
-
expect(yaml['smell_type']).to eq 'FeatureEnvy'
|
107
|
-
end
|
108
|
-
it 'includes the context' do
|
109
|
-
expect(yaml['context']).to eq context_name
|
110
|
-
end
|
111
|
-
it 'includes the message' do
|
112
|
-
expect(yaml['message']).to eq message
|
113
|
-
end
|
114
|
-
it 'includes the line numbers' do
|
115
|
-
expect(yaml['lines']).to match_array lines
|
116
|
-
end
|
118
|
+
it 'includes the smell type' do
|
119
|
+
expect(yaml['smell_type']).to eq 'FeatureEnvy'
|
117
120
|
end
|
118
121
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
let(:smell_type) { 'FeatureEnvy' }
|
123
|
-
let(:source) { 'a/ruby/source/file.rb' }
|
124
|
-
let(:yaml) do
|
125
|
-
warning = Reek::Smells::SmellWarning.new(detector, source: source,
|
126
|
-
context: context_name,
|
127
|
-
lines: lines,
|
128
|
-
message: message,
|
129
|
-
parameters: parameters)
|
130
|
-
warning.yaml_hash
|
131
|
-
end
|
122
|
+
it 'includes the context' do
|
123
|
+
expect(yaml['context']).to eq context_name
|
124
|
+
end
|
132
125
|
|
133
|
-
|
126
|
+
it 'includes the message' do
|
127
|
+
expect(yaml['message']).to eq message
|
128
|
+
end
|
134
129
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
130
|
+
it 'includes the line numbers' do
|
131
|
+
expect(yaml['lines']).to match_array lines
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'includes the source' do
|
135
|
+
expect(yaml['source']).to eq source
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'includes the parameters' do
|
139
|
+
parameters.each do |key, value|
|
140
|
+
expect(yaml[key]).to eq value
|
145
141
|
end
|
146
142
|
end
|
147
143
|
end
|
@@ -33,7 +33,7 @@ RSpec.describe Reek::Smells::SubclassedFromCoreClass do
|
|
33
33
|
end
|
34
34
|
EOS
|
35
35
|
|
36
|
-
expect(src).
|
36
|
+
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'does not report on coincidental core class names in other namespaces' do
|
@@ -42,7 +42,7 @@ RSpec.describe Reek::Smells::SubclassedFromCoreClass do
|
|
42
42
|
end
|
43
43
|
EOS
|
44
44
|
|
45
|
-
expect(src).
|
45
|
+
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'reports if we inherit from a core class using Class#new' do
|
@@ -67,16 +67,16 @@ RSpec.describe Reek::Smells::SubclassedFromCoreClass do
|
|
67
67
|
|
68
68
|
it 'does not report class which inherits from allowed class via Class.new' do
|
69
69
|
src = 'Alfa = Class.new(StandardError)'
|
70
|
-
expect(src).
|
70
|
+
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'does not report classes created with Struct.new' do
|
74
74
|
src = "Alfa = Struct.new('Array')"
|
75
|
-
expect(src).
|
75
|
+
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'does not report class created by another class constructor taking a core class as argument' do
|
79
79
|
src = 'Charlie = Delta.new(Array)'
|
80
|
-
expect(src).
|
80
|
+
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
81
81
|
end
|
82
82
|
end
|
@@ -21,7 +21,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
21
21
|
count: 3).with_config(config)
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'does not report for non-excessive constants' do
|
25
25
|
src = <<-EOS
|
26
26
|
class Alfa
|
27
27
|
Bravo = Charlie = 1
|
@@ -31,7 +31,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
31
31
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
32
32
|
end
|
33
33
|
|
34
|
-
it '
|
34
|
+
it 'does not report when increasing default' do
|
35
35
|
src = <<-EOS
|
36
36
|
# :reek:TooManyConstants: { max_constants: 3 }
|
37
37
|
class Alfa
|
@@ -42,7 +42,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
42
42
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
45
|
+
it 'does not report when disabled' do
|
46
46
|
src = <<-EOS
|
47
47
|
# :reek:TooManyConstants: { enabled: false }
|
48
48
|
class Alfa
|
@@ -53,7 +53,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
53
53
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'does not account class definition' do
|
57
57
|
src = <<-EOS
|
58
58
|
class Alfa
|
59
59
|
Bravo = Charlie = 1
|
@@ -64,7 +64,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
64
64
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
65
65
|
end
|
66
66
|
|
67
|
-
it '
|
67
|
+
it 'does not account struct definition' do
|
68
68
|
src = <<-EOS
|
69
69
|
class Alfa
|
70
70
|
Bravo = Charlie = 1
|
@@ -72,10 +72,10 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
72
72
|
end
|
73
73
|
EOS
|
74
74
|
|
75
|
-
expect(src).
|
75
|
+
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
76
76
|
end
|
77
77
|
|
78
|
-
it '
|
78
|
+
it 'counts each constant only once' do
|
79
79
|
src = <<-EOS
|
80
80
|
class Alfa
|
81
81
|
Bravo = Charlie = 1
|
@@ -93,7 +93,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
93
93
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
94
94
|
end
|
95
95
|
|
96
|
-
it '
|
96
|
+
it 'does not report outer module when inner module suppressed' do
|
97
97
|
src = <<-EOS
|
98
98
|
module Alfa
|
99
99
|
# ignore :reek:TooManyConstants:
|
@@ -106,7 +106,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
106
106
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
107
107
|
end
|
108
108
|
|
109
|
-
it '
|
109
|
+
it 'counts each constant only once for each namespace' do
|
110
110
|
src = <<-EOS
|
111
111
|
module Alfa
|
112
112
|
Bravo = Charlie = 1
|
@@ -120,7 +120,7 @@ RSpec.describe Reek::Smells::TooManyConstants do
|
|
120
120
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
121
121
|
end
|
122
122
|
|
123
|
-
it '
|
123
|
+
it 'reports for excessive constants inside a module' do
|
124
124
|
src = <<-EOS
|
125
125
|
module Alfa
|
126
126
|
Bravo = Charlie = Delta = 1
|