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
@@ -13,7 +13,7 @@ RSpec.describe Reek::Report::TextReport do
|
|
13
13
|
heading_formatter: Reek::Report::HeadingFormatter::Quiet
|
14
14
|
}
|
15
15
|
end
|
16
|
-
let(:instance) {
|
16
|
+
let(:instance) { described_class.new report_options }
|
17
17
|
|
18
18
|
context 'with a single empty source' do
|
19
19
|
before do
|
@@ -21,7 +21,7 @@ RSpec.describe Reek::Report::TextReport do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'has an empty quiet_report' do
|
24
|
-
expect { instance.show }.
|
24
|
+
expect { instance.show }.not_to output.to_stdout
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -32,7 +32,7 @@ RSpec.describe Reek::Report::TextReport do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with colors disabled' do
|
35
|
-
before
|
35
|
+
before do
|
36
36
|
Rainbow.enabled = false
|
37
37
|
end
|
38
38
|
|
@@ -42,7 +42,7 @@ RSpec.describe Reek::Report::TextReport do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'with colors enabled' do
|
45
|
-
before
|
45
|
+
before do
|
46
46
|
Rainbow.enabled = true
|
47
47
|
end
|
48
48
|
|
@@ -67,9 +67,13 @@ RSpec.describe Reek::Report::TextReport do
|
|
67
67
|
expect { instance.show }.to output(/string -- 2 warnings/).to_stdout
|
68
68
|
end
|
69
69
|
|
70
|
-
it '
|
71
|
-
|
72
|
-
expect { instance.show }.to output(
|
70
|
+
it 'mentions every smell name' do
|
71
|
+
matcher = match(/UncommunicativeParameterName/).and match(/UtilityFunction/)
|
72
|
+
expect { instance.show }.to output(matcher).to_stdout
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'shows total number of warnings' do
|
76
|
+
expect { instance.show }.to output(/4 total warnings\n\Z/).to_stdout
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
@@ -83,7 +87,7 @@ RSpec.describe Reek::Report::TextReport do
|
|
83
87
|
to output(/\A\e\[36mstring -- \e\[0m\e\[33m2 warning\e\[0m\e\[33ms\e\[0m/).to_stdout
|
84
88
|
end
|
85
89
|
|
86
|
-
it '
|
90
|
+
it 'shows total number of warnings in color' do
|
87
91
|
expect { instance.show }.
|
88
92
|
to output(/\e\[31m4 total warnings\n\e\[0m\Z/).to_stdout
|
89
93
|
end
|
@@ -3,7 +3,7 @@ require_lib 'reek/examiner'
|
|
3
3
|
require_lib 'reek/report/report'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Report::XMLReport do
|
6
|
-
let(:xml_report) {
|
6
|
+
let(:xml_report) { described_class.new }
|
7
7
|
|
8
8
|
context 'empty source' do
|
9
9
|
it 'prints empty checkstyle XML' do
|
@@ -8,7 +8,7 @@ require 'stringio'
|
|
8
8
|
|
9
9
|
RSpec.describe Reek::Report::YAMLReport do
|
10
10
|
let(:options) { {} }
|
11
|
-
let(:instance) {
|
11
|
+
let(:instance) { described_class.new(options) }
|
12
12
|
let(:examiner) { Reek::Examiner.new(source) }
|
13
13
|
|
14
14
|
before do
|
data/spec/reek/report_spec.rb
CHANGED
@@ -4,25 +4,25 @@ require_lib 'reek/report'
|
|
4
4
|
RSpec.describe Reek::Report do
|
5
5
|
describe '.report_class' do
|
6
6
|
it 'returns the correct class' do
|
7
|
-
expect(
|
7
|
+
expect(described_class.report_class(:text)).to eq Reek::Report::TextReport
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '.location_formatter' do
|
12
12
|
it 'returns the correct class' do
|
13
|
-
expect(
|
13
|
+
expect(described_class.location_formatter(:plain)).to eq Reek::Report::BlankLocationFormatter
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '.heading_formatter' do
|
18
18
|
it 'returns the correct class' do
|
19
|
-
expect(
|
19
|
+
expect(described_class.heading_formatter(:quiet)).to eq Reek::Report::HeadingFormatter::Quiet
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '.warning_formatter_class' do
|
24
24
|
it 'returns the correct class' do
|
25
|
-
expect(
|
25
|
+
expect(described_class.warning_formatter_class(:simple)).to eq Reek::Report::SimpleWarningFormatter
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -23,12 +23,9 @@ RSpec.describe Reek::Smells::Attribute do
|
|
23
23
|
end
|
24
24
|
EOS
|
25
25
|
|
26
|
-
expect(src).
|
27
|
-
|
28
|
-
|
29
|
-
expect(src).to reek_of(:Attribute,
|
30
|
-
lines: [3],
|
31
|
-
context: 'Alfa#charlie')
|
26
|
+
expect(src).
|
27
|
+
to reek_of(:Attribute, lines: [2], context: 'Alfa#bravo').
|
28
|
+
and reek_of(:Attribute, lines: [3], context: 'Alfa#charlie')
|
32
29
|
end
|
33
30
|
|
34
31
|
it 'records nothing with no attributes' do
|
@@ -37,7 +34,7 @@ RSpec.describe Reek::Smells::Attribute do
|
|
37
34
|
end
|
38
35
|
EOS
|
39
36
|
|
40
|
-
expect(src).
|
37
|
+
expect(src).not_to reek_of(:Attribute)
|
41
38
|
end
|
42
39
|
|
43
40
|
context 'with attributes' do
|
@@ -49,7 +46,7 @@ RSpec.describe Reek::Smells::Attribute do
|
|
49
46
|
end
|
50
47
|
EOS
|
51
48
|
|
52
|
-
expect(src).
|
49
|
+
expect(src).not_to reek_of(:Attribute)
|
53
50
|
end
|
54
51
|
|
55
52
|
it 'records writer attribute' do
|
@@ -115,7 +112,7 @@ RSpec.describe Reek::Smells::Attribute do
|
|
115
112
|
end
|
116
113
|
EOS
|
117
114
|
|
118
|
-
expect(src).
|
115
|
+
expect(src).not_to reek_of(:Attribute)
|
119
116
|
end
|
120
117
|
|
121
118
|
it "doesn't record private attributes" do
|
@@ -130,7 +127,7 @@ RSpec.describe Reek::Smells::Attribute do
|
|
130
127
|
end
|
131
128
|
EOS
|
132
129
|
|
133
|
-
expect(src).
|
130
|
+
expect(src).not_to reek_of(:Attribute)
|
134
131
|
end
|
135
132
|
|
136
133
|
it 'records attr_writer defined in public section' do
|
@@ -22,14 +22,9 @@ RSpec.describe Reek::Smells::BooleanParameter do
|
|
22
22
|
end
|
23
23
|
EOS
|
24
24
|
|
25
|
-
expect(src).
|
26
|
-
|
27
|
-
|
28
|
-
parameter: 'bravo')
|
29
|
-
expect(src).to reek_of(:BooleanParameter,
|
30
|
-
lines: [1],
|
31
|
-
context: 'alfa',
|
32
|
-
parameter: 'charlie')
|
25
|
+
expect(src).
|
26
|
+
to reek_of(:BooleanParameter, lines: [1], context: 'alfa', parameter: 'bravo').
|
27
|
+
and reek_of(:BooleanParameter, lines: [1], context: 'alfa', parameter: 'charlie')
|
33
28
|
end
|
34
29
|
|
35
30
|
context 'in a method' do
|
@@ -41,17 +36,17 @@ RSpec.describe Reek::Smells::BooleanParameter do
|
|
41
36
|
it 'reports two parameters defaulted to booleans in a mixed parameter list' do
|
42
37
|
src = 'def alfa(bravo, charlie = true, delta = false, &echo) end'
|
43
38
|
|
44
|
-
expect(src).to reek_of(:BooleanParameter, parameter: 'charlie')
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
expect(src).not_to reek_of(:BooleanParameter, parameter: 'echo')
|
39
|
+
expect(src).to reek_of(:BooleanParameter, parameter: 'charlie').
|
40
|
+
and reek_of(:BooleanParameter, parameter: 'delta').
|
41
|
+
and not_reek_of(:BooleanParameter, parameter: 'bravo').
|
42
|
+
and not_reek_of(:BooleanParameter, parameter: 'echo')
|
49
43
|
end
|
50
44
|
|
51
45
|
it 'reports keyword parameters defaulted to booleans' do
|
52
46
|
src = 'def alfa(bravo: true, charlie: false) end'
|
53
|
-
expect(src).
|
54
|
-
|
47
|
+
expect(src).
|
48
|
+
to reek_of(:BooleanParameter, parameter: 'bravo').
|
49
|
+
and reek_of(:BooleanParameter, parameter: 'charlie')
|
55
50
|
end
|
56
51
|
|
57
52
|
it 'does not report regular parameters' do
|
@@ -89,11 +84,10 @@ RSpec.describe Reek::Smells::BooleanParameter do
|
|
89
84
|
it 'reports two parameters defaulted to booleans' do
|
90
85
|
src = 'def self.alfa(bravo, charlie = true, delta = false, &echo) end'
|
91
86
|
|
92
|
-
expect(src).to reek_of(:BooleanParameter, parameter: 'charlie')
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
expect(src).not_to reek_of(:BooleanParameter, parameter: 'echo')
|
87
|
+
expect(src).to reek_of(:BooleanParameter, parameter: 'charlie').
|
88
|
+
and reek_of(:BooleanParameter, parameter: 'delta').
|
89
|
+
and not_reek_of(:BooleanParameter, parameter: 'bravo').
|
90
|
+
and not_reek_of(:BooleanParameter, parameter: 'echo')
|
97
91
|
end
|
98
92
|
end
|
99
93
|
end
|
@@ -25,8 +25,9 @@ RSpec.describe Reek::Smells::ClassVariable do
|
|
25
25
|
end
|
26
26
|
EOS
|
27
27
|
|
28
|
-
expect(src).
|
29
|
-
|
28
|
+
expect(src).
|
29
|
+
to reek_of(:ClassVariable, name: '@@bravo').
|
30
|
+
and reek_of(:ClassVariable, name: '@@charlie')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'does not report class instance variables' do
|
@@ -36,7 +37,7 @@ RSpec.describe Reek::Smells::ClassVariable do
|
|
36
37
|
end
|
37
38
|
EOS
|
38
39
|
|
39
|
-
expect(src).
|
40
|
+
expect(src).not_to reek_of(:ClassVariable)
|
40
41
|
end
|
41
42
|
|
42
43
|
context 'with no class variables' do
|
@@ -47,7 +48,7 @@ RSpec.describe Reek::Smells::ClassVariable do
|
|
47
48
|
end
|
48
49
|
EOS
|
49
50
|
|
50
|
-
expect(src).
|
51
|
+
expect(src).not_to reek_of(:ClassVariable)
|
51
52
|
end
|
52
53
|
|
53
54
|
it 'records nothing in the module' do
|
@@ -57,7 +58,7 @@ RSpec.describe Reek::Smells::ClassVariable do
|
|
57
58
|
end
|
58
59
|
EOS
|
59
60
|
|
60
|
-
expect(src).
|
61
|
+
expect(src).not_to reek_of(:ClassVariable)
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
@@ -25,8 +25,9 @@ RSpec.describe Reek::Smells::ControlParameter do
|
|
25
25
|
end
|
26
26
|
EOS
|
27
27
|
|
28
|
-
expect(src).
|
29
|
-
|
28
|
+
expect(src).
|
29
|
+
to reek_of(:ControlParameter, lines: [2], argument: 'bravo').
|
30
|
+
and reek_of(:ControlParameter, lines: [3], argument: 'charlie')
|
30
31
|
end
|
31
32
|
|
32
33
|
context 'parameter not used to determine code path' do
|
@@ -33,12 +33,9 @@ RSpec.describe Reek::Smells::DataClump do
|
|
33
33
|
end
|
34
34
|
EOS
|
35
35
|
|
36
|
-
expect(src).
|
37
|
-
|
38
|
-
|
39
|
-
expect(src).to reek_of(:DataClump,
|
40
|
-
lines: [6, 7, 8],
|
41
|
-
parameters: ['juliett', 'kilo'])
|
36
|
+
expect(src).
|
37
|
+
to reek_of(:DataClump, lines: [2, 3, 4], parameters: ['echo', 'foxtrot']).
|
38
|
+
and reek_of(:DataClump, lines: [6, 7, 8], parameters: ['juliett', 'kilo'])
|
42
39
|
end
|
43
40
|
|
44
41
|
%w(class module).each do |scope|
|
@@ -36,14 +36,9 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
|
|
36
36
|
end
|
37
37
|
EOS
|
38
38
|
|
39
|
-
expect(src).
|
40
|
-
|
41
|
-
|
42
|
-
count: 2)
|
43
|
-
expect(src).to reek_of(:DuplicateMethodCall,
|
44
|
-
lines: [8, 9],
|
45
|
-
name: 'foxtrot.golf',
|
46
|
-
count: 2)
|
39
|
+
expect(src).
|
40
|
+
to reek_of(:DuplicateMethodCall, lines: [3, 4], name: 'charlie.delta', count: 2).
|
41
|
+
and reek_of(:DuplicateMethodCall, lines: [8, 9], name: 'foxtrot.golf', count: 2)
|
47
42
|
end
|
48
43
|
|
49
44
|
context 'with repeated method calls' do
|
@@ -57,13 +52,14 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
|
|
57
52
|
expect(src).to reek_of(:DuplicateMethodCall, name: '@bravo.charlie(2, 3)')
|
58
53
|
end
|
59
54
|
|
60
|
-
it '
|
55
|
+
it 'reports nested calls' do
|
61
56
|
src = 'def alfa; @bravo.charlie.delta + @bravo.charlie.delta; end'
|
62
|
-
expect(src).
|
63
|
-
|
57
|
+
expect(src).
|
58
|
+
to reek_of(:DuplicateMethodCall, name: '@bravo.charlie').
|
59
|
+
and reek_of(:DuplicateMethodCall, name: '@bravo.charlie.delta')
|
64
60
|
end
|
65
61
|
|
66
|
-
it '
|
62
|
+
it 'ignores calls to new' do
|
67
63
|
src = 'def alfa; @bravo.new + @bravo.new; end'
|
68
64
|
expect(src).not_to reek_of(:DuplicateMethodCall)
|
69
65
|
end
|
@@ -155,12 +151,12 @@ RSpec.describe Reek::Smells::DuplicateMethodCall do
|
|
155
151
|
end
|
156
152
|
|
157
153
|
context 'non-repeated method calls' do
|
158
|
-
it '
|
154
|
+
it 'does not report similar calls' do
|
159
155
|
src = 'def alfa(bravo) bravo.charlie == self.charlie end'
|
160
156
|
expect(src).not_to reek_of(:DuplicateMethodCall)
|
161
157
|
end
|
162
158
|
|
163
|
-
it '
|
159
|
+
it 'respects call parameters' do
|
164
160
|
src = 'def alfa; @bravo.charlie(3) + @bravo.charlie(2) end'
|
165
161
|
expect(src).not_to reek_of(:DuplicateMethodCall)
|
166
162
|
end
|
@@ -32,62 +32,69 @@ RSpec.describe Reek::Smells::FeatureEnvy do
|
|
32
32
|
end
|
33
33
|
EOS
|
34
34
|
|
35
|
-
expect(src).
|
36
|
-
|
37
|
-
|
38
|
-
expect(src).to reek_of(:FeatureEnvy,
|
39
|
-
lines: [7, 7],
|
40
|
-
name: 'hotel')
|
35
|
+
expect(src).
|
36
|
+
to reek_of(:FeatureEnvy, lines: [3, 3], name: 'charlie').
|
37
|
+
and reek_of(:FeatureEnvy, lines: [7, 7], name: 'hotel')
|
41
38
|
end
|
42
39
|
|
43
40
|
it 'does not report use of self' do
|
44
|
-
|
41
|
+
src = 'def alfa; self.to_s + self.to_i; end'
|
42
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
45
43
|
end
|
46
44
|
|
47
45
|
it 'does not report vcall with no argument' do
|
48
|
-
|
46
|
+
src = 'def alfa; bravo; end'
|
47
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'does not report single use' do
|
52
|
-
|
51
|
+
src = 'def alfa(bravo); bravo.charlie(@delta); end'
|
52
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'does not report return value' do
|
56
|
-
|
56
|
+
src = 'def alfa(bravo); bravo.charlie(@delta); bravo; end'
|
57
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
57
58
|
end
|
58
59
|
|
59
60
|
it 'does ignore global variables' do
|
60
|
-
|
61
|
+
src = 'def alfa; $bravo.to_a; $bravo[@charlie]; end'
|
62
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'does not report class methods' do
|
64
|
-
|
66
|
+
src = 'def alfa; self.class.bravo(self); end'
|
67
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
65
68
|
end
|
66
69
|
|
67
70
|
it 'does not report single use of an ivar' do
|
68
|
-
|
71
|
+
src = 'def alfa; @bravo.to_a; end'
|
72
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
69
73
|
end
|
70
74
|
|
71
75
|
it 'does not report returning an ivar' do
|
72
|
-
|
76
|
+
src = 'def alfa; @bravo.to_a; @bravo; end'
|
77
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
73
78
|
end
|
74
79
|
|
75
80
|
it 'does not report ivar usage in a parameter' do
|
76
|
-
|
77
|
-
|
81
|
+
src = 'def alfa; @bravo.charlie + delta(@bravo) - echo(@bravo) end'
|
82
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
78
83
|
end
|
79
84
|
|
80
85
|
it 'does not report single use of an lvar' do
|
81
|
-
|
86
|
+
src = 'def alfa; bravo = @charlie; bravo.to_a; end'
|
87
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
82
88
|
end
|
83
89
|
|
84
90
|
it 'does not report returning an lvar' do
|
85
|
-
|
91
|
+
src = 'def alfa; bravo = @charlie; bravo.to_a; lv end'
|
92
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
86
93
|
end
|
87
94
|
|
88
95
|
it 'ignores lvar usage in a parameter' do
|
89
|
-
|
90
|
-
|
96
|
+
src = 'def alfa; bravo = @item; bravo.charlie + delta(bravo) - echo(bravo); end'
|
97
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'ignores multiple ivars' do
|
@@ -115,11 +122,12 @@ RSpec.describe Reek::Smells::FeatureEnvy do
|
|
115
122
|
end
|
116
123
|
EOS
|
117
124
|
|
118
|
-
expect(src).
|
119
|
-
|
125
|
+
expect(src).
|
126
|
+
to reek_of(:FeatureEnvy, name: 'delta').
|
127
|
+
and not_reek_of(:FeatureEnvy, name: 'bravo')
|
120
128
|
end
|
121
129
|
|
122
|
-
it '
|
130
|
+
it 'reports multiple affinities' do
|
123
131
|
src = <<-EOS
|
124
132
|
def alfa
|
125
133
|
bravo = @charlie
|
@@ -129,8 +137,9 @@ RSpec.describe Reek::Smells::FeatureEnvy do
|
|
129
137
|
end
|
130
138
|
EOS
|
131
139
|
|
132
|
-
expect(src).
|
133
|
-
|
140
|
+
expect(src).
|
141
|
+
to reek_of(:FeatureEnvy, name: 'delta').
|
142
|
+
and reek_of(:FeatureEnvy, name: 'bravo')
|
134
143
|
end
|
135
144
|
|
136
145
|
it 'is not be fooled by duplication' do
|