reek 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/README.md +54 -5
- data/Rakefile +1 -1
- data/features/command_line_interface/smell_selection.feature +4 -4
- data/features/command_line_interface/smells_count.feature +9 -8
- data/features/configuration_files/masking_smells.feature +16 -51
- data/features/configuration_files/overrides_defaults.feature +1 -1
- data/features/rake_task/rake_task.feature +14 -14
- data/features/reports/reports.feature +21 -19
- data/features/reports/yaml.feature +35 -63
- data/features/samples.feature +55 -54
- data/features/support/env.rb +8 -1
- data/lib/reek/cli/application.rb +22 -7
- data/lib/reek/cli/command.rb +4 -2
- data/lib/reek/cli/help_command.rb +1 -1
- data/lib/reek/cli/options.rb +3 -3
- data/lib/reek/cli/reek_command.rb +4 -8
- data/lib/reek/cli/report/formatter.rb +8 -5
- data/lib/reek/cli/report/report.rb +6 -5
- data/lib/reek/cli/report/strategy.rb +3 -2
- data/lib/reek/cli/version_command.rb +1 -1
- data/lib/reek/configuration/app_configuration.rb +75 -0
- data/lib/reek/configuration/configuration_file_finder.rb +56 -0
- data/lib/reek/core/code_context.rb +2 -6
- data/lib/reek/core/module_context.rb +4 -0
- data/lib/reek/core/smell_repository.rb +5 -3
- data/lib/reek/core/sniffer.rb +12 -8
- data/lib/reek/examiner.rb +7 -6
- data/lib/reek/rake/task.rb +10 -12
- data/lib/reek/smell_warning.rb +25 -43
- data/lib/reek/smells/attribute.rb +7 -12
- data/lib/reek/smells/boolean_parameter.rb +9 -9
- data/lib/reek/smells/class_variable.rb +7 -13
- data/lib/reek/smells/control_parameter.rb +8 -11
- data/lib/reek/smells/data_clump.rb +16 -21
- data/lib/reek/smells/duplicate_method_call.rb +11 -18
- data/lib/reek/smells/feature_envy.rb +8 -8
- data/lib/reek/smells/irresponsible_module.rb +6 -10
- data/lib/reek/smells/long_parameter_list.rb +7 -15
- data/lib/reek/smells/long_yield_list.rb +13 -15
- data/lib/reek/smells/module_initialize.rb +4 -7
- data/lib/reek/smells/nested_iterators.rb +6 -13
- data/lib/reek/smells/nil_check.rb +9 -7
- data/lib/reek/smells/prima_donna_method.rb +5 -7
- data/lib/reek/smells/repeated_conditional.rb +19 -15
- data/lib/reek/smells/smell_detector.rb +21 -1
- data/lib/reek/smells/too_many_instance_variables.rb +9 -16
- data/lib/reek/smells/too_many_methods.rb +10 -17
- data/lib/reek/smells/too_many_statements.rb +14 -14
- data/lib/reek/smells/uncommunicative_method_name.rb +9 -10
- data/lib/reek/smells/uncommunicative_module_name.rb +9 -10
- data/lib/reek/smells/uncommunicative_parameter_name.rb +9 -9
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -9
- data/lib/reek/smells/unused_parameters.rb +8 -20
- data/lib/reek/smells/utility_function.rb +12 -10
- data/lib/reek/source.rb +0 -1
- data/lib/reek/source/code_comment.rb +1 -0
- data/lib/reek/source/source_code.rb +3 -13
- data/lib/reek/source/source_file.rb +0 -14
- data/lib/reek/source/source_repository.rb +7 -0
- data/lib/reek/spec/should_reek_of.rb +3 -3
- data/lib/reek/spec/should_reek_only_of.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +4 -2
- data/spec/factories/factories.rb +32 -0
- data/spec/matchers/smell_of_matcher.rb +3 -2
- data/spec/reek/cli/report_spec.rb +2 -1
- data/spec/reek/configuration/app_configuration_spec.rb +67 -0
- data/spec/reek/configuration/configuration_file_finder_spec.rb +35 -0
- data/spec/reek/core/code_context_spec.rb +1 -1
- data/spec/reek/core/module_context_spec.rb +5 -1
- data/spec/reek/core/smell_configuration_spec.rb +21 -13
- data/spec/reek/core/warning_collector_spec.rb +4 -1
- data/spec/reek/examiner_spec.rb +19 -1
- data/spec/reek/smell_warning_spec.rb +42 -36
- data/spec/reek/smells/attribute_spec.rb +6 -2
- data/spec/reek/smells/boolean_parameter_spec.rb +11 -12
- data/spec/reek/smells/class_variable_spec.rb +16 -6
- data/spec/reek/smells/control_parameter_spec.rb +17 -19
- data/spec/reek/smells/data_clump_spec.rb +25 -15
- data/spec/reek/smells/duplicate_method_call_spec.rb +18 -12
- data/spec/reek/smells/feature_envy_spec.rb +29 -10
- data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
- data/spec/reek/smells/long_parameter_list_spec.rb +16 -10
- data/spec/reek/smells/long_yield_list_spec.rb +2 -2
- data/spec/reek/smells/module_initialize_spec.rb +26 -0
- data/spec/reek/smells/nested_iterators_spec.rb +21 -10
- data/spec/reek/smells/nil_check_spec.rb +0 -2
- data/spec/reek/smells/prima_donna_method_spec.rb +3 -3
- data/spec/reek/smells/repeated_conditional_spec.rb +0 -26
- data/spec/reek/smells/smell_detector_shared.rb +4 -4
- data/spec/reek/smells/too_many_instance_variables_spec.rb +3 -3
- data/spec/reek/smells/too_many_methods_spec.rb +16 -11
- data/spec/reek/smells/too_many_statements_spec.rb +55 -18
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -2
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -21
- data/spec/reek/smells/unused_parameters_spec.rb +3 -5
- data/spec/reek/smells/utility_function_spec.rb +2 -1
- data/spec/reek/source/code_comment_spec.rb +7 -2
- data/spec/reek/source/reference_collector_spec.rb +0 -1
- data/spec/reek/source/sexp_extensions_spec.rb +0 -15
- data/spec/reek/source/source_code_spec.rb +13 -1
- data/spec/reek/spec/should_reek_only_of_spec.rb +22 -10
- data/spec/reek/spec/should_reek_spec.rb +6 -2
- data/spec/samples/minimal_smelly_and_masked/config.reek +7 -0
- data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +4 -0
- data/spec/samples/simple_configuration.reek +5 -0
- data/spec/samples/standard_smelly/dirty.rb +8 -0
- data/spec/samples/standard_smelly/minimal_dirty.rb +4 -0
- data/spec/spec_helper.rb +20 -0
- data/tasks/develop.rake +1 -1
- data/tasks/rubocop.rake +5 -0
- metadata +41 -6
- data/lib/reek/config_file_exception.rb +0 -7
- data/lib/reek/smell_description.rb +0 -26
- data/lib/reek/source/config_file.rb +0 -88
- data/spec/reek/smell_description_spec.rb +0 -43
@@ -26,7 +26,7 @@ describe LongYieldList do
|
|
26
26
|
end
|
27
27
|
it 'should report yield with many parameters' do
|
28
28
|
src = 'def simple(arga, argb, &blk) f(3);yield arga,argb,arga,argb; end'
|
29
|
-
expect(src).to smell_of(LongYieldList,
|
29
|
+
expect(src).to smell_of(LongYieldList, count: 4)
|
30
30
|
end
|
31
31
|
it 'should not report yield of a long expression' do
|
32
32
|
src = 'def simple(arga, argb, &blk) f(3);yield(if @dec then argb else 5+3 end); end'
|
@@ -50,7 +50,7 @@ EOS
|
|
50
50
|
it_should_behave_like 'common fields set correctly'
|
51
51
|
|
52
52
|
it 'reports the correct values' do
|
53
|
-
expect(@warning.
|
53
|
+
expect(@warning.parameters[:count]).to eq(4)
|
54
54
|
expect(@warning.lines).to eq([3])
|
55
55
|
end
|
56
56
|
end
|
@@ -16,5 +16,31 @@ describe ModuleInitialize do
|
|
16
16
|
expect(src).to smell_of(ModuleInitialize)
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
context 'with method named initialize in a nested class' do
|
21
|
+
it 'does not smell' do
|
22
|
+
src = <<-EOF
|
23
|
+
module A
|
24
|
+
class B
|
25
|
+
def initialize; end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
expect(src).not_to smell_of(ModuleInitialize)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with method named initialize in a nested struct' do
|
34
|
+
it 'does not smell' do
|
35
|
+
src = <<-EOF
|
36
|
+
module A
|
37
|
+
B = Struct.new(:c) do
|
38
|
+
def initialize; end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
EOF
|
42
|
+
expect(src).not_to smell_of(ModuleInitialize)
|
43
|
+
end
|
44
|
+
end
|
19
45
|
end
|
20
46
|
end
|
@@ -5,7 +5,6 @@ require 'reek/smells/smell_detector_shared'
|
|
5
5
|
include Reek::Smells
|
6
6
|
|
7
7
|
describe NestedIterators do
|
8
|
-
|
9
8
|
context 'with no iterators' do
|
10
9
|
it 'reports no smells' do
|
11
10
|
src = 'def fred() nothing = true; end'
|
@@ -85,7 +84,7 @@ EOS
|
|
85
84
|
) { |qux| qux.quuz }
|
86
85
|
end
|
87
86
|
EOS
|
88
|
-
expect(src).to smell_of(NestedIterators,
|
87
|
+
expect(src).to smell_of(NestedIterators, count: 2)
|
89
88
|
end
|
90
89
|
|
91
90
|
it 'reports the deepest level of nesting only' do
|
@@ -98,7 +97,7 @@ EOS
|
|
98
97
|
}
|
99
98
|
end
|
100
99
|
EOS
|
101
|
-
expect(src).to smell_of(NestedIterators,
|
100
|
+
expect(src).to smell_of(NestedIterators, count: 3)
|
102
101
|
end
|
103
102
|
|
104
103
|
context 'when the allowed nesting depth is 3' do
|
@@ -150,18 +149,30 @@ EOS
|
|
150
149
|
end
|
151
150
|
|
152
151
|
it 'should report nested iterators inside the ignored iterator' do
|
153
|
-
src = '
|
154
|
-
|
152
|
+
src = '
|
153
|
+
def bad(fred)
|
154
|
+
@fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } }
|
155
|
+
end
|
156
|
+
'
|
157
|
+
expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
|
155
158
|
end
|
156
159
|
|
157
160
|
it 'should report nested iterators outside the ignored iterator' do
|
158
|
-
src = '
|
159
|
-
|
161
|
+
src = '
|
162
|
+
def bad(fred)
|
163
|
+
@fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } }
|
164
|
+
end
|
165
|
+
'
|
166
|
+
expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
|
160
167
|
end
|
161
168
|
|
162
169
|
it 'should report nested iterators with the ignored iterator between them' do
|
163
|
-
src = '
|
164
|
-
|
170
|
+
src = '
|
171
|
+
def bad(fred)
|
172
|
+
@fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } }
|
173
|
+
end
|
174
|
+
'
|
175
|
+
expect(src).to smell_of(NestedIterators, count: 2).with_config(@config)
|
165
176
|
end
|
166
177
|
end
|
167
178
|
end
|
@@ -190,7 +201,7 @@ EOS
|
|
190
201
|
it_should_behave_like 'common fields set correctly'
|
191
202
|
|
192
203
|
it 'reports correct values' do
|
193
|
-
expect(@warning.
|
204
|
+
expect(@warning.parameters[:count]).to eq(2)
|
194
205
|
expect(@warning.lines).to eq([3])
|
195
206
|
end
|
196
207
|
end
|
@@ -17,14 +17,14 @@ describe PrimaDonnaMethod do
|
|
17
17
|
describe 'the right smell' do
|
18
18
|
let(:detector) { PrimaDonnaMethod.new('dummy_source') }
|
19
19
|
let(:src) { 'class C; def m!; end; end' }
|
20
|
-
let(:ctx) {
|
20
|
+
let(:ctx) { ModuleContext.new(nil, src.to_reek_source.syntax_tree) }
|
21
21
|
|
22
22
|
it 'should be reported' do
|
23
23
|
smells = detector.examine_context(ctx)
|
24
24
|
warning = smells[0]
|
25
25
|
|
26
|
-
expect(warning.
|
27
|
-
expect(warning.
|
26
|
+
expect(warning.smell_category).to eq('PrimaDonnaMethod')
|
27
|
+
expect(warning.smell_type).to eq('PrimaDonnaMethod')
|
28
28
|
expect(warning.lines).to eq([1])
|
29
29
|
end
|
30
30
|
end
|
@@ -75,32 +75,6 @@ EOS
|
|
75
75
|
it 'knows there are three copies' do
|
76
76
|
expect(@conds.values[1].length).to eq(3)
|
77
77
|
end
|
78
|
-
|
79
|
-
context 'looking at the YAML' do
|
80
|
-
before :each do
|
81
|
-
@detector.examine(@ctx)
|
82
|
-
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
83
|
-
@yaml = warning.to_yaml
|
84
|
-
end
|
85
|
-
it 'reports the source' do
|
86
|
-
expect(@yaml).to match(/source:\s*#{@source_name}/)
|
87
|
-
end
|
88
|
-
it 'reports the class' do
|
89
|
-
expect(@yaml).to match(/class:\s*SimulatedPolymorphism/)
|
90
|
-
end
|
91
|
-
it 'reports the subclass' do
|
92
|
-
expect(@yaml).to match(/subclass:\s*RepeatedConditional/)
|
93
|
-
end
|
94
|
-
it 'reports the expression' do
|
95
|
-
expect(@yaml).to match(/expression:\s*(! )?['"]?#{@cond}["']?/)
|
96
|
-
end
|
97
|
-
it 'reports the number of occurrences' do
|
98
|
-
expect(@yaml).to match(/occurrences:\s*3/)
|
99
|
-
end
|
100
|
-
it 'reports the referring lines' do
|
101
|
-
expect(@yaml).to match(/lines:\s*- 4\s*- 7\s*- 12/)
|
102
|
-
end
|
103
|
-
end
|
104
78
|
end
|
105
79
|
|
106
80
|
context 'with a matching if and case' do
|
@@ -32,10 +32,10 @@ shared_examples_for 'common fields set correctly' do
|
|
32
32
|
it 'reports the source' do
|
33
33
|
expect(@warning.source).to eq(@source_name)
|
34
34
|
end
|
35
|
-
it 'reports the class' do
|
36
|
-
expect(@warning.
|
35
|
+
it 'reports the smell class' do
|
36
|
+
expect(@warning.smell_category).to eq(@detector.smell_category)
|
37
37
|
end
|
38
|
-
it 'reports the
|
39
|
-
expect(@warning.
|
38
|
+
it 'reports the smell sub class' do
|
39
|
+
expect(@warning.smell_type).to eq(@detector.smell_type)
|
40
40
|
end
|
41
41
|
end
|
@@ -80,9 +80,9 @@ describe TooManyInstanceVariables do
|
|
80
80
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
81
81
|
@warning = @detector.examine_context(ctx)[0]
|
82
82
|
expect(@warning.source).to eq(@source_name)
|
83
|
-
expect(@warning.
|
84
|
-
expect(@warning.
|
85
|
-
expect(@warning.
|
83
|
+
expect(@warning.smell_category).to eq(TooManyInstanceVariables.smell_category)
|
84
|
+
expect(@warning.smell_type).to eq(TooManyInstanceVariables.smell_type)
|
85
|
+
expect(@warning.parameters[:count]).to eq(10)
|
86
86
|
expect(@warning.lines).to eq([2])
|
87
87
|
end
|
88
88
|
end
|
@@ -16,7 +16,6 @@ describe TooManyMethods do
|
|
16
16
|
it_should_behave_like 'SmellDetector'
|
17
17
|
|
18
18
|
context 'counting methods' do
|
19
|
-
|
20
19
|
it 'should not report 25 methods' do
|
21
20
|
src = <<EOS
|
22
21
|
# smelly class for testing purposes
|
@@ -28,7 +27,7 @@ class Full
|
|
28
27
|
def me41x()3 end;def me42x()3 end;def me43x()3 end;def me44x()3 end;def me45x()3 end
|
29
28
|
end
|
30
29
|
EOS
|
31
|
-
ctx =
|
30
|
+
ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
|
32
31
|
expect(@detector.examine_context(ctx)).to be_empty
|
33
32
|
end
|
34
33
|
|
@@ -43,11 +42,11 @@ class Full
|
|
43
42
|
def me51x()3 end
|
44
43
|
end
|
45
44
|
EOS
|
46
|
-
ctx =
|
45
|
+
ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
|
47
46
|
smells = @detector.examine_context(ctx)
|
48
47
|
expect(smells.length).to eq(1)
|
49
|
-
expect(smells[0].
|
50
|
-
expect(smells[0].
|
48
|
+
expect(smells[0].smell_type).to eq(TooManyMethods.smell_type)
|
49
|
+
expect(smells[0].parameters[:count]).to eq(26)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -59,11 +58,17 @@ class Full
|
|
59
58
|
def me11x()3 end;def me12x()3 end;def me13x()3 end;def me14x()3 end;def me15x()3 end
|
60
59
|
def me21x()3 end;def me22x()3 end;def me23x()3 end;def me24x()3 end;def me25x()3 end
|
61
60
|
def me31x()3 end;def me32x()3 end;def me33x()3 end;def me34x()3 end;def me35x()3 end
|
62
|
-
module Hidden
|
61
|
+
module Hidden
|
62
|
+
def me41x()3 end
|
63
|
+
def me42x()3 end
|
64
|
+
def me43x()3 end
|
65
|
+
def me44x()3 end
|
66
|
+
def me45x()3 end
|
67
|
+
end
|
63
68
|
def me51x()3 end
|
64
69
|
end
|
65
70
|
EOS
|
66
|
-
ctx =
|
71
|
+
ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
|
67
72
|
expect(@detector.examine_context(ctx)).to be_empty
|
68
73
|
end
|
69
74
|
end
|
@@ -79,12 +84,12 @@ class Full
|
|
79
84
|
def me51x()3 end
|
80
85
|
end
|
81
86
|
EOS
|
82
|
-
ctx =
|
87
|
+
ctx = ModuleContext.new(nil, src.to_reek_source.syntax_tree)
|
83
88
|
@warning = @detector.examine_context(ctx)[0]
|
84
89
|
expect(@warning.source).to eq(@source_name)
|
85
|
-
expect(@warning.
|
86
|
-
expect(@warning.
|
87
|
-
expect(@warning.
|
90
|
+
expect(@warning.smell_category).to eq(TooManyMethods.smell_category)
|
91
|
+
expect(@warning.smell_type).to eq(TooManyMethods.smell_type)
|
92
|
+
expect(@warning.parameters[:count]).to eq(26)
|
88
93
|
expect(@warning.lines).to eq([1])
|
89
94
|
end
|
90
95
|
end
|
@@ -31,7 +31,11 @@ describe TooManyStatements do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should not report initialize' do
|
34
|
-
src = '
|
34
|
+
src = '
|
35
|
+
def initialize(arga)
|
36
|
+
alf = f(1); @bet = 2; @cut = 3; @dit = 4; @emp = 5; @fry = 6
|
37
|
+
end
|
38
|
+
'
|
35
39
|
expect(src).not_to smell_of(TooManyStatements)
|
36
40
|
end
|
37
41
|
|
@@ -134,7 +138,15 @@ describe TooManyStatements, 'does not count control statements' do
|
|
134
138
|
end
|
135
139
|
|
136
140
|
it 'counts 3 statements in an else' do
|
137
|
-
method = process_method('
|
141
|
+
method = process_method('
|
142
|
+
def one()
|
143
|
+
if val == 4
|
144
|
+
callee(); callee(); callee()
|
145
|
+
else
|
146
|
+
callee(); callee(); callee()
|
147
|
+
end
|
148
|
+
end
|
149
|
+
')
|
138
150
|
expect(method.num_statements).to eq(6)
|
139
151
|
end
|
140
152
|
|
@@ -159,8 +171,8 @@ describe TooManyStatements, 'does not count control statements' do
|
|
159
171
|
end
|
160
172
|
|
161
173
|
it 'counts 3 statements in a while loop' do
|
162
|
-
|
163
|
-
expect(
|
174
|
+
source = 'def one() while val < 4; callee(); callee(); callee(); end; end'
|
175
|
+
expect(process_method(source).num_statements).to eq(3)
|
164
176
|
end
|
165
177
|
|
166
178
|
it 'counts extra statements in a while condition' do
|
@@ -174,8 +186,8 @@ describe TooManyStatements, 'does not count control statements' do
|
|
174
186
|
end
|
175
187
|
|
176
188
|
it 'counts 3 statements in a until loop' do
|
177
|
-
|
178
|
-
expect(
|
189
|
+
source = 'def one() until val < 4; callee(); callee(); callee(); end; end'
|
190
|
+
expect(process_method(source).num_statements).to eq(3)
|
179
191
|
end
|
180
192
|
|
181
193
|
it 'counts 1 statement in a for loop' do
|
@@ -184,8 +196,8 @@ describe TooManyStatements, 'does not count control statements' do
|
|
184
196
|
end
|
185
197
|
|
186
198
|
it 'counts 3 statements in a for loop' do
|
187
|
-
|
188
|
-
expect(
|
199
|
+
source = 'def one() for i in 0..4; callee(); callee(); callee(); end; end'
|
200
|
+
expect(process_method(source).num_statements).to eq(3)
|
189
201
|
end
|
190
202
|
|
191
203
|
it 'counts 1 statement in a rescue' do
|
@@ -194,7 +206,15 @@ describe TooManyStatements, 'does not count control statements' do
|
|
194
206
|
end
|
195
207
|
|
196
208
|
it 'counts 3 statements in a rescue' do
|
197
|
-
method = process_method('
|
209
|
+
method = process_method('
|
210
|
+
def one()
|
211
|
+
begin
|
212
|
+
callee(); callee(); callee()
|
213
|
+
rescue
|
214
|
+
callee(); callee(); callee()
|
215
|
+
end
|
216
|
+
end
|
217
|
+
')
|
198
218
|
expect(method.num_statements).to eq(6)
|
199
219
|
end
|
200
220
|
|
@@ -204,17 +224,31 @@ describe TooManyStatements, 'does not count control statements' do
|
|
204
224
|
end
|
205
225
|
|
206
226
|
it 'counts 3 statements in a when' do
|
207
|
-
method = process_method('
|
227
|
+
method = process_method('
|
228
|
+
def one()
|
229
|
+
case fred
|
230
|
+
when "hi" then callee(); callee()
|
231
|
+
when "lo" then callee()
|
232
|
+
end
|
233
|
+
end
|
234
|
+
')
|
208
235
|
expect(method.num_statements).to eq(3)
|
209
236
|
end
|
210
237
|
|
211
238
|
it 'counts 1 statement in a case else' do
|
212
|
-
|
213
|
-
expect(
|
239
|
+
source = 'def one() case fred; when "hi"; callee(); else; callee(); end; end'
|
240
|
+
expect(process_method(source).num_statements).to eq(2)
|
214
241
|
end
|
215
242
|
|
216
243
|
it 'counts 3 statements in a case else' do
|
217
|
-
method = process_method('
|
244
|
+
method = process_method('
|
245
|
+
def one()
|
246
|
+
case fred
|
247
|
+
when "hi" then callee(); callee(); callee()
|
248
|
+
else callee(); callee(); callee()
|
249
|
+
end
|
250
|
+
end
|
251
|
+
')
|
218
252
|
expect(method.num_statements).to eq(6)
|
219
253
|
end
|
220
254
|
|
@@ -234,8 +268,8 @@ describe TooManyStatements, 'does not count control statements' do
|
|
234
268
|
end
|
235
269
|
|
236
270
|
it 'counts 4 statements in an iterator' do
|
237
|
-
|
238
|
-
expect(
|
271
|
+
source = 'def one() fred.each do; callee(); callee(); callee(); end; end'
|
272
|
+
expect(process_method(source).num_statements).to eq(4)
|
239
273
|
end
|
240
274
|
|
241
275
|
it 'counts 1 statement in a singleton method' do
|
@@ -259,14 +293,17 @@ describe TooManyStatements do
|
|
259
293
|
expect(ctx).to receive(:config_for).with(TooManyStatements).and_return({})
|
260
294
|
@smells = @detector.examine_context(ctx)
|
261
295
|
end
|
296
|
+
|
262
297
|
it 'reports only 1 smell' do
|
263
298
|
expect(@smells.length).to eq(1)
|
264
299
|
end
|
300
|
+
|
265
301
|
it 'reports the number of statements' do
|
266
|
-
expect(@smells[0].
|
302
|
+
expect(@smells[0].parameters[:count]).to eq(@num_statements)
|
267
303
|
end
|
268
|
-
|
269
|
-
|
304
|
+
|
305
|
+
it 'reports the correct smell sub class' do
|
306
|
+
expect(@smells[0].smell_type).to eq(TooManyStatements.smell_type)
|
270
307
|
end
|
271
308
|
end
|
272
309
|
end
|
@@ -17,7 +17,8 @@ describe UncommunicativeMethodName do
|
|
17
17
|
|
18
18
|
['help', '+', '-', '/', '*'].each do |method_name|
|
19
19
|
it "accepts the method name '#{method_name}'" do
|
20
|
-
|
20
|
+
src = "def #{method_name}(fred) basics(17) end"
|
21
|
+
expect(src).not_to smell_of(UncommunicativeMethodName)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -33,7 +34,7 @@ describe UncommunicativeMethodName do
|
|
33
34
|
it_should_behave_like 'common fields set correctly'
|
34
35
|
|
35
36
|
it 'reports the correct values' do
|
36
|
-
expect(@warning.
|
37
|
+
expect(@warning.parameters[:name]).to eq(method_name)
|
37
38
|
expect(@warning.lines).to eq([1])
|
38
39
|
expect(@warning.context).to eq(method_name)
|
39
40
|
end
|
@@ -33,10 +33,10 @@ describe UncommunicativeModuleName do
|
|
33
33
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
34
34
|
smells = @detector.examine_context(ctx)
|
35
35
|
expect(smells.length).to eq(1)
|
36
|
-
expect(smells[0].
|
37
|
-
expect(smells[0].
|
38
|
-
expect(smells[0].
|
39
|
-
expect(smells[0].context).to match(/#{smells[0].
|
36
|
+
expect(smells[0].smell_category).to eq(UncommunicativeModuleName.smell_category)
|
37
|
+
expect(smells[0].smell_type).to eq(UncommunicativeModuleName.smell_type)
|
38
|
+
expect(smells[0].parameters[:name]).to eq('X')
|
39
|
+
expect(smells[0].context).to match(/#{smells[0].parameters[:name]}/)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -59,7 +59,7 @@ describe UncommunicativeModuleName do
|
|
59
59
|
it_should_behave_like 'common fields set correctly'
|
60
60
|
|
61
61
|
it 'reports the correct values' do
|
62
|
-
expect(@warning.
|
62
|
+
expect(@warning.parameters[:name]).to eq('Printer2')
|
63
63
|
expect(@warning.lines).to eq([1])
|
64
64
|
end
|
65
65
|
end
|