reek 2.0.0 → 2.0.1
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 +5 -0
- data/README.md +13 -2
- data/Rakefile +2 -1
- data/features/command_line_interface/options.feature +2 -3
- data/features/command_line_interface/smell_selection.feature +0 -1
- data/features/command_line_interface/smells_count.feature +0 -2
- data/features/command_line_interface/stdin.feature +3 -10
- data/features/configuration_files/masking_smells.feature +1 -5
- data/features/configuration_files/overrides_defaults.feature +0 -1
- data/features/rake_task/rake_task.feature +1 -4
- data/features/reports/json.feature +73 -0
- data/features/reports/reports.feature +0 -3
- data/features/reports/yaml.feature +0 -1
- data/features/ruby_api/api.feature +0 -1
- data/features/samples.feature +0 -4
- data/features/step_definitions/reek_steps.rb +14 -4
- data/features/support/env.rb +3 -0
- data/lib/reek/cli/option_interpreter.rb +2 -0
- data/lib/reek/cli/options.rb +3 -3
- data/lib/reek/cli/report/formatter.rb +1 -1
- data/lib/reek/cli/report/location_formatter.rb +11 -0
- data/lib/reek/cli/report/report.rb +11 -2
- data/lib/reek/core/code_context.rb +49 -10
- data/lib/reek/core/sniffer.rb +2 -2
- data/lib/reek/core/{code_parser.rb → tree_walker.rb} +16 -7
- data/lib/reek/examiner.rb +0 -39
- data/lib/reek/smells.rb +3 -25
- data/lib/reek/smells/feature_envy.rb +0 -2
- data/lib/reek/smells/smell_detector.rb +0 -6
- data/lib/reek/source/sexp_extensions.rb +17 -6
- data/lib/reek/source/sexp_node.rb +1 -1
- data/lib/reek/spec.rb +66 -0
- data/lib/reek/spec/should_reek.rb +0 -6
- data/lib/reek/spec/should_reek_of.rb +0 -49
- data/lib/reek/spec/should_reek_only_of.rb +0 -11
- data/lib/reek/version.rb +6 -1
- data/reek.gemspec +3 -2
- data/spec/reek/cli/json_report_spec.rb +20 -0
- data/spec/reek/core/code_context_spec.rb +6 -0
- data/spec/reek/core/smell_configuration_spec.rb +3 -3
- data/spec/reek/core/{code_parser_spec.rb → tree_walker_spec.rb} +4 -4
- data/spec/reek/examiner_spec.rb +0 -19
- data/spec/reek/smells/attribute_spec.rb +6 -9
- data/spec/reek/smells/boolean_parameter_spec.rb +13 -15
- data/spec/reek/smells/class_variable_spec.rb +17 -17
- data/spec/reek/smells/control_parameter_spec.rb +44 -46
- data/spec/reek/smells/data_clump_spec.rb +73 -70
- data/spec/reek/smells/duplicate_method_call_spec.rb +39 -37
- data/spec/reek/smells/feature_envy_spec.rb +53 -57
- data/spec/reek/smells/irresponsible_module_spec.rb +12 -11
- data/spec/reek/smells/long_parameter_list_spec.rb +33 -26
- data/spec/reek/smells/long_yield_list_spec.rb +15 -19
- data/spec/reek/smells/module_initialize_spec.rb +4 -6
- data/spec/reek/smells/nested_iterators_spec.rb +28 -28
- data/spec/reek/smells/nil_check_spec.rb +18 -20
- data/spec/reek/smells/prima_donna_method_spec.rb +6 -9
- data/spec/reek/smells/repeated_conditional_spec.rb +41 -43
- data/spec/reek/smells/too_many_instance_variables_spec.rb +6 -11
- data/spec/reek/smells/too_many_methods_spec.rb +44 -61
- data/spec/reek/smells/too_many_statements_spec.rb +14 -41
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +6 -11
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +10 -14
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +15 -16
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +33 -36
- data/spec/reek/smells/unused_parameters_spec.rb +16 -19
- data/spec/reek/smells/utility_function_spec.rb +7 -10
- metadata +22 -6
@@ -2,119 +2,124 @@ require 'spec_helper'
|
|
2
2
|
require 'reek/smells/data_clump'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
|
-
include Reek::Smells
|
6
|
-
|
7
5
|
shared_examples_for 'a data clump detector' do
|
8
6
|
it 'does not report small parameter sets' do
|
9
|
-
src =
|
10
|
-
# test module
|
11
|
-
#{@context} Scrunch
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
EOS
|
17
|
-
expect(src).not_to reek_of(DataClump)
|
7
|
+
src = <<-EOS
|
8
|
+
# test module
|
9
|
+
#{@context} Scrunch
|
10
|
+
def first(pa) @field == :sym ? 0 : 3; end
|
11
|
+
def second(pa) @field == :sym; end
|
12
|
+
def third(pa) pa - pb + @fred; end
|
13
|
+
end
|
14
|
+
EOS
|
15
|
+
expect(src).not_to reek_of(:DataClump)
|
18
16
|
end
|
19
17
|
|
20
18
|
context 'with 3 identical pairs' do
|
21
19
|
before :each do
|
22
20
|
@module_name = 'Scrunch'
|
23
|
-
@src =
|
24
|
-
#{@context} #{@module_name}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
EOS
|
30
|
-
ctx = ModuleContext.new(nil, @src.to_reek_source.syntax_tree)
|
31
|
-
detector = DataClump
|
21
|
+
@src = <<-EOS
|
22
|
+
#{@context} #{@module_name}
|
23
|
+
def first(pa, pb) @field == :sym ? 0 : 3; end
|
24
|
+
def second(pa, pb) @field == :sym; end
|
25
|
+
def third(pa, pb) pa - pb + @fred; end
|
26
|
+
end
|
27
|
+
EOS
|
28
|
+
ctx = Reek::Core::ModuleContext.new(nil, @src.to_reek_source.syntax_tree)
|
29
|
+
detector = build(:smell_detector, smell_type: :DataClump)
|
32
30
|
@smells = detector.examine_context(ctx)
|
33
31
|
end
|
32
|
+
|
34
33
|
it 'records only the one smell' do
|
35
34
|
expect(@smells.length).to eq(1)
|
36
35
|
end
|
36
|
+
|
37
37
|
it 'reports all parameters' do
|
38
38
|
expect(@smells[0].parameters[:parameters]).to eq(['pa', 'pb'])
|
39
39
|
end
|
40
|
+
|
40
41
|
it 'reports the number of occurrences' do
|
41
42
|
expect(@smells[0].parameters[:count]).to eq(3)
|
42
43
|
end
|
44
|
+
|
43
45
|
it 'reports all methods' do
|
44
46
|
expect(@smells[0].parameters[:methods]).to eq(['first', 'second', 'third'])
|
45
47
|
end
|
48
|
+
|
46
49
|
it 'reports the declaration line numbers' do
|
47
50
|
expect(@smells[0].lines).to eq([2, 3, 4])
|
48
51
|
end
|
52
|
+
|
49
53
|
it 'reports the correct smell class' do
|
50
|
-
expect(@smells[0].smell_category).to eq(DataClump.smell_category)
|
54
|
+
expect(@smells[0].smell_category).to eq(Reek::Smells::DataClump.smell_category)
|
51
55
|
end
|
56
|
+
|
52
57
|
it 'reports the context fq name' do
|
53
58
|
expect(@smells[0].context).to eq(@module_name)
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
it 'reports 3 swapped pairs' do
|
58
|
-
src =
|
59
|
-
#{@context} Scrunch
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
EOS
|
65
|
-
expect(src).to reek_of(DataClump,
|
63
|
+
src = <<-EOS
|
64
|
+
#{@context} Scrunch
|
65
|
+
def one(pa, pb) @field == :sym ? 0 : 3; end
|
66
|
+
def two(pb, pa) @field == :sym; end
|
67
|
+
def tri(pa, pb) pa - pb + @fred; end
|
68
|
+
end
|
69
|
+
EOS
|
70
|
+
expect(src).to reek_of(:DataClump,
|
66
71
|
count: 3,
|
67
72
|
parameters: ['pa', 'pb'])
|
68
73
|
end
|
69
74
|
|
70
75
|
it 'reports 3 identical parameter sets' do
|
71
|
-
src =
|
72
|
-
#{@context} Scrunch
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
EOS
|
78
|
-
expect(src).to reek_of(DataClump,
|
76
|
+
src = <<-EOS
|
77
|
+
#{@context} Scrunch
|
78
|
+
def first(pa, pb, pc) @field == :sym ? 0 : 3; end
|
79
|
+
def second(pa, pb, pc) @field == :sym; end
|
80
|
+
def third(pa, pb, pc) pa - pb + @fred; end
|
81
|
+
end
|
82
|
+
EOS
|
83
|
+
expect(src).to reek_of(:DataClump,
|
79
84
|
count: 3,
|
80
85
|
parameters: ['pa', 'pb', 'pc'])
|
81
86
|
end
|
82
87
|
|
83
88
|
it 'reports re-ordered identical parameter sets' do
|
84
|
-
src =
|
85
|
-
#{@context} Scrunch
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
EOS
|
91
|
-
expect(src).to reek_of(DataClump,
|
89
|
+
src = <<-EOS
|
90
|
+
#{@context} Scrunch
|
91
|
+
def first(pb, pa, pc) @field == :sym ? 0 : 3; end
|
92
|
+
def second(pc, pb, pa) @field == :sym; end
|
93
|
+
def third(pa, pb, pc) pa - pb + @fred; end
|
94
|
+
end
|
95
|
+
EOS
|
96
|
+
expect(src).to reek_of(:DataClump,
|
92
97
|
count: 3,
|
93
98
|
parameters: ['pa', 'pb', 'pc'])
|
94
99
|
end
|
95
100
|
|
96
101
|
it 'counts only identical parameter sets' do
|
97
|
-
src =
|
98
|
-
#{@context} RedCloth
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
EOS
|
104
|
-
expect(src).not_to reek_of(DataClump)
|
102
|
+
src = <<-EOS
|
103
|
+
#{@context} RedCloth
|
104
|
+
def fa(p1, p2, p3, conten) end
|
105
|
+
def fb(p1, p2, p3, conten) end
|
106
|
+
def fc(name, windowW, windowH) end
|
107
|
+
end
|
108
|
+
EOS
|
109
|
+
expect(src).not_to reek_of(:DataClump)
|
105
110
|
end
|
106
111
|
|
107
112
|
it 'gets a real example right' do
|
108
|
-
src =
|
109
|
-
#{@context} Inline
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
EOS
|
117
|
-
expect(src).to reek_of(DataClump, count: 5)
|
113
|
+
src = <<-EOS
|
114
|
+
#{@context} Inline
|
115
|
+
def generate(src, options) end
|
116
|
+
def c (src, options) end
|
117
|
+
def c_singleton (src, options) end
|
118
|
+
def c_raw (src, options) end
|
119
|
+
def c_raw_singleton (src, options) end
|
120
|
+
end
|
121
|
+
EOS
|
122
|
+
expect(src).to reek_of(:DataClump, count: 5)
|
118
123
|
end
|
119
124
|
|
120
125
|
it 'correctly checks number of occurences' do
|
@@ -127,7 +132,7 @@ EOS
|
|
127
132
|
def fe(p5, p1, p2) end
|
128
133
|
end
|
129
134
|
EOS
|
130
|
-
expect(src).not_to reek_of(DataClump)
|
135
|
+
expect(src).not_to reek_of(:DataClump)
|
131
136
|
end
|
132
137
|
|
133
138
|
it 'detects clumps smaller than the total number of arguments' do
|
@@ -138,7 +143,7 @@ EOS
|
|
138
143
|
def fc(p4, p1, p2) end
|
139
144
|
end
|
140
145
|
EOS
|
141
|
-
expect(src).to reek_of(DataClump,
|
146
|
+
expect(src).to reek_of(:DataClump,
|
142
147
|
parameters: %w(p1 p2))
|
143
148
|
end
|
144
149
|
|
@@ -150,14 +155,14 @@ EOS
|
|
150
155
|
def fc(p1, p2, *) end
|
151
156
|
end
|
152
157
|
EOS
|
153
|
-
expect(src).to reek_of(DataClump,
|
158
|
+
expect(src).to reek_of(:DataClump,
|
154
159
|
parameters: %w(p1 p2))
|
155
160
|
end
|
156
161
|
end
|
157
162
|
|
158
|
-
describe DataClump do
|
163
|
+
describe Reek::Smells::DataClump do
|
159
164
|
before(:each) do
|
160
|
-
@detector = DataClump
|
165
|
+
@detector = build(:smell_detector, smell_type: :DataClump)
|
161
166
|
end
|
162
167
|
|
163
168
|
it_should_behave_like 'SmellDetector'
|
@@ -177,6 +182,4 @@ describe DataClump do
|
|
177
182
|
|
178
183
|
it_should_behave_like 'a data clump detector'
|
179
184
|
end
|
180
|
-
|
181
|
-
# TODO: include singleton methods in the calcs
|
182
185
|
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'reek/smells/duplicate_method_call'
|
3
|
-
require 'reek/core/
|
3
|
+
require 'reek/core/code_context'
|
4
|
+
require 'reek/core/tree_walker'
|
4
5
|
require 'reek/core/sniffer'
|
5
6
|
require 'reek/smells/smell_detector_shared'
|
6
7
|
|
7
|
-
|
8
|
-
include Reek::Smells
|
9
|
-
|
10
|
-
describe DuplicateMethodCall do
|
8
|
+
describe Reek::Smells::DuplicateMethodCall do
|
11
9
|
context 'when a smell is reported' do
|
12
10
|
before :each do
|
13
|
-
@source_name = '
|
14
|
-
@detector = DuplicateMethodCall
|
11
|
+
@source_name = 'dummy_source'
|
12
|
+
@detector = build(:smell_detector, smell_type: :DuplicateMethodCall, source: @source_name)
|
15
13
|
src = <<-EOS
|
16
14
|
def double_thing(other)
|
17
15
|
other[@thing]
|
@@ -19,7 +17,7 @@ describe DuplicateMethodCall do
|
|
19
17
|
other[@thing]
|
20
18
|
end
|
21
19
|
EOS
|
22
|
-
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
20
|
+
ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
23
21
|
smells = @detector.examine_context(ctx)
|
24
22
|
expect(smells.length).to eq(1)
|
25
23
|
@warning = smells[0]
|
@@ -31,6 +29,7 @@ describe DuplicateMethodCall do
|
|
31
29
|
it 'reports the call' do
|
32
30
|
expect(@warning.parameters[:name]).to eq('other[@thing]')
|
33
31
|
end
|
32
|
+
|
34
33
|
it 'reports the correct lines' do
|
35
34
|
expect(@warning.lines).to eq([2, 4])
|
36
35
|
end
|
@@ -39,28 +38,28 @@ describe DuplicateMethodCall do
|
|
39
38
|
context 'with repeated method calls' do
|
40
39
|
it 'reports repeated call' do
|
41
40
|
src = 'def double_thing() @other.thing + @other.thing end'
|
42
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing')
|
41
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing')
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'reports repeated call to lvar' do
|
46
45
|
src = 'def double_thing(other) other[@thing] + other[@thing] end'
|
47
|
-
expect(src).to reek_of(DuplicateMethodCall, name: 'other[@thing]')
|
46
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: 'other[@thing]')
|
48
47
|
end
|
49
48
|
|
50
49
|
it 'reports call parameters' do
|
51
50
|
src = 'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'
|
52
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing(2, 3)')
|
51
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing(2, 3)')
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'should report nested calls' do
|
56
55
|
src = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
57
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing')
|
58
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing.foo')
|
56
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing')
|
57
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing.foo')
|
59
58
|
end
|
60
59
|
|
61
60
|
it 'should ignore calls to new' do
|
62
61
|
src = 'def double_thing() @other.new + @other.new end'
|
63
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
62
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -76,7 +75,7 @@ describe DuplicateMethodCall do
|
|
76
75
|
end
|
77
76
|
end
|
78
77
|
EOS
|
79
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
78
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
@@ -88,7 +87,7 @@ describe DuplicateMethodCall do
|
|
88
87
|
bar { baz }
|
89
88
|
end
|
90
89
|
EOS
|
91
|
-
expect(src).to reek_of(DuplicateMethodCall)
|
90
|
+
expect(src).to reek_of(:DuplicateMethodCall)
|
92
91
|
end
|
93
92
|
|
94
93
|
it 'reports no smell if the blocks are different' do
|
@@ -98,7 +97,7 @@ describe DuplicateMethodCall do
|
|
98
97
|
bar { qux }
|
99
98
|
end
|
100
99
|
EOS
|
101
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
100
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
@@ -110,7 +109,7 @@ describe DuplicateMethodCall do
|
|
110
109
|
bar.qux { baz }
|
111
110
|
end
|
112
111
|
EOS
|
113
|
-
expect(src).to reek_of(DuplicateMethodCall)
|
112
|
+
expect(src).to reek_of(:DuplicateMethodCall)
|
114
113
|
end
|
115
114
|
|
116
115
|
it 'reports a smell if the blocks are different' do
|
@@ -120,53 +119,55 @@ describe DuplicateMethodCall do
|
|
120
119
|
bar.qux { qux }
|
121
120
|
end
|
122
121
|
EOS
|
123
|
-
expect(src).to reek_of(DuplicateMethodCall)
|
122
|
+
expect(src).to reek_of(:DuplicateMethodCall)
|
124
123
|
end
|
125
124
|
end
|
126
125
|
|
127
126
|
context 'with repeated attribute assignment' do
|
128
127
|
it 'reports repeated assignment' do
|
129
128
|
src = 'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'
|
130
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other[thing] = true')
|
129
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other[thing] = true')
|
131
130
|
end
|
132
131
|
it 'does not report multi-assignments' do
|
133
|
-
src =
|
134
|
-
def _parse ctxt
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
EOS
|
139
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
132
|
+
src = <<-EOS
|
133
|
+
def _parse ctxt
|
134
|
+
ctxt.index, result = @ind, @result
|
135
|
+
error, ctxt.index = @err, @err_ind
|
136
|
+
end
|
137
|
+
EOS
|
138
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
140
139
|
end
|
141
140
|
end
|
142
141
|
|
143
142
|
context 'non-repeated method calls' do
|
144
143
|
it 'should not report similar calls' do
|
145
144
|
src = 'def equals(other) other.thing == self.thing end'
|
146
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
145
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
147
146
|
end
|
147
|
+
|
148
148
|
it 'should respect call parameters' do
|
149
149
|
src = 'def double_thing() @other.thing(3) + @other.thing(2) end'
|
150
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
150
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
context 'allowing up to 3 calls' do
|
155
155
|
before :each do
|
156
|
-
@config = { DuplicateMethodCall:
|
156
|
+
@config = { DuplicateMethodCall:
|
157
|
+
{ Reek::Smells::DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3 } }
|
157
158
|
end
|
158
159
|
|
159
160
|
it 'does not report double calls' do
|
160
161
|
src = 'def double_thing() @other.thing + @other.thing end'
|
161
162
|
with_test_config(@config) do
|
162
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
163
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
166
167
|
it 'does not report triple calls' do
|
167
168
|
src = 'def double_thing() @other.thing + @other.thing + @other.thing end'
|
168
169
|
with_test_config(@config) do
|
169
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
170
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
170
171
|
end
|
171
172
|
end
|
172
173
|
|
@@ -177,7 +178,7 @@ EOS
|
|
177
178
|
end
|
178
179
|
'
|
179
180
|
with_test_config(@config) do
|
180
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing', count: 4)
|
181
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing', count: 4)
|
181
182
|
end
|
182
183
|
end
|
183
184
|
end
|
@@ -185,14 +186,15 @@ EOS
|
|
185
186
|
context 'allowing calls to some methods' do
|
186
187
|
before :each do
|
187
188
|
@config = { DuplicateMethodCall:
|
188
|
-
{ DuplicateMethodCall::ALLOW_CALLS_KEY =>
|
189
|
+
{ Reek::Smells::DuplicateMethodCall::ALLOW_CALLS_KEY =>
|
190
|
+
['@some.thing', /puts/] } }
|
189
191
|
end
|
190
192
|
|
191
193
|
it 'does not report calls to some methods' do
|
192
194
|
src = 'def double_some_thing() @some.thing + @some.thing end'
|
193
195
|
|
194
196
|
with_test_config(@config) do
|
195
|
-
expect(src).not_to reek_of(DuplicateMethodCall)
|
197
|
+
expect(src).not_to reek_of(:DuplicateMethodCall)
|
196
198
|
end
|
197
199
|
end
|
198
200
|
|
@@ -200,7 +202,7 @@ EOS
|
|
200
202
|
src = 'def double_other_thing() @other.thing + @other.thing end'
|
201
203
|
|
202
204
|
with_test_config(@config) do
|
203
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing')
|
205
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing')
|
204
206
|
end
|
205
207
|
end
|
206
208
|
|
@@ -208,7 +210,7 @@ EOS
|
|
208
210
|
src = 'def double_puts() puts @other.thing; puts @other.thing end'
|
209
211
|
|
210
212
|
with_test_config(@config) do
|
211
|
-
expect(src).to reek_of(DuplicateMethodCall, name: '@other.thing')
|
213
|
+
expect(src).to reek_of(:DuplicateMethodCall, name: '@other.thing')
|
212
214
|
end
|
213
215
|
end
|
214
216
|
end
|
@@ -2,10 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'reek/smells/feature_envy'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
|
-
|
6
|
-
include Reek::Smells
|
7
|
-
|
8
|
-
describe FeatureEnvy do
|
5
|
+
describe Reek::Smells::FeatureEnvy do
|
9
6
|
context 'with no smell' do
|
10
7
|
it 'should not report use of self' do
|
11
8
|
expect('def simple() self.to_s + self.to_i end').not_to reek_of(:FeatureEnvy)
|
@@ -132,14 +129,6 @@ describe FeatureEnvy do
|
|
132
129
|
lv.price + lv.tax
|
133
130
|
end
|
134
131
|
').to reek_only_of(:FeatureEnvy)
|
135
|
-
#
|
136
|
-
# def moved_version
|
137
|
-
# price + tax
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# def envy
|
141
|
-
# @item.moved_version
|
142
|
-
# end
|
143
132
|
end
|
144
133
|
|
145
134
|
it 'ignores frequent use of a call' do
|
@@ -177,54 +166,54 @@ describe FeatureEnvy do
|
|
177
166
|
end
|
178
167
|
|
179
168
|
it 'counts self references correctly' do
|
180
|
-
src =
|
181
|
-
def adopt(other)
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
end
|
188
|
-
EOS
|
169
|
+
src = <<-EOS
|
170
|
+
def adopt(other)
|
171
|
+
other.keys.each do |key|
|
172
|
+
self[key] += 3
|
173
|
+
self[key] = o4
|
174
|
+
end
|
175
|
+
self
|
176
|
+
end
|
177
|
+
EOS
|
189
178
|
expect(src).not_to reek_of(:FeatureEnvy)
|
190
179
|
end
|
191
180
|
end
|
192
181
|
|
193
|
-
describe FeatureEnvy do
|
182
|
+
describe Reek::Smells::FeatureEnvy do
|
194
183
|
it 'counts references to self correctly' do
|
195
|
-
ruby =
|
196
|
-
def report
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
205
|
-
EOS
|
184
|
+
ruby = <<-EOS
|
185
|
+
def report
|
186
|
+
unless @report
|
187
|
+
@report = Report.new
|
188
|
+
cf = SmellConfig.new
|
189
|
+
cf = cf.load_local(@dir) if @dir
|
190
|
+
TreeWalker.new(@report, cf.smell_listeners).check_source(@source)
|
191
|
+
end
|
192
|
+
@report
|
193
|
+
end
|
194
|
+
EOS
|
206
195
|
expect(ruby).not_to reek_of(:FeatureEnvy)
|
207
196
|
end
|
208
197
|
|
209
198
|
it 'interprets << correctly' do
|
210
|
-
ruby =
|
211
|
-
def report_on(report)
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
218
|
-
EOS
|
199
|
+
ruby = <<-EOS
|
200
|
+
def report_on(report)
|
201
|
+
if @is_doubled
|
202
|
+
report.record_doubled_smell(self)
|
203
|
+
else
|
204
|
+
report << self
|
205
|
+
end
|
206
|
+
end
|
207
|
+
EOS
|
219
208
|
|
220
209
|
expect(ruby).not_to reek_of(:FeatureEnvy)
|
221
210
|
end
|
222
211
|
end
|
223
212
|
|
224
|
-
describe FeatureEnvy do
|
213
|
+
describe Reek::Smells::FeatureEnvy do
|
225
214
|
before(:each) do
|
226
|
-
@source_name = '
|
227
|
-
@detector = FeatureEnvy
|
215
|
+
@source_name = 'dummy_source'
|
216
|
+
@detector = build(:smell_detector, smell_type: :FeatureEnvy, source: @source_name)
|
228
217
|
end
|
229
218
|
|
230
219
|
it_should_behave_like 'SmellDetector'
|
@@ -232,37 +221,44 @@ describe FeatureEnvy do
|
|
232
221
|
context 'when reporting yaml' do
|
233
222
|
before :each do
|
234
223
|
@receiver = 'other'
|
235
|
-
src =
|
236
|
-
def envious(other)
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
end
|
242
|
-
EOS
|
224
|
+
src = <<-EOS
|
225
|
+
def envious(other)
|
226
|
+
#{@receiver}.call
|
227
|
+
self.do_nothing
|
228
|
+
#{@receiver}.other
|
229
|
+
#{@receiver}.fred
|
230
|
+
end
|
231
|
+
EOS
|
243
232
|
source = src.to_reek_source
|
244
|
-
sniffer = Sniffer.new(source)
|
245
|
-
@mctx =
|
233
|
+
sniffer = Reek::Core::Sniffer.new(source)
|
234
|
+
@mctx = Reek::Core::TreeWalker.new(sniffer).process_def(source.syntax_tree)
|
246
235
|
@smells = @detector.examine_context(@mctx)
|
247
236
|
end
|
237
|
+
|
248
238
|
it 'reports only that smell' do
|
249
239
|
expect(@smells.length).to eq(1)
|
250
240
|
end
|
241
|
+
|
251
242
|
it 'reports the source' do
|
252
243
|
expect(@smells[0].source).to eq(@source_name)
|
253
244
|
end
|
245
|
+
|
254
246
|
it 'reports the smell class' do
|
255
|
-
expect(@smells[0].smell_category).to eq(
|
247
|
+
expect(@smells[0].smell_category).to eq(described_class.smell_category)
|
256
248
|
end
|
249
|
+
|
257
250
|
it 'reports the smell sub class' do
|
258
|
-
expect(@smells[0].smell_type).to eq(
|
251
|
+
expect(@smells[0].smell_type).to eq(described_class.smell_type)
|
259
252
|
end
|
253
|
+
|
260
254
|
it 'reports the envious receiver' do
|
261
255
|
expect(@smells[0].parameters[:name]).to eq(@receiver)
|
262
256
|
end
|
257
|
+
|
263
258
|
it 'reports the number of references' do
|
264
259
|
expect(@smells[0].parameters[:count]).to eq(3)
|
265
260
|
end
|
261
|
+
|
266
262
|
it 'reports the referring lines' do
|
267
263
|
skip
|
268
264
|
expect(@smells[0].lines).to eq([2, 4, 5])
|