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,98 +1,111 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
require_lib 'reek/smells/class_variable'
|
3
|
-
require_lib 'reek/context/module_context'
|
4
|
-
require_relative 'smell_detector_shared'
|
5
3
|
|
6
4
|
RSpec.describe Reek::Smells::ClassVariable do
|
7
|
-
|
8
|
-
|
5
|
+
it 'reports the right values' do
|
6
|
+
src = <<-EOS
|
7
|
+
class Alfa
|
8
|
+
@@bravo = 5
|
9
|
+
end
|
10
|
+
EOS
|
9
11
|
|
10
|
-
|
12
|
+
expect(src).to reek_of(:ClassVariable,
|
13
|
+
lines: [2],
|
14
|
+
context: 'Alfa',
|
15
|
+
message: "declares the class variable '@@bravo'",
|
16
|
+
source: 'string',
|
17
|
+
name: '@@bravo')
|
18
|
+
end
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
it 'does count all class variables' do
|
21
|
+
src = <<-EOS
|
22
|
+
class Alfa
|
23
|
+
@@bravo = 42
|
24
|
+
@@charlie = 99
|
25
|
+
end
|
26
|
+
EOS
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
expect(detector.sniff(Reek::Context::CodeContext.new(nil, exp))).to be_empty
|
21
|
-
end
|
28
|
+
expect(src).to reek_of(:ClassVariable, name: '@@bravo')
|
29
|
+
expect(src).to reek_of(:ClassVariable, name: '@@charlie')
|
22
30
|
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
it 'records only that class variable' do
|
30
|
-
expect(smells.length).to eq(1)
|
32
|
+
it 'does not report class instance variables' do
|
33
|
+
src = <<-EOS
|
34
|
+
class Alfa
|
35
|
+
@bravo = 42
|
31
36
|
end
|
37
|
+
EOS
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
39
|
+
expect(src).to_not reek_of(:ClassVariable)
|
40
|
+
end
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
context 'with no class variables' do
|
43
|
+
it 'records nothing in the class' do
|
44
|
+
src = <<-EOS
|
45
|
+
class Alfa
|
46
|
+
def bravo; end
|
47
|
+
end
|
48
|
+
EOS
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
it_should_behave_like 'one variable found'
|
47
|
-
end
|
50
|
+
expect(src).to_not reek_of(:ClassVariable)
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
it 'records nothing in the module' do
|
54
|
+
src = <<-EOS
|
55
|
+
module Alfa
|
56
|
+
def bravo; end
|
57
|
+
end
|
58
|
+
EOS
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
expect(src).to_not reek_of(:ClassVariable)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
['class', 'module'].each do |scope|
|
65
|
+
context "Scoped to #{scope}" do
|
66
|
+
context 'set in a method' do
|
67
|
+
it 'reports correctly' do
|
68
|
+
src = <<-EOS
|
69
|
+
#{scope} Alfa
|
70
|
+
def bravo
|
71
|
+
@@charlie = {}
|
72
|
+
end
|
60
73
|
end
|
61
74
|
EOS
|
75
|
+
|
76
|
+
expect(src).to reek_of(:ClassVariable)
|
62
77
|
end
|
63
|
-
it_should_behave_like 'one variable found'
|
64
78
|
end
|
65
79
|
|
66
|
-
context
|
67
|
-
|
68
|
-
<<-EOS
|
69
|
-
#{scope}
|
70
|
-
def
|
71
|
-
|
80
|
+
context 'used in a method' do
|
81
|
+
it 'reports correctly' do
|
82
|
+
src = <<-EOS
|
83
|
+
#{scope} Alfa
|
84
|
+
def bravo
|
85
|
+
puts @@charlie
|
86
|
+
end
|
72
87
|
end
|
73
88
|
EOS
|
89
|
+
|
90
|
+
expect(src).to reek_of(:ClassVariable)
|
74
91
|
end
|
75
|
-
it_should_behave_like 'one variable found'
|
76
92
|
end
|
77
|
-
end
|
78
|
-
end
|
79
93
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
86
|
-
EOS
|
87
|
-
ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
88
|
-
detector.sniff(ctx).first
|
89
|
-
end
|
94
|
+
context "set in #{scope} and used in a method" do
|
95
|
+
it 'reports correctly' do
|
96
|
+
src = <<-EOS
|
97
|
+
#{scope} Alfa
|
98
|
+
@@bravo = 42
|
90
99
|
|
91
|
-
|
100
|
+
def charlie
|
101
|
+
puts @@bravo
|
102
|
+
end
|
103
|
+
end
|
104
|
+
EOS
|
92
105
|
|
93
|
-
|
94
|
-
|
95
|
-
|
106
|
+
expect(src).to reek_of(:ClassVariable)
|
107
|
+
end
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
98
111
|
end
|
@@ -1,292 +1,252 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
require_lib 'reek/smells/control_parameter'
|
3
|
-
require_relative 'smell_detector_shared'
|
4
3
|
|
5
4
|
RSpec.describe Reek::Smells::ControlParameter do
|
6
|
-
|
5
|
+
it 'reports the right values' do
|
6
|
+
src = <<-EOS
|
7
|
+
def alfa(bravo)
|
8
|
+
bravo ? true : false
|
9
|
+
end
|
10
|
+
EOS
|
11
|
+
|
12
|
+
expect(src).to reek_of(:ControlParameter,
|
13
|
+
lines: [2],
|
14
|
+
context: 'alfa',
|
15
|
+
message: "is controlled by argument 'bravo'",
|
16
|
+
source: 'string',
|
17
|
+
argument: 'bravo')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does count all occurences' do
|
21
|
+
src = <<-EOS
|
22
|
+
def alfa(bravo, charlie)
|
23
|
+
bravo ? true : false
|
24
|
+
charlie ? true : false
|
25
|
+
end
|
26
|
+
EOS
|
7
27
|
|
8
|
-
|
28
|
+
expect(src).to reek_of(:ControlParameter, lines: [2], argument: 'bravo')
|
29
|
+
expect(src).to reek_of(:ControlParameter, lines: [3], argument: 'charlie')
|
30
|
+
end
|
9
31
|
|
10
32
|
context 'parameter not used to determine code path' do
|
11
33
|
it 'does not report a ternary check on an ivar' do
|
12
|
-
src = 'def
|
34
|
+
src = 'def alfa(bravo) @charlie ? bravo : false end'
|
13
35
|
expect(src).not_to reek_of(:ControlParameter)
|
14
36
|
end
|
15
37
|
|
16
38
|
it 'does not report a ternary check on a lvar' do
|
17
|
-
src = 'def
|
39
|
+
src = 'def alfa(bravo) charlie = 27; charlie ? bravo : @delta end'
|
18
40
|
expect(src).not_to reek_of(:ControlParameter)
|
19
41
|
end
|
20
42
|
|
21
43
|
it 'does not report when parameter is unused' do
|
22
|
-
src = 'def
|
44
|
+
src = 'def alfa(bravo) charlie = 1 end'
|
23
45
|
expect(src).not_to reek_of(:ControlParameter)
|
24
46
|
end
|
25
47
|
|
26
48
|
it 'does not report when parameter is used inside conditional' do
|
27
|
-
src = 'def
|
49
|
+
src = 'def alfa(bravo) if true then puts bravo end end'
|
28
50
|
expect(src).not_to reek_of(:ControlParameter)
|
29
51
|
end
|
30
52
|
end
|
31
53
|
|
32
54
|
context 'parameter only used to determine code path' do
|
33
55
|
it 'reports a ternary check on a parameter' do
|
34
|
-
src = 'def
|
35
|
-
expect(src).to reek_of(:ControlParameter
|
56
|
+
src = 'def alfa(bravo); bravo ? true : false; end'
|
57
|
+
expect(src).to reek_of(:ControlParameter)
|
36
58
|
end
|
37
59
|
|
38
60
|
it 'reports a couple inside a block' do
|
39
|
-
src = 'def
|
40
|
-
expect(src).to reek_of(:ControlParameter
|
61
|
+
src = 'def alfa(bravo); charlie.map { |delta| bravo ? delta : "#{delta}" }; end'
|
62
|
+
expect(src).to reek_of(:ControlParameter)
|
41
63
|
end
|
42
64
|
|
43
65
|
it 'reports on an if statement modifier' do
|
44
|
-
src = 'def
|
45
|
-
expect(src).to reek_of(:ControlParameter
|
66
|
+
src = 'def alfa(bravo); charlie if bravo; end'
|
67
|
+
expect(src).to reek_of(:ControlParameter)
|
46
68
|
end
|
47
69
|
|
48
70
|
it 'reports on an unless statement modifier' do
|
49
|
-
src = 'def
|
50
|
-
expect(src).to reek_of(:ControlParameter
|
71
|
+
src = 'def alfa(bravo); charlie unless bravo; end'
|
72
|
+
expect(src).to reek_of(:ControlParameter)
|
51
73
|
end
|
52
74
|
|
53
75
|
it 'reports on if control expression' do
|
54
|
-
src = 'def
|
55
|
-
expect(src).to reek_of(:ControlParameter
|
76
|
+
src = 'def alfa(bravo); if bravo then charlie end; end'
|
77
|
+
expect(src).to reek_of(:ControlParameter)
|
56
78
|
end
|
57
79
|
|
58
80
|
it 'reports on if control expression with &&' do
|
59
|
-
src = 'def
|
60
|
-
expect(src).to reek_of(:ControlParameter
|
81
|
+
src = 'def alfa(bravo); if bravo && true then charlie end; end'
|
82
|
+
expect(src).to reek_of(:ControlParameter)
|
61
83
|
end
|
62
84
|
|
63
|
-
it 'reports on if control expression with
|
64
|
-
src = 'def
|
65
|
-
expect(src).to reek_of(:ControlParameter
|
85
|
+
it 'reports on if control expression with `and`' do
|
86
|
+
src = 'def alfa(bravo); if bravo and true then charlie end; end'
|
87
|
+
expect(src).to reek_of(:ControlParameter)
|
66
88
|
end
|
67
89
|
|
68
|
-
it 'reports on if control expression with
|
69
|
-
src = 'def
|
70
|
-
expect(src).to reek_of(:ControlParameter
|
90
|
+
it 'reports on if control expression with preceding &&' do
|
91
|
+
src = 'def alfa(bravo); if true && bravo then charlie end; end'
|
92
|
+
expect(src).to reek_of(:ControlParameter)
|
71
93
|
end
|
72
94
|
|
73
95
|
it 'reports on if control expression with ||' do
|
74
|
-
src = 'def
|
75
|
-
expect(src).to reek_of(:ControlParameter
|
96
|
+
src = 'def alfa(bravo); if bravo || true then charlie end; end'
|
97
|
+
expect(src).to reek_of(:ControlParameter)
|
76
98
|
end
|
77
99
|
|
78
100
|
it 'reports on if control expression with or' do
|
79
|
-
src = 'def
|
80
|
-
expect(src).to reek_of(:ControlParameter
|
101
|
+
src = 'def alfa(bravo); if bravo or true then charlie end; end'
|
102
|
+
expect(src).to reek_of(:ControlParameter)
|
81
103
|
end
|
82
104
|
|
83
105
|
it 'reports on if control expression with if' do
|
84
|
-
src = 'def
|
85
|
-
expect(src).to reek_of(:ControlParameter
|
106
|
+
src = 'def alfa(bravo); if (bravo if true) then charlie end; end'
|
107
|
+
expect(src).to reek_of(:ControlParameter)
|
86
108
|
end
|
87
109
|
|
88
110
|
it 'reports on && notation' do
|
89
|
-
src = 'def
|
90
|
-
expect(src).to reek_of(:ControlParameter
|
111
|
+
src = 'def alfa(bravo); bravo && charlie; end'
|
112
|
+
expect(src).to reek_of(:ControlParameter)
|
91
113
|
end
|
92
114
|
|
93
115
|
it 'reports on || notation' do
|
94
|
-
src = 'def
|
95
|
-
expect(src).to reek_of(:ControlParameter
|
116
|
+
src = 'def alfa(bravo); bravo || charlie; end'
|
117
|
+
expect(src).to reek_of(:ControlParameter)
|
96
118
|
end
|
97
119
|
|
98
120
|
it 'reports on case statement' do
|
99
|
-
src =
|
100
|
-
|
121
|
+
src = <<-EOS
|
122
|
+
def alfa(bravo)
|
123
|
+
case bravo
|
124
|
+
when nil then nil
|
125
|
+
else false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
EOS
|
129
|
+
|
130
|
+
expect(src).to reek_of(:ControlParameter)
|
101
131
|
end
|
102
132
|
|
103
|
-
it 'reports on nested if statements that are both control parameters' do
|
133
|
+
it 'reports on nested if statements that are both using control parameters' do
|
104
134
|
src = <<-EOS
|
105
|
-
def nested(
|
106
|
-
if
|
107
|
-
|
108
|
-
|
135
|
+
def nested(bravo)
|
136
|
+
if bravo
|
137
|
+
charlie
|
138
|
+
charlie if bravo
|
109
139
|
end
|
110
140
|
end
|
111
141
|
EOS
|
112
|
-
|
142
|
+
|
143
|
+
expect(src).to reek_of(:ControlParameter)
|
113
144
|
end
|
114
145
|
|
115
146
|
it 'reports on nested if statements where the inner if is a control parameter' do
|
116
147
|
src = <<-EOS
|
117
|
-
def nested(
|
148
|
+
def nested(bravo)
|
118
149
|
if true
|
119
|
-
|
120
|
-
|
150
|
+
charlie
|
151
|
+
charlie if bravo
|
121
152
|
end
|
122
153
|
end
|
123
154
|
EOS
|
124
|
-
|
155
|
+
|
156
|
+
expect(src).to reek_of(:ControlParameter)
|
125
157
|
end
|
126
158
|
|
127
159
|
it 'reports on explicit comparison in the condition' do
|
128
|
-
src = 'def
|
160
|
+
src = 'def alfa(bravo); if bravo == charlie then charlie end; end'
|
129
161
|
expect(src).to reek_of(:ControlParameter)
|
130
162
|
end
|
131
163
|
|
132
164
|
it 'reports on explicit negative comparison in the condition' do
|
133
|
-
src = 'def
|
165
|
+
src = 'def alfa(bravo); if bravo != charlie then charlie end; end'
|
134
166
|
expect(src).to reek_of(:ControlParameter)
|
135
167
|
end
|
136
168
|
|
137
169
|
it 'reports when the argument is compared to a regexp' do
|
138
|
-
src = 'def
|
170
|
+
src = 'def alfa(bravo); if bravo =~ charlie then charlie end; end'
|
139
171
|
expect(src).to reek_of(:ControlParameter)
|
140
172
|
end
|
141
173
|
|
142
174
|
it 'reports when the argument is reverse-compared to a regexp' do
|
143
|
-
src = 'def
|
175
|
+
src = 'def alfa(bravo); if /charlie/ =~ bravo then charlie end; end'
|
144
176
|
expect(src).to reek_of(:ControlParameter)
|
145
177
|
end
|
146
178
|
|
147
179
|
it 'reports when the argument is used in a complex regexp' do
|
148
|
-
src = 'def
|
180
|
+
src = 'def alfa(bravo); if /charlie#{bravo}/ =~ delta then charlie end; end'
|
149
181
|
expect(src).to reek_of(:ControlParameter)
|
150
182
|
end
|
151
183
|
|
152
184
|
it 'reports when the argument is a block parameter' do
|
153
|
-
src =
|
154
|
-
def foo &blk
|
155
|
-
bar(blk || proc {})
|
156
|
-
end
|
157
|
-
EOS
|
185
|
+
src = 'def bravo(&charlie); delta(charlie || proc {}); end'
|
158
186
|
expect(src).to reek_of(:ControlParameter)
|
159
187
|
end
|
160
188
|
end
|
161
189
|
|
162
190
|
context 'parameter used besides determining code path' do
|
163
191
|
it 'does not report on if conditional expression' do
|
164
|
-
src = 'def
|
192
|
+
src = 'def alfa(bravo); if bravo then charlie(bravo); end end'
|
165
193
|
expect(src).not_to reek_of(:ControlParameter)
|
166
194
|
end
|
167
195
|
|
168
196
|
it 'does not report on an if statement modifier' do
|
169
|
-
src = 'def
|
197
|
+
src = 'def alfa(bravo); charlie(bravo) if bravo; end'
|
170
198
|
expect(src).not_to reek_of(:ControlParameter)
|
171
199
|
end
|
172
200
|
|
173
201
|
it 'does not report on an unless statement modifier' do
|
174
|
-
src = 'def
|
175
|
-
expect(src).not_to reek_of(:ControlParameter)
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'does not report on if control expression' do
|
179
|
-
src = 'def simple(arg) args = {}; if arg then args.merge(\'a\' => arg) end end'
|
202
|
+
src = 'def alfa(bravo); charlie(bravo) unless bravo; end'
|
180
203
|
expect(src).not_to reek_of(:ControlParameter)
|
181
204
|
end
|
182
205
|
|
183
206
|
it 'does not report on if control expression with &&' do
|
184
|
-
src = 'def
|
207
|
+
src = 'def alfa(bravo) if bravo && true then puts bravo end end'
|
185
208
|
expect(src).not_to reek_of(:ControlParameter)
|
186
209
|
end
|
187
210
|
|
188
211
|
it 'does not report on && notation' do
|
189
|
-
src = 'def
|
212
|
+
src = 'def alfa(bravo); bravo && charlie(bravo); end'
|
190
213
|
expect(src).not_to reek_of(:ControlParameter)
|
191
214
|
end
|
192
215
|
|
193
216
|
it 'does not report on || notation' do
|
194
|
-
src = 'def
|
217
|
+
src = 'def alfa(bravo); bravo || charlie(bravo) end'
|
195
218
|
expect(src).not_to reek_of(:ControlParameter)
|
196
219
|
end
|
197
220
|
|
198
221
|
it 'does not report when parameter is used outside conditional' do
|
199
|
-
src = 'def
|
222
|
+
src = 'def alfa(bravo) puts bravo; if bravo then charlie end; end'
|
200
223
|
expect(src).not_to reek_of(:ControlParameter)
|
201
224
|
end
|
202
225
|
|
203
226
|
it 'does not report when parameter is used as a method call argument in a condition' do
|
204
|
-
src = 'def
|
227
|
+
src = 'def alfa(bravo); if charlie(bravo) then delta end; end'
|
205
228
|
expect(src).not_to reek_of(:ControlParameter)
|
206
229
|
end
|
207
230
|
|
208
231
|
it 'does not report when parameter is used as a method call receiver in a condition' do
|
209
|
-
src = 'def
|
210
|
-
expect(src).not_to reek_of(:ControlParameter)
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'does not report when the argument is a hash on which we access a key' do
|
214
|
-
src = 'def simple(arg) if arg[\'a\'] then puts \'a\' else puts \'b\' end end'
|
215
|
-
expect(src).not_to reek_of :ControlParameter
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'does not report when used in first conditional but not second' do
|
219
|
-
src = <<-EOS
|
220
|
-
def things(arg)
|
221
|
-
if arg
|
222
|
-
puts arg
|
223
|
-
end
|
224
|
-
if arg
|
225
|
-
puts 'a'
|
226
|
-
end
|
227
|
-
end
|
228
|
-
EOS
|
229
|
-
expect(src).not_to reek_of(:ControlParameter)
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'does not report when used in second conditional but not first' do
|
233
|
-
src = <<-EOS
|
234
|
-
def things(arg)
|
235
|
-
if arg
|
236
|
-
puts 'a'
|
237
|
-
end
|
238
|
-
if arg
|
239
|
-
puts arg
|
240
|
-
end
|
241
|
-
end
|
242
|
-
EOS
|
232
|
+
src = 'def alfa(bravo); if bravo.charlie? then delta end; end'
|
243
233
|
expect(src).not_to reek_of(:ControlParameter)
|
244
234
|
end
|
245
235
|
|
246
236
|
it 'does not report when used in body of control flow operator' do
|
247
237
|
src = <<-EOS
|
248
|
-
def
|
249
|
-
case
|
250
|
-
when :
|
251
|
-
puts '
|
238
|
+
def alfa(bravo)
|
239
|
+
case bravo
|
240
|
+
when :charlie
|
241
|
+
puts 'charlie'
|
252
242
|
else
|
253
|
-
puts '
|
254
|
-
end
|
255
|
-
qux or quuz(arg)
|
256
|
-
end
|
257
|
-
EOS
|
258
|
-
expect(src).not_to reek_of(:ControlParameter)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context 'when a smell is reported' do
|
263
|
-
let(:warning) do
|
264
|
-
src = <<-EOS
|
265
|
-
def things(arg)
|
266
|
-
@text.map do |blk|
|
267
|
-
arg ? blk : "blk"
|
243
|
+
puts 'delta'
|
268
244
|
end
|
269
|
-
|
245
|
+
echo or foxtrot(bravo)
|
270
246
|
end
|
271
247
|
EOS
|
272
|
-
ctx = Reek::Context::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
273
|
-
smells = detector.run_for(ctx)
|
274
|
-
expect(smells.length).to eq(1)
|
275
|
-
smells.first
|
276
|
-
end
|
277
|
-
|
278
|
-
it_should_behave_like 'common fields set correctly'
|
279
|
-
|
280
|
-
it 'reports the argument' do
|
281
|
-
expect(warning.parameters[:argument]).to eq('arg')
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'reports the lines' do
|
285
|
-
expect(warning.lines).to eq([3, 5])
|
286
|
-
end
|
287
248
|
|
288
|
-
|
289
|
-
expect(warning.message).to eq('is controlled by argument arg')
|
249
|
+
expect(src).not_to reek_of(:ControlParameter)
|
290
250
|
end
|
291
251
|
end
|
292
252
|
end
|