reek 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/README.md +22 -14
- data/Rakefile +2 -15
- data/assets/html_output.html.erb +103 -0
- data/features/command_line_interface/options.feature +3 -0
- data/features/command_line_interface/smell_selection.feature +19 -0
- data/features/rake_task/rake_task.feature +1 -1
- data/features/reports/reports.feature +16 -0
- data/features/reports/yaml.feature +26 -23
- data/features/samples.feature +2 -1
- data/features/step_definitions/reek_steps.rb +15 -15
- data/features/support/env.rb +7 -9
- data/lib/reek/cli/application.rb +2 -4
- data/lib/reek/cli/command.rb +12 -0
- data/lib/reek/cli/help_command.rb +3 -6
- data/lib/reek/cli/options.rb +147 -0
- data/lib/reek/cli/reek_command.rb +18 -14
- data/lib/reek/cli/report/formatter.rb +56 -0
- data/lib/reek/cli/report/report.rb +106 -0
- data/lib/reek/cli/report/strategy.rb +63 -0
- data/lib/reek/cli/version_command.rb +3 -6
- data/lib/reek/config_file_exception.rb +0 -1
- data/lib/reek/core/code_context.rb +1 -3
- data/lib/reek/core/code_parser.rb +13 -12
- data/lib/reek/core/method_context.rb +13 -2
- data/lib/reek/core/module_context.rb +0 -4
- data/lib/reek/core/object_refs.rb +2 -3
- data/lib/reek/core/singleton_method_context.rb +0 -2
- data/lib/reek/core/smell_configuration.rb +3 -5
- data/lib/reek/core/smell_repository.rb +7 -8
- data/lib/reek/core/sniffer.rb +4 -10
- data/lib/reek/core/stop_context.rb +2 -4
- data/lib/reek/core/warning_collector.rb +0 -1
- data/lib/reek/examiner.rb +19 -17
- data/lib/reek/rake/task.rb +7 -10
- data/lib/reek/smell_warning.rb +4 -8
- data/lib/reek/smells.rb +0 -1
- data/lib/reek/smells/attribute.rb +8 -11
- data/lib/reek/smells/boolean_parameter.rb +5 -7
- data/lib/reek/smells/class_variable.rb +6 -7
- data/lib/reek/smells/control_parameter.rb +78 -45
- data/lib/reek/smells/data_clump.rb +13 -16
- data/lib/reek/smells/duplicate_method_call.rb +13 -11
- data/lib/reek/smells/feature_envy.rb +6 -7
- data/lib/reek/smells/irresponsible_module.rb +4 -6
- data/lib/reek/smells/long_parameter_list.rb +5 -7
- data/lib/reek/smells/long_yield_list.rb +2 -4
- data/lib/reek/smells/nested_iterators.rb +12 -22
- data/lib/reek/smells/nil_check.rb +35 -46
- data/lib/reek/smells/prima_donna_method.rb +24 -16
- data/lib/reek/smells/repeated_conditional.rb +8 -10
- data/lib/reek/smells/smell_detector.rb +9 -7
- data/lib/reek/smells/too_many_instance_variables.rb +7 -9
- data/lib/reek/smells/too_many_methods.rb +6 -8
- data/lib/reek/smells/too_many_statements.rb +4 -6
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +7 -9
- data/lib/reek/smells/uncommunicative_variable_name.rb +15 -18
- data/lib/reek/smells/unused_parameters.rb +5 -45
- data/lib/reek/smells/utility_function.rb +9 -10
- data/lib/reek/source.rb +0 -1
- data/lib/reek/source/code_comment.rb +7 -8
- data/lib/reek/source/config_file.rb +2 -4
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/reference_collector.rb +1 -2
- data/lib/reek/source/sexp_extensions.rb +93 -10
- data/lib/reek/source/sexp_formatter.rb +2 -3
- data/lib/reek/source/sexp_node.rb +19 -15
- data/lib/reek/source/source_code.rb +4 -14
- data/lib/reek/source/source_file.rb +3 -5
- data/lib/reek/source/source_locator.rb +5 -6
- data/lib/reek/source/source_repository.rb +3 -3
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +1 -2
- data/lib/reek/spec/should_reek.rb +8 -5
- data/lib/reek/spec/should_reek_of.rb +6 -4
- data/lib/reek/spec/should_reek_only_of.rb +10 -6
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +34 -30
- data/spec/gem/updates_spec.rb +3 -4
- data/spec/gem/yard_spec.rb +1 -2
- data/spec/matchers/smell_of_matcher.rb +12 -14
- data/spec/quality/reek_source_spec.rb +42 -0
- data/spec/reek/cli/help_command_spec.rb +7 -5
- data/spec/reek/cli/report_spec.rb +89 -22
- data/spec/reek/cli/version_command_spec.rb +8 -6
- data/spec/reek/core/code_context_spec.rb +25 -26
- data/spec/reek/core/code_parser_spec.rb +6 -6
- data/spec/reek/core/method_context_spec.rb +18 -18
- data/spec/reek/core/module_context_spec.rb +5 -5
- data/spec/reek/core/object_refs_spec.rb +21 -22
- data/spec/reek/core/smell_configuration_spec.rb +22 -21
- data/spec/reek/core/stop_context_spec.rb +2 -2
- data/spec/reek/core/warning_collector_spec.rb +3 -3
- data/spec/reek/examiner_spec.rb +9 -9
- data/spec/reek/smell_warning_spec.rb +29 -29
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/behaves_like_variable_detector.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +17 -17
- data/spec/reek/smells/class_variable_spec.rb +9 -9
- data/spec/reek/smells/control_parameter_spec.rb +161 -137
- data/spec/reek/smells/data_clump_spec.rb +22 -19
- data/spec/reek/smells/duplicate_method_call_spec.rb +71 -27
- data/spec/reek/smells/feature_envy_spec.rb +32 -32
- data/spec/reek/smells/irresponsible_module_spec.rb +21 -21
- data/spec/reek/smells/long_parameter_list_spec.rb +14 -14
- data/spec/reek/smells/long_yield_list_spec.rb +6 -6
- data/spec/reek/smells/nested_iterators_spec.rb +21 -21
- data/spec/reek/smells/nil_check_spec.rb +23 -15
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -5
- data/spec/reek/smells/repeated_conditional_spec.rb +14 -14
- data/spec/reek/smells/smell_detector_shared.rb +9 -9
- data/spec/reek/smells/too_many_instance_variables_spec.rb +12 -12
- data/spec/reek/smells/too_many_methods_spec.rb +10 -10
- data/spec/reek/smells/too_many_statements_spec.rb +41 -41
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +21 -21
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +49 -49
- data/spec/reek/smells/unused_parameters_spec.rb +26 -16
- data/spec/reek/smells/utility_function_spec.rb +20 -20
- data/spec/reek/source/code_comment_spec.rb +37 -37
- data/spec/reek/source/object_source_spec.rb +5 -5
- data/spec/reek/source/reference_collector_spec.rb +9 -9
- data/spec/reek/source/sexp_extensions_spec.rb +73 -52
- data/spec/reek/source/sexp_formatter_spec.rb +3 -4
- data/spec/reek/source/sexp_node_spec.rb +3 -3
- data/spec/reek/source/source_code_spec.rb +16 -15
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_only_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_spec.rb +11 -11
- data/spec/samples/one_smelly_file/dirty.rb +3 -0
- data/spec/spec_helper.rb +0 -6
- data/tasks/develop.rake +8 -16
- data/tasks/reek.rake +5 -13
- data/tasks/test.rake +5 -22
- metadata +56 -34
- data/lib/reek/cli/command_line.rb +0 -126
- data/lib/reek/cli/report.rb +0 -138
@@ -14,7 +14,7 @@ shared_examples_for 'a data clump detector' do
|
|
14
14
|
def third(pa) pa - pb + @fred; end
|
15
15
|
end
|
16
16
|
EOS
|
17
|
-
src.
|
17
|
+
expect(src).not_to smell_of(DataClump)
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'with 3 identical pairs' do
|
@@ -34,25 +34,25 @@ EOS
|
|
34
34
|
@yaml = @warning.to_yaml
|
35
35
|
end
|
36
36
|
it 'records only the one smell' do
|
37
|
-
@smells.length.
|
37
|
+
expect(@smells.length).to eq(1)
|
38
38
|
end
|
39
39
|
it 'reports all parameters' do
|
40
|
-
@smells[0].smell[DataClump::PARAMETERS_KEY].
|
40
|
+
expect(@smells[0].smell[DataClump::PARAMETERS_KEY]).to eq(['pa', 'pb'])
|
41
41
|
end
|
42
42
|
it 'reports the number of occurrences' do
|
43
|
-
@smells[0].smell[DataClump::OCCURRENCES_KEY].
|
43
|
+
expect(@smells[0].smell[DataClump::OCCURRENCES_KEY]).to eq(3)
|
44
44
|
end
|
45
45
|
it 'reports all methods' do
|
46
|
-
@smells[0].smell[DataClump::METHODS_KEY].
|
46
|
+
expect(@smells[0].smell[DataClump::METHODS_KEY]).to eq(['first', 'second', 'third'])
|
47
47
|
end
|
48
48
|
it 'reports the declaration line numbers' do
|
49
|
-
@smells[0].lines.
|
49
|
+
expect(@smells[0].lines).to eq([2, 3, 4])
|
50
50
|
end
|
51
51
|
it 'reports the correct smell class' do
|
52
|
-
@smells[0].smell_class.
|
52
|
+
expect(@smells[0].smell_class).to eq(DataClump::SMELL_CLASS)
|
53
53
|
end
|
54
54
|
it 'reports the context fq name' do
|
55
|
-
@smells[0].context.
|
55
|
+
expect(@smells[0].context).to eq(@module_name)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -64,8 +64,9 @@ EOS
|
|
64
64
|
def tri(pa, pb) pa - pb + @fred; end
|
65
65
|
end
|
66
66
|
EOS
|
67
|
-
src.
|
68
|
-
|
67
|
+
expect(src).to smell_of(DataClump,
|
68
|
+
DataClump::OCCURRENCES_KEY => 3,
|
69
|
+
DataClump::PARAMETERS_KEY => ['pa', 'pb'])
|
69
70
|
end
|
70
71
|
|
71
72
|
it 'reports 3 identical parameter sets' do
|
@@ -76,8 +77,9 @@ EOS
|
|
76
77
|
def third(pa, pb, pc) pa - pb + @fred; end
|
77
78
|
end
|
78
79
|
EOS
|
79
|
-
src.
|
80
|
-
|
80
|
+
expect(src).to smell_of(DataClump,
|
81
|
+
DataClump::OCCURRENCES_KEY => 3,
|
82
|
+
DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
|
81
83
|
end
|
82
84
|
|
83
85
|
it 'reports re-ordered identical parameter sets' do
|
@@ -88,8 +90,9 @@ EOS
|
|
88
90
|
def third(pa, pb, pc) pa - pb + @fred; end
|
89
91
|
end
|
90
92
|
EOS
|
91
|
-
src.
|
92
|
-
|
93
|
+
expect(src).to smell_of(DataClump,
|
94
|
+
DataClump::OCCURRENCES_KEY => 3,
|
95
|
+
DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
|
93
96
|
end
|
94
97
|
|
95
98
|
it 'counts only identical parameter sets' do
|
@@ -100,7 +103,7 @@ EOS
|
|
100
103
|
def fc(name, windowW, windowH) end
|
101
104
|
end
|
102
105
|
EOS
|
103
|
-
src.
|
106
|
+
expect(src).not_to smell_of(DataClump)
|
104
107
|
end
|
105
108
|
|
106
109
|
it 'gets a real example right' do
|
@@ -113,7 +116,7 @@ EOS
|
|
113
116
|
def c_raw_singleton (src, options) end
|
114
117
|
end
|
115
118
|
EOS
|
116
|
-
src.
|
119
|
+
expect(src).to smell_of(DataClump, DataClump::OCCURRENCES_KEY => 5)
|
117
120
|
end
|
118
121
|
|
119
122
|
it 'correctly checks number of occurences' do
|
@@ -126,7 +129,7 @@ EOS
|
|
126
129
|
def fe(p5, p1, p2) end
|
127
130
|
end
|
128
131
|
EOS
|
129
|
-
src.
|
132
|
+
expect(src).not_to smell_of(DataClump)
|
130
133
|
end
|
131
134
|
|
132
135
|
it 'detects clumps smaller than the total number of arguments' do
|
@@ -137,8 +140,8 @@ EOS
|
|
137
140
|
def fc(p4, p1, p2) end
|
138
141
|
end
|
139
142
|
EOS
|
140
|
-
src.
|
141
|
-
|
143
|
+
expect(src).to smell_of(DataClump,
|
144
|
+
DataClump::PARAMETERS_KEY => %w(p1 p2))
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
EOS
|
23
23
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
24
24
|
smells = @detector.examine_context(ctx)
|
25
|
-
smells.length.
|
25
|
+
expect(smells.length).to eq(1)
|
26
26
|
@warning = smells[0]
|
27
27
|
end
|
28
28
|
|
@@ -30,38 +30,38 @@ EOS
|
|
30
30
|
it_should_behave_like 'common fields set correctly'
|
31
31
|
|
32
32
|
it 'reports the call' do
|
33
|
-
@warning.smell[DuplicateMethodCall::CALL_KEY].
|
33
|
+
expect(@warning.smell[DuplicateMethodCall::CALL_KEY]).to eq('other[@thing]')
|
34
34
|
end
|
35
35
|
it 'reports the correct lines' do
|
36
|
-
@warning.lines.
|
36
|
+
expect(@warning.lines).to eq([2, 4])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
40
|
+
context 'with repeated method calls' do
|
41
41
|
it 'reports repeated call' do
|
42
42
|
src = 'def double_thing() @other.thing + @other.thing end'
|
43
|
-
src.
|
43
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing')
|
44
44
|
end
|
45
45
|
it 'reports repeated call to lvar' do
|
46
46
|
src = 'def double_thing(other) other[@thing] + other[@thing] end'
|
47
|
-
src.
|
47
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => 'other[@thing]')
|
48
48
|
end
|
49
49
|
it 'reports call parameters' do
|
50
50
|
src = 'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'
|
51
|
-
src.
|
51
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing(2, 3)')
|
52
52
|
end
|
53
53
|
it 'should report nested calls' do
|
54
54
|
src = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
55
|
-
src.
|
56
|
-
|
55
|
+
expect(src).to smell_of(DuplicateMethodCall, { DuplicateMethodCall::CALL_KEY => '@other.thing' },
|
56
|
+
DuplicateMethodCall::CALL_KEY => '@other.thing.foo')
|
57
57
|
end
|
58
58
|
it 'should ignore calls to new' do
|
59
59
|
src = 'def double_thing() @other.new + @other.new end'
|
60
|
-
src.
|
60
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
context
|
64
|
+
context 'with repeated simple method calls' do
|
65
65
|
it 'reports no smell' do
|
66
66
|
src = <<-EOS
|
67
67
|
def foo
|
@@ -73,14 +73,58 @@ EOS
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
EOS
|
76
|
-
src.
|
76
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'with repeated simple method calls with blocks' do
|
81
|
+
it 'reports a smell if the blocks are identical' do
|
82
|
+
src = <<-EOS
|
83
|
+
def foo
|
84
|
+
bar { baz }
|
85
|
+
bar { baz }
|
86
|
+
end
|
87
|
+
EOS
|
88
|
+
expect(src).to smell_of(DuplicateMethodCall)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'reports no smell if the blocks are different' do
|
92
|
+
src = <<-EOS
|
93
|
+
def foo
|
94
|
+
bar { baz }
|
95
|
+
bar { qux }
|
96
|
+
end
|
97
|
+
EOS
|
98
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with repeated method calls with receivers with blocks' do
|
103
|
+
it 'reports a smell if the blocks are identical' do
|
104
|
+
src = <<-EOS
|
105
|
+
def foo
|
106
|
+
bar.qux { baz }
|
107
|
+
bar.qux { baz }
|
108
|
+
end
|
109
|
+
EOS
|
110
|
+
expect(src).to smell_of(DuplicateMethodCall)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'reports a smell if the blocks are different' do
|
114
|
+
src = <<-EOS
|
115
|
+
def foo
|
116
|
+
bar.qux { baz }
|
117
|
+
bar.qux { qux }
|
118
|
+
end
|
119
|
+
EOS
|
120
|
+
expect(src).to smell_of(DuplicateMethodCall)
|
77
121
|
end
|
78
122
|
end
|
79
123
|
|
80
124
|
context 'with repeated attribute assignment' do
|
81
125
|
it 'reports repeated assignment' do
|
82
126
|
src = 'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'
|
83
|
-
src.
|
127
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other[thing] = true')
|
84
128
|
end
|
85
129
|
it 'does not report multi-assignments' do
|
86
130
|
src = <<EOS
|
@@ -89,54 +133,54 @@ def _parse ctxt
|
|
89
133
|
error, ctxt.index = @err, @err_ind
|
90
134
|
end
|
91
135
|
EOS
|
92
|
-
src.
|
136
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
93
137
|
end
|
94
138
|
end
|
95
139
|
|
96
|
-
context
|
140
|
+
context 'non-repeated method calls' do
|
97
141
|
it 'should not report similar calls' do
|
98
142
|
src = 'def equals(other) other.thing == self.thing end'
|
99
|
-
src.
|
143
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
100
144
|
end
|
101
145
|
it 'should respect call parameters' do
|
102
146
|
src = 'def double_thing() @other.thing(3) + @other.thing(2) end'
|
103
|
-
src.
|
147
|
+
expect(src).not_to smell_of(DuplicateMethodCall)
|
104
148
|
end
|
105
149
|
end
|
106
150
|
|
107
|
-
context
|
151
|
+
context 'allowing up to 3 calls' do
|
108
152
|
before :each do
|
109
|
-
@config = {DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3}
|
153
|
+
@config = { DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3 }
|
110
154
|
end
|
111
155
|
it 'does not report double calls' do
|
112
156
|
src = 'def double_thing() @other.thing + @other.thing end'
|
113
|
-
src.
|
157
|
+
expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
|
114
158
|
end
|
115
159
|
it 'does not report triple calls' do
|
116
160
|
src = 'def double_thing() @other.thing + @other.thing + @other.thing end'
|
117
|
-
src.
|
161
|
+
expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
|
118
162
|
end
|
119
163
|
it 'reports quadruple calls' do
|
120
164
|
src = 'def double_thing() @other.thing + @other.thing + @other.thing + @other.thing end'
|
121
|
-
src.
|
165
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing', DuplicateMethodCall::OCCURRENCES_KEY => 4).with_config(@config)
|
122
166
|
end
|
123
167
|
end
|
124
168
|
|
125
|
-
context
|
169
|
+
context 'allowing calls to some methods' do
|
126
170
|
before :each do
|
127
|
-
@config = {DuplicateMethodCall::ALLOW_CALLS_KEY => ['@some.thing'
|
171
|
+
@config = { DuplicateMethodCall::ALLOW_CALLS_KEY => ['@some.thing', /puts/] }
|
128
172
|
end
|
129
173
|
it 'does not report calls to some methods' do
|
130
174
|
src = 'def double_some_thing() @some.thing + @some.thing end'
|
131
|
-
src.
|
175
|
+
expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
|
132
176
|
end
|
133
177
|
it 'reports calls to other methods' do
|
134
178
|
src = 'def double_other_thing() @other.thing + @other.thing end'
|
135
|
-
src.
|
179
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
|
136
180
|
end
|
137
181
|
it 'does not report calls to methods specifed with a regular expression' do
|
138
182
|
src = 'def double_puts() puts @other.thing; puts @other.thing end'
|
139
|
-
src.
|
183
|
+
expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
|
140
184
|
end
|
141
185
|
end
|
142
186
|
end
|
@@ -8,40 +8,40 @@ include Reek::Smells
|
|
8
8
|
describe FeatureEnvy do
|
9
9
|
context 'with no smell' do
|
10
10
|
it 'should not report use of self' do
|
11
|
-
'def simple() self.to_s + self.to_i end'.
|
11
|
+
expect('def simple() self.to_s + self.to_i end').not_to reek
|
12
12
|
end
|
13
13
|
it 'should not report vcall with no argument' do
|
14
|
-
'def simple() func; end'.
|
14
|
+
expect('def simple() func; end').not_to reek
|
15
15
|
end
|
16
16
|
it 'should not report single use' do
|
17
|
-
'def no_envy(arga) arga.barg(@item) end'.
|
17
|
+
expect('def no_envy(arga) arga.barg(@item) end').not_to reek
|
18
18
|
end
|
19
19
|
it 'should not report return value' do
|
20
|
-
'def no_envy(arga) arga.barg(@item); arga end'.
|
20
|
+
expect('def no_envy(arga) arga.barg(@item); arga end').not_to reek
|
21
21
|
end
|
22
22
|
it 'should ignore global variables' do
|
23
|
-
'def no_envy() $s2.to_a; $s2[@item] end'.
|
23
|
+
expect('def no_envy() $s2.to_a; $s2[@item] end').not_to reek
|
24
24
|
end
|
25
25
|
it 'should not report class methods' do
|
26
|
-
'def simple() self.class.new.flatten_merge(self) end'.
|
26
|
+
expect('def simple() self.class.new.flatten_merge(self) end').not_to reek
|
27
27
|
end
|
28
28
|
it 'should not report single use of an ivar' do
|
29
|
-
'def no_envy() @item.to_a end'.
|
29
|
+
expect('def no_envy() @item.to_a end').not_to reek
|
30
30
|
end
|
31
31
|
it 'should not report returning an ivar' do
|
32
|
-
'def no_envy() @item.to_a; @item end'.
|
32
|
+
expect('def no_envy() @item.to_a; @item end').not_to reek
|
33
33
|
end
|
34
34
|
it 'should not report ivar usage in a parameter' do
|
35
|
-
'def no_envy() @item.price + tax(@item) - savings(@item) end'.
|
35
|
+
expect('def no_envy() @item.price + tax(@item) - savings(@item) end').not_to reek
|
36
36
|
end
|
37
37
|
it 'should not report single use of an lvar' do
|
38
|
-
'def no_envy() lv = @item; lv.to_a end'.
|
38
|
+
expect('def no_envy() lv = @item; lv.to_a end').not_to reek
|
39
39
|
end
|
40
40
|
it 'should not report returning an lvar' do
|
41
|
-
'def no_envy() lv = @item; lv.to_a; lv end'.
|
41
|
+
expect('def no_envy() lv = @item; lv.to_a; lv end').not_to reek
|
42
42
|
end
|
43
43
|
it 'ignores lvar usage in a parameter' do
|
44
|
-
'def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end'.
|
44
|
+
expect('def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end').not_to reek
|
45
45
|
end
|
46
46
|
it 'ignores multiple ivars' do
|
47
47
|
src = <<EOS
|
@@ -52,7 +52,7 @@ describe FeatureEnvy do
|
|
52
52
|
@nother.d
|
53
53
|
end
|
54
54
|
EOS
|
55
|
-
src.
|
55
|
+
expect(src).not_to reek
|
56
56
|
#
|
57
57
|
# def other.func(me)
|
58
58
|
# a
|
@@ -66,7 +66,7 @@ EOS
|
|
66
66
|
|
67
67
|
context 'with 2 calls to a parameter' do
|
68
68
|
it 'reports the smell' do
|
69
|
-
'def envy(arga) arga.b(arga) + arga.c(@fred) end'.
|
69
|
+
expect('def envy(arga) arga.b(arga) + arga.c(@fred) end').to reek_only_of(:FeatureEnvy, /arga/)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -80,7 +80,7 @@ def total_envy
|
|
80
80
|
total *= 1.15
|
81
81
|
end
|
82
82
|
EOS
|
83
|
-
src.
|
83
|
+
expect(src).to reek_only_of(:FeatureEnvy, /total/)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should report multiple affinities' do
|
@@ -92,20 +92,20 @@ def total_envy
|
|
92
92
|
total += fred.tax
|
93
93
|
end
|
94
94
|
EOS
|
95
|
-
src.
|
96
|
-
src.
|
95
|
+
expect(src).to reek_of(:FeatureEnvy, /total/)
|
96
|
+
expect(src).to reek_of(:FeatureEnvy, /fred/)
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should not be fooled by duplication' do
|
100
|
-
'def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end'.
|
100
|
+
expect('def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'should count local calls' do
|
104
|
-
'def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end'.
|
104
|
+
expect('def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should report many calls to lvar' do
|
108
|
-
'def envy() lv = @item; lv.price + lv.tax; end'.
|
108
|
+
expect('def envy() lv = @item; lv.price + lv.tax; end').to reek_only_of(:FeatureEnvy, /lv/)
|
109
109
|
#
|
110
110
|
# def moved_version
|
111
111
|
# price + tax
|
@@ -117,7 +117,7 @@ EOS
|
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'ignores frequent use of a call' do
|
120
|
-
'def func() other.a; other.b; nother.c end'.
|
120
|
+
expect('def func() other.a; other.b; nother.c end').not_to reek_of(:FeatureEnvy)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'counts self references correctly' do
|
@@ -130,7 +130,7 @@ def adopt(other)
|
|
130
130
|
self
|
131
131
|
end
|
132
132
|
EOS
|
133
|
-
src.
|
133
|
+
expect(src).not_to reek
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -147,7 +147,7 @@ def report
|
|
147
147
|
@report
|
148
148
|
end
|
149
149
|
EOS
|
150
|
-
ruby.
|
150
|
+
expect(ruby).not_to reek
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'interprets << correctly' do
|
@@ -161,7 +161,7 @@ def report_on(report)
|
|
161
161
|
end
|
162
162
|
EOS
|
163
163
|
|
164
|
-
ruby.
|
164
|
+
expect(ruby).not_to reek
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -190,26 +190,26 @@ EOS
|
|
190
190
|
@smells = @detector.examine_context(@mctx)
|
191
191
|
end
|
192
192
|
it 'reports only that smell' do
|
193
|
-
@smells.length.
|
193
|
+
expect(@smells.length).to eq(1)
|
194
194
|
end
|
195
195
|
it 'reports the source' do
|
196
|
-
@smells[0].source.
|
196
|
+
expect(@smells[0].source).to eq(@source_name)
|
197
197
|
end
|
198
198
|
it 'reports the class' do
|
199
|
-
@smells[0].smell_class.
|
199
|
+
expect(@smells[0].smell_class).to eq(FeatureEnvy::SMELL_CLASS)
|
200
200
|
end
|
201
201
|
it 'reports the subclass' do
|
202
|
-
@smells[0].subclass.
|
202
|
+
expect(@smells[0].subclass).to eq(FeatureEnvy::SMELL_SUBCLASS)
|
203
203
|
end
|
204
204
|
it 'reports the envious receiver' do
|
205
|
-
@smells[0].smell[FeatureEnvy::RECEIVER_KEY].
|
205
|
+
expect(@smells[0].smell[FeatureEnvy::RECEIVER_KEY]).to eq(@receiver)
|
206
206
|
end
|
207
207
|
it 'reports the number of references' do
|
208
|
-
@smells[0].smell[FeatureEnvy::REFERENCES_KEY].
|
208
|
+
expect(@smells[0].smell[FeatureEnvy::REFERENCES_KEY]).to eq(3)
|
209
209
|
end
|
210
210
|
it 'reports the referring lines' do
|
211
|
-
|
212
|
-
@smells[0].lines.
|
211
|
+
skip
|
212
|
+
expect(@smells[0].lines).to eq([2, 4, 5])
|
213
213
|
end
|
214
214
|
end
|
215
215
|
end
|