reek 4.4.0 → 4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +41 -4
- data/README.md +15 -3
- data/defaults.reek +1 -1
- data/docs/Basic-Smell-Options.md +2 -2
- data/docs/Code-Smells.md +4 -0
- data/docs/How-To-Write-New-Detectors.md +116 -0
- data/docs/How-reek-works-internally.md +3 -4
- data/docs/Instance-Variable-Assumption.md +134 -0
- data/docs/Simulated-Polymorphism.md +1 -1
- data/docs/Smell-Suppression.md +6 -6
- data/docs/{style-guide.md → Style-Guide.md} +0 -0
- data/docs/Unused-Private-Method.md +1 -1
- data/docs/YAML-Reports.md +0 -18
- data/features/configuration_files/directory_specific_directives.feature +4 -4
- data/features/configuration_files/unused_private_method.feature +2 -2
- data/features/samples.feature +122 -117
- data/features/smells/subclassed_from_core_class.feature +1 -1
- data/lib/reek/code_comment.rb +13 -4
- data/lib/reek/context/code_context.rb +1 -0
- data/lib/reek/examiner.rb +24 -27
- data/lib/reek/smells/class_variable.rb +1 -1
- data/lib/reek/smells/control_parameter.rb +1 -1
- data/lib/reek/smells/data_clump.rb +1 -1
- data/lib/reek/smells/duplicate_method_call.rb +1 -1
- data/lib/reek/smells/feature_envy.rb +1 -1
- data/lib/reek/smells/instance_variable_assumption.rb +1 -1
- data/lib/reek/smells/prima_donna_method.rb +1 -1
- data/lib/reek/smells/repeated_conditional.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +5 -14
- data/lib/reek/smells/smell_repository.rb +1 -5
- data/lib/reek/smells/smell_warning.rb +6 -8
- data/lib/reek/smells/subclassed_from_core_class.rb +1 -1
- data/lib/reek/smells/uncommunicative_variable_name.rb +22 -12
- data/lib/reek/smells/unused_private_method.rb +1 -1
- data/lib/reek/spec.rb +2 -2
- data/lib/reek/spec/should_reek_of.rb +12 -8
- data/lib/reek/version.rb +1 -1
- data/spec/reek/code_comment_spec.rb +13 -5
- data/spec/reek/examiner_spec.rb +2 -2
- data/spec/reek/smells/attribute_spec.rb +91 -78
- data/spec/reek/smells/boolean_parameter_spec.rb +72 -64
- data/spec/reek/smells/class_variable_spec.rb +81 -68
- data/spec/reek/smells/control_parameter_spec.rb +101 -141
- data/spec/reek/smells/data_clump_spec.rb +94 -149
- data/spec/reek/smells/duplicate_method_call_spec.rb +98 -85
- data/spec/reek/smells/feature_envy_spec.rb +164 -183
- data/spec/reek/smells/instance_variable_assumption_spec.rb +51 -147
- data/spec/reek/smells/irresponsible_module_spec.rb +153 -170
- data/spec/reek/smells/long_parameter_list_spec.rb +44 -88
- data/spec/reek/smells/long_yield_list_spec.rb +41 -41
- data/spec/reek/smells/manual_dispatch_spec.rb +36 -18
- data/spec/reek/smells/module_initialize_spec.rb +31 -33
- data/spec/reek/smells/nested_iterators_spec.rb +189 -183
- data/spec/reek/smells/nil_check_spec.rb +48 -37
- data/spec/reek/smells/prima_donna_method_spec.rb +41 -26
- data/spec/reek/smells/repeated_conditional_spec.rb +75 -87
- data/spec/reek/smells/smell_warning_spec.rb +7 -0
- data/spec/reek/smells/subclassed_from_core_class_spec.rb +37 -112
- data/spec/reek/smells/too_many_constants_spec.rb +109 -199
- data/spec/reek/smells/too_many_instance_variables_spec.rb +105 -128
- data/spec/reek/smells/too_many_methods_spec.rb +38 -62
- data/spec/reek/smells/too_many_statements_spec.rb +69 -45
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +16 -29
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +24 -37
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +55 -60
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +108 -95
- data/spec/reek/smells/unused_parameters_spec.rb +73 -49
- data/spec/reek/smells/unused_private_method_spec.rb +97 -50
- data/spec/reek/smells/utility_function_spec.rb +130 -188
- data/spec/reek/spec/should_reek_of_spec.rb +2 -2
- metadata +6 -7
- data/lib/reek/cli/warning_collector.rb +0 -27
- data/spec/reek/cli/warning_collector_spec.rb +0 -25
- data/spec/reek/smells/smell_detector_shared.rb +0 -29
@@ -1,88 +1,99 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_lib 'reek/context/code_context'
|
3
2
|
require_lib 'reek/smells/nil_check'
|
4
|
-
require_relative 'smell_detector_shared'
|
5
3
|
|
6
4
|
RSpec.describe Reek::Smells::NilCheck do
|
7
|
-
it 'reports
|
5
|
+
it 'reports the right values' do
|
8
6
|
src = <<-EOS
|
9
|
-
def
|
10
|
-
|
7
|
+
def alfa(bravo)
|
8
|
+
bravo.nil?
|
11
9
|
end
|
12
10
|
EOS
|
13
|
-
expect(src).to reek_of :NilCheck,
|
14
|
-
lines: [2],
|
15
|
-
message: 'performs a nil-check'
|
16
|
-
end
|
17
11
|
|
18
|
-
|
19
|
-
|
12
|
+
expect(src).to reek_of(:NilCheck,
|
13
|
+
lines: [2],
|
14
|
+
context: 'alfa',
|
15
|
+
message: 'performs a nil-check',
|
16
|
+
source: 'string')
|
20
17
|
end
|
21
18
|
|
22
|
-
it '
|
19
|
+
it 'does count all occurences' do
|
23
20
|
src = <<-EOS
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def alfa(bravo, charlie)
|
22
|
+
bravo.nil?
|
23
|
+
charlie.nil?
|
24
|
+
end
|
27
25
|
EOS
|
28
|
-
|
26
|
+
|
27
|
+
expect(src).to reek_of(:NilCheck,
|
28
|
+
lines: [2, 3],
|
29
|
+
context: 'alfa')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'reports nothing when scope includes no nil checks' do
|
33
|
+
expect('def alfa; end').not_to reek_of(:NilCheck)
|
29
34
|
end
|
30
35
|
|
31
36
|
it 'reports when scope uses == nil' do
|
32
37
|
src = <<-EOS
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
def alfa(bravo)
|
39
|
+
bravo == nil
|
40
|
+
end
|
36
41
|
EOS
|
42
|
+
|
37
43
|
expect(src).to reek_of(:NilCheck)
|
38
44
|
end
|
39
45
|
|
40
46
|
it 'reports when scope uses === nil' do
|
41
47
|
src = <<-EOS
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
def alfa(bravo)
|
49
|
+
bravo === nil
|
50
|
+
end
|
45
51
|
EOS
|
52
|
+
|
46
53
|
expect(src).to reek_of(:NilCheck)
|
47
54
|
end
|
48
55
|
|
49
56
|
it 'reports when scope uses nil ==' do
|
50
57
|
src = <<-EOS
|
51
|
-
|
52
|
-
|
53
|
-
|
58
|
+
def alfa(bravo)
|
59
|
+
nil == bravo
|
60
|
+
end
|
54
61
|
EOS
|
62
|
+
|
55
63
|
expect(src).to reek_of(:NilCheck)
|
56
64
|
end
|
57
65
|
|
58
66
|
it 'reports when scope uses a case-clause checking nil' do
|
59
67
|
src = <<-EOS
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
def alfa(bravo)
|
69
|
+
case bravo
|
70
|
+
when nil then puts "Nil"
|
71
|
+
end
|
63
72
|
end
|
64
|
-
end
|
65
73
|
EOS
|
74
|
+
|
66
75
|
expect(src).to reek_of(:NilCheck)
|
67
76
|
end
|
68
77
|
|
69
78
|
it 'reports when scope uses &.' do
|
70
79
|
src = <<-EOS
|
71
|
-
|
72
|
-
|
73
|
-
|
80
|
+
def alfa(bravo)
|
81
|
+
bravo&.charlie
|
82
|
+
end
|
74
83
|
EOS
|
84
|
+
|
75
85
|
expect(src).to reek_of(:NilCheck)
|
76
86
|
end
|
77
87
|
|
78
88
|
it 'reports all lines when scope uses multiple nilchecks' do
|
79
89
|
src = <<-EOS
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
90
|
+
def alfa(bravo)
|
91
|
+
bravo.nil?
|
92
|
+
@charlie === nil
|
93
|
+
delta&.echo
|
94
|
+
end
|
85
95
|
EOS
|
96
|
+
|
86
97
|
expect(src).to reek_of(:NilCheck, lines: [2, 3, 4])
|
87
98
|
end
|
88
99
|
end
|
@@ -1,38 +1,53 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_lib 'reek/
|
3
|
-
require_relative 'smell_detector_shared'
|
2
|
+
require_lib 'reek/smells/prima_donna_method'
|
4
3
|
|
5
4
|
RSpec.describe Reek::Smells::PrimaDonnaMethod do
|
6
5
|
it 'reports the right values' do
|
7
|
-
src =
|
8
|
-
|
6
|
+
src = <<-EOS
|
7
|
+
class Alfa
|
8
|
+
def bravo!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
|
13
|
+
expect(src).to reek_of(:PrimaDonnaMethod,
|
14
|
+
lines: [1],
|
15
|
+
context: 'Alfa',
|
16
|
+
message: "has prima donna method 'bravo!'",
|
17
|
+
source: 'string',
|
18
|
+
name: :bravo!)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'does count all occurences' do
|
22
|
+
src = <<-EOS
|
23
|
+
class Alfa
|
24
|
+
def bravo!
|
25
|
+
end
|
26
|
+
|
27
|
+
def charlie!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
EOS
|
31
|
+
|
32
|
+
expect(src).to reek_of(:PrimaDonnaMethod,
|
33
|
+
lines: [1],
|
34
|
+
name: :bravo!)
|
35
|
+
expect(src).to reek_of(:PrimaDonnaMethod,
|
9
36
|
lines: [1],
|
10
|
-
|
11
|
-
name: :m!
|
37
|
+
name: :charlie!)
|
12
38
|
end
|
13
39
|
|
14
40
|
it 'should report nothing when method and bang counterpart exist' do
|
15
|
-
|
16
|
-
|
41
|
+
src = <<-EOS
|
42
|
+
class Alfa
|
43
|
+
def bravo
|
44
|
+
end
|
17
45
|
|
18
|
-
|
19
|
-
|
20
|
-
|
46
|
+
def bravo!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
EOS
|
21
50
|
|
22
|
-
|
23
|
-
let(:detector) { build(:smell_detector, smell_type: :PrimaDonnaMethod) }
|
24
|
-
let(:src) { 'class C; def m!; end; end' }
|
25
|
-
let(:ctx) do
|
26
|
-
Reek::Context::ModuleContext.new(nil,
|
27
|
-
Reek::Source::SourceCode.from(src).syntax_tree)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should be reported' do
|
31
|
-
smells = detector.sniff(ctx)
|
32
|
-
warning = smells[0]
|
33
|
-
|
34
|
-
expect(warning.smell_type).to eq('PrimaDonnaMethod')
|
35
|
-
expect(warning.lines).to eq([1])
|
36
|
-
end
|
51
|
+
expect(src).not_to reek_of(:PrimaDonnaMethod)
|
37
52
|
end
|
38
53
|
end
|
@@ -1,112 +1,100 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
require_lib 'reek/smells/repeated_conditional'
|
3
|
-
require_lib 'reek/context/code_context'
|
4
|
-
require_relative 'smell_detector_shared'
|
5
|
-
require_lib 'reek/source/source_code'
|
6
3
|
|
7
4
|
RSpec.describe Reek::Smells::RepeatedConditional do
|
8
|
-
|
5
|
+
it 'reports the right values' do
|
6
|
+
src = <<-EOS
|
7
|
+
class Alfa
|
8
|
+
attr_accessor :bravo
|
9
9
|
|
10
|
-
|
10
|
+
def charlie
|
11
|
+
puts "Repeat 1!" if bravo
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ctx = Reek::Context::CodeContext.new(nil, ast)
|
16
|
-
expect(detector.conditional_counts(ctx).length).to eq(0)
|
17
|
-
end
|
18
|
-
end
|
14
|
+
def delta
|
15
|
+
puts "Repeat 2!" if bravo
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def echo
|
19
|
+
puts "Repeat 3!" if bravo
|
20
|
+
end
|
21
|
+
end
|
22
|
+
EOS
|
23
|
+
|
24
|
+
expect(src).to reek_of(:RepeatedConditional,
|
25
|
+
lines: [5, 9, 13],
|
26
|
+
context: 'Alfa',
|
27
|
+
message: "tests 'bravo' at least 3 times",
|
28
|
+
source: 'string',
|
29
|
+
name: 'bravo',
|
30
|
+
count: 3)
|
26
31
|
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
expect(detector.conditional_counts(ctx).length).to eq(0)
|
33
|
-
end
|
34
|
-
end
|
33
|
+
it 'does count all occurences' do
|
34
|
+
src = <<-EOS
|
35
|
+
class Alfa
|
36
|
+
attr_accessor :bravo
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def charlie
|
39
|
+
puts "Repeat 1!" if bravo
|
40
|
+
puts "And again!" if bravo
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
class Scrunch
|
43
|
-
def first
|
44
|
-
puts "hello" if @debug
|
45
|
-
return #{cond} ? 0 : 3;
|
46
|
-
end
|
47
|
-
def second
|
48
|
-
if #{cond}
|
49
|
-
@other += " quarts"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
def third
|
53
|
-
raise 'flu!' unless #{cond}
|
54
|
-
end
|
43
|
+
def delta
|
44
|
+
puts "Repeat 2!" if bravo
|
55
45
|
end
|
56
|
-
EOS
|
57
46
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
def echo
|
48
|
+
puts "Repeat 3!" if bravo
|
49
|
+
end
|
50
|
+
end
|
51
|
+
EOS
|
62
52
|
|
63
|
-
|
64
|
-
|
65
|
-
|
53
|
+
expect(src).to reek_of(:RepeatedConditional,
|
54
|
+
lines: [5, 6, 10, 14],
|
55
|
+
count: 4)
|
56
|
+
end
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
|
58
|
+
it 'does not report two repeated conditionals' do
|
59
|
+
src = <<-EOS
|
60
|
+
class Alfa
|
61
|
+
attr_accessor :bravo
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
def charlie
|
64
|
+
puts "Repeat 1!" if bravo
|
65
|
+
end
|
66
|
+
|
67
|
+
def delta
|
68
|
+
puts "Repeat 2!" if bravo
|
69
|
+
end
|
70
|
+
end
|
71
|
+
EOS
|
72
|
+
|
73
|
+
expect(src).not_to reek_of(:RepeatedConditional)
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
it 'reports repeated conditionals regardless of `if` or `case` statements' do
|
77
|
+
src = <<-EOS
|
78
|
+
class Alfa
|
79
|
+
attr_accessor :bravo
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
class Scrunch
|
83
|
-
def alpha
|
84
|
-
return #{cond} ? 0 : 2;
|
85
|
-
end
|
86
|
-
def beta
|
87
|
-
case #{cond}
|
88
|
-
when :symbol
|
89
|
-
@tother += " pints"
|
90
|
-
end
|
91
|
-
end
|
81
|
+
def charlie
|
82
|
+
puts "Repeat 1!" if bravo
|
92
83
|
end
|
93
|
-
EOS
|
94
|
-
|
95
|
-
ast = Reek::Source::SourceCode.from(src).syntax_tree
|
96
|
-
ctx = Reek::Context::CodeContext.new(nil, ast)
|
97
|
-
detector.conditional_counts(ctx)
|
98
|
-
end
|
99
84
|
|
100
|
-
|
101
|
-
|
102
|
-
|
85
|
+
def delta
|
86
|
+
case bravo
|
87
|
+
when 1 then puts "Repeat 2!"
|
88
|
+
else 'nothing'
|
89
|
+
end
|
90
|
+
end
|
103
91
|
|
104
|
-
|
105
|
-
|
106
|
-
|
92
|
+
def echo
|
93
|
+
puts "Repeat 3!" if bravo
|
94
|
+
end
|
95
|
+
end
|
96
|
+
EOS
|
107
97
|
|
108
|
-
|
109
|
-
expect(conds.values[0].length).to eq(2)
|
110
|
-
end
|
98
|
+
expect(src).to reek_of(:RepeatedConditional)
|
111
99
|
end
|
112
100
|
end
|
@@ -31,6 +31,13 @@ RSpec.describe Reek::Smells::SmellWarning do
|
|
31
31
|
it_should_behave_like 'first sorts ahead of second'
|
32
32
|
end
|
33
33
|
|
34
|
+
context 'smells differing only by lines' do
|
35
|
+
let(:first) { build(:smell_warning, smell_detector: feature_envy_detector, lines: [2]) }
|
36
|
+
let(:second) { build(:smell_warning, smell_detector: feature_envy_detector, lines: [3]) }
|
37
|
+
|
38
|
+
it_should_behave_like 'first sorts ahead of second'
|
39
|
+
end
|
40
|
+
|
34
41
|
context 'smells differing only by context' do
|
35
42
|
let(:first) { build(:smell_warning, smell_detector: duplication_detector, context: 'first') }
|
36
43
|
let(:second) do
|
@@ -1,157 +1,82 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
require_lib 'reek/smells/subclassed_from_core_class'
|
3
|
-
require_relative 'smell_detector_shared'
|
4
3
|
|
5
4
|
RSpec.describe Reek::Smells::SubclassedFromCoreClass do
|
6
|
-
|
7
|
-
|
8
|
-
it_should_behave_like 'SmellDetector'
|
9
|
-
|
10
|
-
context 'report' do
|
11
|
-
context 'smell line' do
|
12
|
-
context 'single class' do
|
13
|
-
it 'should report the core class in the message' do
|
14
|
-
src = <<-EOS
|
15
|
-
class Dummy < Hash
|
16
|
-
end
|
17
|
-
EOS
|
18
|
-
|
19
|
-
expect(src).to reek_of(:SubclassedFromCoreClass, lines: [1])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'class inside a module' do
|
24
|
-
it 'should report the core class in the message' do
|
25
|
-
src = <<-EOS
|
26
|
-
module Namespace
|
27
|
-
class Dummy < Hash
|
28
|
-
end
|
29
|
-
end
|
30
|
-
EOS
|
31
|
-
|
32
|
-
expect(src).to reek_of(:SubclassedFromCoreClass, lines: [2])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'smell message' do
|
38
|
-
context 'Array' do
|
39
|
-
it 'should report the core class in the message' do
|
40
|
-
src = <<-EOS
|
41
|
-
class Dummy < Array
|
42
|
-
end
|
43
|
-
EOS
|
44
|
-
|
45
|
-
expect(src).to reek_of(:SubclassedFromCoreClass, message: 'inherits from a core class (Array)')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'Hash' do
|
50
|
-
it 'should report the core class in the message' do
|
51
|
-
src = <<-EOS
|
52
|
-
class Dummy < Hash
|
53
|
-
end
|
54
|
-
EOS
|
55
|
-
|
56
|
-
expect(src).to reek_of(:SubclassedFromCoreClass, message: 'inherits from a core class (Hash)')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does not inherit from a core class' do
|
5
|
+
it 'reports the right values' do
|
63
6
|
src = <<-EOS
|
64
|
-
class
|
7
|
+
class Alfa < Hash
|
65
8
|
end
|
66
9
|
EOS
|
67
10
|
|
68
|
-
expect(src).
|
11
|
+
expect(src).to reek_of(:SubclassedFromCoreClass,
|
12
|
+
lines: [1],
|
13
|
+
context: 'Alfa',
|
14
|
+
message: "inherits from core class 'Hash'",
|
15
|
+
source: 'string',
|
16
|
+
ancestor: 'Hash')
|
69
17
|
end
|
70
18
|
|
71
|
-
it '
|
19
|
+
it 'reports when inheriting from a core class inside a module' do
|
72
20
|
src = <<-EOS
|
73
|
-
|
21
|
+
module Alfa
|
22
|
+
class Bravo < Hash
|
23
|
+
end
|
74
24
|
end
|
75
25
|
EOS
|
76
26
|
|
77
|
-
expect(src).to reek_of(:SubclassedFromCoreClass,
|
27
|
+
expect(src).to reek_of(:SubclassedFromCoreClass, context: 'Alfa::Bravo')
|
78
28
|
end
|
79
29
|
|
80
|
-
it '
|
30
|
+
it 'does not report when not inheriting from a core class' do
|
81
31
|
src = <<-EOS
|
82
|
-
class
|
32
|
+
class Alfa
|
83
33
|
end
|
84
34
|
EOS
|
35
|
+
|
85
36
|
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
86
37
|
end
|
87
38
|
|
88
|
-
it '
|
39
|
+
it 'does not report on coincidental core class names in other namespaces' do
|
89
40
|
src = <<-EOS
|
90
|
-
|
91
|
-
class Dummy < Array
|
92
|
-
end
|
41
|
+
class Alfa < Bravo::Array
|
93
42
|
end
|
94
43
|
EOS
|
95
|
-
|
44
|
+
|
45
|
+
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
96
46
|
end
|
97
47
|
|
98
|
-
it '
|
99
|
-
src = '
|
100
|
-
expect(src).to reek_of(:SubclassedFromCoreClass
|
48
|
+
it 'reports if we inherit from a core class using Class#new' do
|
49
|
+
src = 'Alfa = Class.new(Array)'
|
50
|
+
expect(src).to reek_of(:SubclassedFromCoreClass)
|
101
51
|
end
|
102
52
|
|
103
|
-
it '
|
53
|
+
it 'reports if inner class inherit from a core class' do
|
104
54
|
src = <<-EOS
|
105
|
-
|
106
|
-
|
107
|
-
Dummiest = Class.new(Array)
|
108
|
-
end
|
55
|
+
class Alfa
|
56
|
+
Bravo = Class.new(Array)
|
109
57
|
end
|
110
58
|
EOS
|
111
|
-
|
59
|
+
|
60
|
+
expect(src).to reek_of(:SubclassedFromCoreClass, context: 'Alfa::Bravo')
|
112
61
|
end
|
113
62
|
|
114
|
-
it '
|
115
|
-
src =
|
116
|
-
|
117
|
-
class Dummy
|
118
|
-
Dummiest = Class.new(My::Array)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
EOS
|
122
|
-
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
63
|
+
it 'reports class which inherits from core class via Class.new' do
|
64
|
+
src = 'Alfa = Class.new(Array)'
|
65
|
+
expect(src).to reek_of(:SubclassedFromCoreClass)
|
123
66
|
end
|
124
67
|
|
125
|
-
it '
|
126
|
-
src =
|
127
|
-
module Namespace
|
128
|
-
class Dummy
|
129
|
-
Dummiest = Class.new(StandardError)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
EOS
|
68
|
+
it 'does not report class which inherits from allowed class via Class.new' do
|
69
|
+
src = 'Alfa = Class.new(StandardError)'
|
133
70
|
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
134
71
|
end
|
135
72
|
|
136
|
-
it '
|
137
|
-
src =
|
138
|
-
module Namespace
|
139
|
-
class Dummy
|
140
|
-
Dummiest = Struct.new('Array')
|
141
|
-
end
|
142
|
-
end
|
143
|
-
EOS
|
73
|
+
it 'does not report classes created with Struct.new' do
|
74
|
+
src = "Alfa = Struct.new('Array')"
|
144
75
|
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
145
76
|
end
|
146
77
|
|
147
|
-
it '
|
148
|
-
src =
|
149
|
-
module Namespace
|
150
|
-
class Dummy
|
151
|
-
Dummiest = Foo.new(Array)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
EOS
|
78
|
+
it 'does not report class created by another class constructor taking a core class as argument' do
|
79
|
+
src = 'Charlie = Delta.new(Array)'
|
155
80
|
expect(src).to_not reek_of(:SubclassedFromCoreClass)
|
156
81
|
end
|
157
82
|
end
|