reek 1.6.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -9
- data/features/command_line_interface/options.feature +20 -16
- data/features/command_line_interface/stdin.feature +1 -1
- data/features/rake_task/rake_task.feature +0 -12
- data/features/reports/reports.feature +63 -23
- data/features/reports/yaml.feature +3 -3
- data/features/samples.feature +3 -3
- data/lib/reek/cli/application.rb +5 -5
- data/lib/reek/cli/input.rb +1 -1
- data/lib/reek/cli/option_interpreter.rb +77 -0
- data/lib/reek/cli/options.rb +89 -82
- data/lib/reek/cli/report/formatter.rb +33 -24
- data/lib/reek/cli/report/heading_formatter.rb +45 -0
- data/lib/reek/cli/report/location_formatter.rb +23 -0
- data/lib/reek/cli/report/report.rb +32 -17
- data/lib/reek/configuration/app_configuration.rb +2 -2
- data/lib/reek/configuration/configuration_file_finder.rb +10 -10
- data/lib/reek/core/smell_repository.rb +3 -28
- data/lib/reek/rake/task.rb +35 -76
- data/lib/reek/smell_warning.rb +31 -16
- data/lib/reek/smells/nested_iterators.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +9 -0
- data/lib/reek/smells/utility_function.rb +2 -1
- data/lib/reek/spec/should_reek.rb +0 -3
- data/lib/reek/spec/should_reek_of.rb +61 -12
- data/lib/reek/spec/should_reek_only_of.rb +12 -10
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +2 -2
- data/spec/factories/factories.rb +2 -5
- data/spec/reek/cli/html_report_spec.rb +28 -0
- data/spec/reek/cli/option_interperter_spec.rb +14 -0
- data/spec/reek/cli/text_report_spec.rb +95 -0
- data/spec/reek/cli/yaml_report_spec.rb +23 -0
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -6
- data/spec/reek/core/module_context_spec.rb +1 -1
- data/spec/reek/core/smell_repository_spec.rb +17 -0
- data/spec/reek/smell_warning_spec.rb +9 -11
- data/spec/reek/smells/boolean_parameter_spec.rb +11 -11
- data/spec/reek/smells/control_parameter_spec.rb +40 -40
- data/spec/reek/smells/data_clump_spec.rb +17 -17
- data/spec/reek/smells/duplicate_method_call_spec.rb +56 -33
- data/spec/reek/smells/feature_envy_spec.rb +44 -40
- data/spec/reek/smells/irresponsible_module_spec.rb +1 -1
- data/spec/reek/smells/long_parameter_list_spec.rb +12 -12
- data/spec/reek/smells/long_yield_list_spec.rb +4 -4
- data/spec/reek/smells/module_initialize_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +71 -52
- data/spec/reek/smells/nil_check_spec.rb +6 -6
- data/spec/reek/smells/prima_donna_method_spec.rb +2 -2
- data/spec/reek/smells/too_many_statements_spec.rb +34 -34
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -38
- data/spec/reek/smells/unused_parameters_spec.rb +16 -17
- data/spec/reek/smells/utility_function_spec.rb +21 -8
- data/spec/reek/spec/should_reek_of_spec.rb +18 -5
- data/spec/reek/spec/should_reek_only_of_spec.rb +7 -1
- data/spec/spec_helper.rb +22 -14
- metadata +15 -20
- data/lib/reek/cli/help_command.rb +0 -15
- data/lib/reek/cli/report/strategy.rb +0 -64
- data/lib/reek/cli/version_command.rb +0 -16
- data/spec/matchers/smell_of_matcher.rb +0 -95
- data/spec/reek/cli/help_command_spec.rb +0 -25
- data/spec/reek/cli/report_spec.rb +0 -132
- data/spec/reek/cli/version_command_spec.rb +0 -31
@@ -18,7 +18,7 @@ describe UncommunicativeMethodName do
|
|
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
|
21
|
+
expect(src).not_to reek_of(UncommunicativeMethodName)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -19,15 +19,19 @@ describe UncommunicativeModuleName do
|
|
19
19
|
it 'does not report one-word name' do
|
20
20
|
expect("#{type} Helper; end").not_to reek_of(:UncommunicativeModuleName)
|
21
21
|
end
|
22
|
+
|
22
23
|
it 'reports one-letter name' do
|
23
|
-
expect("#{type} X; end").to reek_of(:UncommunicativeModuleName,
|
24
|
+
expect("#{type} X; end").to reek_of(:UncommunicativeModuleName, name: 'X')
|
24
25
|
end
|
26
|
+
|
25
27
|
it 'reports name of the form "x2"' do
|
26
|
-
expect("#{type} X2; end").to reek_of(:UncommunicativeModuleName,
|
28
|
+
expect("#{type} X2; end").to reek_of(:UncommunicativeModuleName, name: 'X2')
|
27
29
|
end
|
30
|
+
|
28
31
|
it 'reports long name ending in a number' do
|
29
|
-
expect("#{type} Printer2; end").to reek_of(:UncommunicativeModuleName,
|
32
|
+
expect("#{type} Printer2; end").to reek_of(:UncommunicativeModuleName, name: 'Printer2')
|
30
33
|
end
|
34
|
+
|
31
35
|
it 'reports a bad scoped name' do
|
32
36
|
src = "#{type} Foo::X; end"
|
33
37
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
@@ -19,50 +19,50 @@ describe UncommunicativeParameterName do
|
|
19
19
|
context "in a method definition #{description}" do
|
20
20
|
it 'does not recognise *' do
|
21
21
|
expect("def #{host}help(xray, *) basics(17) end").
|
22
|
-
not_to
|
22
|
+
not_to reek_of(UncommunicativeParameterName)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "reports parameter's name" do
|
26
26
|
src = "def #{host}help(x) basics(x) end"
|
27
|
-
expect(src).to
|
28
|
-
|
27
|
+
expect(src).to reek_of(UncommunicativeParameterName,
|
28
|
+
name: 'x')
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'does not report unused parameters' do
|
32
32
|
src = "def #{host}help(x) basics(17) end"
|
33
|
-
expect(src).not_to
|
33
|
+
expect(src).not_to reek_of(UncommunicativeParameterName)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'does not report two-letter parameter names' do
|
37
37
|
expect("def #{host}help(ab) basics(ab) end").
|
38
|
-
not_to
|
38
|
+
not_to reek_of(UncommunicativeParameterName)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'reports names of the form "x2"' do
|
42
42
|
src = "def #{host}help(x2) basics(x2) end"
|
43
|
-
expect(src).to
|
44
|
-
|
43
|
+
expect(src).to reek_of(UncommunicativeParameterName,
|
44
|
+
name: 'x2')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'reports long name ending in a number' do
|
48
48
|
src = "def #{host}help(param2) basics(param2) end"
|
49
|
-
expect(src).to
|
50
|
-
|
49
|
+
expect(src).to reek_of(UncommunicativeParameterName,
|
50
|
+
name: 'param2')
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'does not report unused anonymous parameter' do
|
54
54
|
expect("def #{host}help(_) basics(17) end").
|
55
|
-
not_to
|
55
|
+
not_to reek_of(UncommunicativeParameterName)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'reports used anonymous parameter' do
|
59
59
|
expect("def #{host}help(_) basics(_) end").
|
60
|
-
to
|
60
|
+
to reek_of(UncommunicativeParameterName)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'reports used parameters marked as unused' do
|
64
64
|
expect("def #{host}help(_unused) basics(_unused) end").
|
65
|
-
to
|
65
|
+
to reek_of(UncommunicativeParameterName)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -22,37 +22,35 @@ describe UncommunicativeVariableName do
|
|
22
22
|
end
|
23
23
|
it 'reports one-letter fieldname in assignment' do
|
24
24
|
src = 'class Thing; def simple(fred) @x = fred end end'
|
25
|
-
expect(src).to reek_of(:UncommunicativeVariableName,
|
25
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: '@x')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'local variable name' do
|
30
30
|
it 'does not report one-word variable name' do
|
31
31
|
expect('def help(fred) simple = jim(45) end').
|
32
|
-
not_to
|
32
|
+
not_to reek_of(UncommunicativeVariableName)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'does not report single underscore as a variable name' do
|
36
|
-
expect('def help(fred) _ = jim(45) end').not_to
|
36
|
+
expect('def help(fred) _ = jim(45) end').not_to reek_of(UncommunicativeVariableName)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'reports one-letter variable name' do
|
40
40
|
src = 'def simple(fred) x = jim(45) end'
|
41
|
-
expect(src).to
|
42
|
-
name: 'x')
|
41
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'reports name of the form "x2"' do
|
46
45
|
src = 'def simple(fred) x2 = jim(45) end'
|
47
|
-
expect(src).to
|
48
|
-
name: 'x2')
|
46
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x2')
|
49
47
|
end
|
50
48
|
|
51
49
|
it 'reports long name ending in a number' do
|
52
50
|
@bad_var = 'var123'
|
53
51
|
src = "def simple(fred) #{@bad_var} = jim(45) end"
|
54
|
-
expect(src).to
|
55
|
-
|
52
|
+
expect(src).to reek_of(UncommunicativeVariableName,
|
53
|
+
name: @bad_var)
|
56
54
|
end
|
57
55
|
|
58
56
|
it 'reports variable name only once' do
|
@@ -67,26 +65,24 @@ describe UncommunicativeVariableName do
|
|
67
65
|
|
68
66
|
it 'reports a bad name inside a block' do
|
69
67
|
src = 'def clean(text) text.each { q2 = 3 } end'
|
70
|
-
expect(src).to
|
71
|
-
name: 'q2')
|
68
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'q2')
|
72
69
|
end
|
73
70
|
|
74
71
|
it 'reports variable name outside any method' do
|
75
|
-
expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName,
|
72
|
+
expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName, name: 'x')
|
76
73
|
end
|
77
74
|
end
|
78
75
|
|
79
76
|
context 'block parameter name' do
|
80
77
|
it 'reports deep block parameter' do
|
81
|
-
src =
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
EOS
|
88
|
-
expect(src).to
|
89
|
-
name: 'x')
|
78
|
+
src = <<-EOS
|
79
|
+
def bad
|
80
|
+
unless @mod then
|
81
|
+
@sig.each { |x| x.to_s }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
EOS
|
85
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
90
86
|
end
|
91
87
|
|
92
88
|
it 'reports all relevant block parameters' do
|
@@ -95,9 +91,8 @@ EOS
|
|
95
91
|
@foo.map { |x, y| x + y }
|
96
92
|
end
|
97
93
|
EOS
|
98
|
-
expect(src).to
|
99
|
-
|
100
|
-
{ name: 'y' })
|
94
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
95
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
101
96
|
end
|
102
97
|
|
103
98
|
it 'reports block parameters used outside of methods' do
|
@@ -106,8 +101,7 @@ EOS
|
|
106
101
|
@foo.map { |x| x * 2 }
|
107
102
|
end
|
108
103
|
EOS
|
109
|
-
expect(src).to
|
110
|
-
name: 'x')
|
104
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
111
105
|
end
|
112
106
|
|
113
107
|
it 'reports splatted block parameters correctly' do
|
@@ -116,8 +110,7 @@ EOS
|
|
116
110
|
@foo.map { |*y| y << 1 }
|
117
111
|
end
|
118
112
|
EOS
|
119
|
-
expect(src).to
|
120
|
-
name: 'y')
|
113
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
121
114
|
end
|
122
115
|
|
123
116
|
it 'reports nested block parameters' do
|
@@ -126,9 +119,8 @@ EOS
|
|
126
119
|
@foo.map { |(x, y)| x + y }
|
127
120
|
end
|
128
121
|
EOS
|
129
|
-
expect(src).to
|
130
|
-
|
131
|
-
{ name: 'y' })
|
122
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
123
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
132
124
|
end
|
133
125
|
|
134
126
|
it 'reports splatted nested block parameters' do
|
@@ -137,9 +129,8 @@ EOS
|
|
137
129
|
@foo.map { |(x, *y)| x + y }
|
138
130
|
end
|
139
131
|
EOS
|
140
|
-
expect(src).to
|
141
|
-
|
142
|
-
{ name: 'y' })
|
132
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
133
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
143
134
|
end
|
144
135
|
|
145
136
|
it 'reports deeply nested block parameters' do
|
@@ -148,10 +139,9 @@ EOS
|
|
148
139
|
@foo.map { |(x, (y, z))| x + y + z }
|
149
140
|
end
|
150
141
|
EOS
|
151
|
-
expect(src).to
|
152
|
-
|
153
|
-
|
154
|
-
{ name: 'z' })
|
142
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
143
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
144
|
+
expect(src).to reek_of(UncommunicativeVariableName, name: 'z')
|
155
145
|
end
|
156
146
|
end
|
157
147
|
|
@@ -8,67 +8,66 @@ include Reek::Smells
|
|
8
8
|
describe UnusedParameters do
|
9
9
|
context 'for methods' do
|
10
10
|
it 'reports nothing for no parameters' do
|
11
|
-
expect('def simple; true end').not_to
|
11
|
+
expect('def simple; true end').not_to reek_of(UnusedParameters)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'reports nothing for used parameter' do
|
15
|
-
expect('def simple(sum); sum end').not_to
|
15
|
+
expect('def simple(sum); sum end').not_to reek_of(UnusedParameters)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'reports for 1 used and 2 unused parameter' do
|
19
19
|
src = 'def simple(num,sum,denum); sum end'
|
20
|
-
expect(src).to
|
21
|
-
|
22
|
-
{ name: 'denum' })
|
20
|
+
expect(src).to reek_of(UnusedParameters, name: 'num')
|
21
|
+
expect(src).to reek_of(UnusedParameters, name: 'denum')
|
23
22
|
end
|
24
23
|
|
25
24
|
it 'reports for 3 used and 1 unused parameter' do
|
26
25
|
src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
|
27
|
-
expect(src).to
|
28
|
-
|
26
|
+
expect(src).to reek_of(UnusedParameters,
|
27
|
+
name: 'quotient')
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'reports nothing for used splatted parameter' do
|
32
|
-
expect('def simple(*sum); sum end').not_to
|
31
|
+
expect('def simple(*sum); sum end').not_to reek_of(UnusedParameters)
|
33
32
|
end
|
34
33
|
|
35
34
|
it 'reports nothing for unused anonymous parameter' do
|
36
|
-
expect('def simple(_); end').not_to
|
35
|
+
expect('def simple(_); end').not_to reek_of(UnusedParameters)
|
37
36
|
end
|
38
37
|
|
39
38
|
it 'reports nothing for named parameters prefixed with _' do
|
40
|
-
expect('def simple(_name); end').not_to
|
39
|
+
expect('def simple(_name); end').not_to reek_of(UnusedParameters)
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'reports nothing for unused anonymous splatted parameter' do
|
44
|
-
expect('def simple(*); end').not_to
|
43
|
+
expect('def simple(*); end').not_to reek_of(UnusedParameters)
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'reports nothing when using super with implicit arguments' do
|
48
|
-
expect('def simple(*args); super; end').not_to
|
47
|
+
expect('def simple(*args); super; end').not_to reek_of(UnusedParameters)
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'reports something when using super explicitely passing no arguments' do
|
52
|
-
expect('def simple(*args); super(); end').to
|
51
|
+
expect('def simple(*args); super(); end').to reek_of(UnusedParameters)
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'reports nothing when using super explicitely passing all arguments' do
|
56
|
-
expect('def simple(*args); super(*args); end').not_to
|
55
|
+
expect('def simple(*args); super(*args); end').not_to reek_of(UnusedParameters)
|
57
56
|
end
|
58
57
|
|
59
58
|
it 'reports nothing when using super in a nested context' do
|
60
59
|
expect('def simple(*args); call_other("something", super); end').
|
61
|
-
not_to
|
60
|
+
not_to reek_of(UnusedParameters)
|
62
61
|
end
|
63
62
|
|
64
63
|
it 'reports something when not using a keyword argument with splat' do
|
65
64
|
expect('def simple(var, kw: :val, **args); @var, @kw = var, kw; end').
|
66
|
-
to
|
65
|
+
to reek_of(UnusedParameters)
|
67
66
|
end
|
68
67
|
|
69
68
|
it 'reports nothing when using a keyword argument with splat' do
|
70
69
|
expect('def simple(var, kw: :val, **args); @var, @kw, @args = var, kw, args; end').
|
71
|
-
not_to
|
70
|
+
not_to reek_of(UnusedParameters)
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|
@@ -22,27 +22,34 @@ describe UtilityFunction do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
25
26
|
context 'with no calls' do
|
26
27
|
it 'does not report empty method' do
|
27
28
|
src = 'def simple(arga) end'
|
28
29
|
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
29
30
|
expect(@detector.examine_context(ctx)).to be_empty
|
30
31
|
end
|
32
|
+
|
31
33
|
it 'does not report literal' do
|
32
34
|
expect('def simple() 3; end').not_to reek_of(:UtilityFunction)
|
33
35
|
end
|
36
|
+
|
34
37
|
it 'does not report instance variable reference' do
|
35
38
|
expect('def simple() @yellow end').not_to reek_of(:UtilityFunction)
|
36
39
|
end
|
40
|
+
|
37
41
|
it 'does not report vcall' do
|
38
42
|
expect('def simple() y end').not_to reek_of(:UtilityFunction)
|
39
43
|
end
|
44
|
+
|
40
45
|
it 'does not report references to self' do
|
41
46
|
expect('def into; self; end').not_to reek_of(:UtilityFunction)
|
42
47
|
end
|
48
|
+
|
43
49
|
it 'recognises an ivar reference within a block' do
|
44
50
|
expect('def clean(text) text.each { @fred = 3} end').not_to reek_of(:UtilityFunction)
|
45
51
|
end
|
52
|
+
|
46
53
|
it 'copes with nil superclass' do
|
47
54
|
expect('class Object; def is_maybe?() false end end').not_to reek_of(:UtilityFunction)
|
48
55
|
end
|
@@ -50,8 +57,9 @@ describe UtilityFunction do
|
|
50
57
|
|
51
58
|
context 'with only one call' do
|
52
59
|
it 'does not report a call to a parameter' do
|
53
|
-
expect('def simple(arga) arga.to_s end').not_to reek_of(:UtilityFunction,
|
60
|
+
expect('def simple(arga) arga.to_s end').not_to reek_of(:UtilityFunction, name: 'simple')
|
54
61
|
end
|
62
|
+
|
55
63
|
it 'does not report a call to a constant' do
|
56
64
|
expect('def simple(arga) FIELDS[arga] end').not_to reek_of(:UtilityFunction)
|
57
65
|
end
|
@@ -60,25 +68,30 @@ describe UtilityFunction do
|
|
60
68
|
context 'with two or more calls' do
|
61
69
|
it 'reports two calls' do
|
62
70
|
src = 'def simple(arga) arga.to_s + arga.to_i end'
|
63
|
-
expect(src).to reek_of(:UtilityFunction,
|
71
|
+
expect(src).to reek_of(:UtilityFunction, name: 'simple')
|
64
72
|
end
|
73
|
+
|
65
74
|
it 'counts a local call in a param initializer' do
|
66
75
|
expect('def simple(arga=local) arga.to_s end').not_to reek_of(:UtilityFunction)
|
67
76
|
end
|
77
|
+
|
68
78
|
it 'should count usages of self'do
|
69
79
|
expect('def <=>(other) Options[:sort_order].compare(self, other) end').
|
70
80
|
not_to reek_of(:UtilityFunction)
|
71
81
|
end
|
82
|
+
|
72
83
|
it 'should count self reference within a dstr' do
|
73
84
|
expect('def as(alias_name); "#{self} as #{alias_name}".to_sym; end').
|
74
85
|
not_to reek_of(:UtilityFunction)
|
75
86
|
end
|
87
|
+
|
76
88
|
it 'should count calls to self within a dstr' do
|
77
89
|
expect('def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end').
|
78
90
|
not_to reek_of(:UtilityFunction)
|
79
91
|
end
|
92
|
+
|
80
93
|
it 'should report message chain' do
|
81
|
-
expect('def simple(arga) arga.b.c end').to reek_of(:UtilityFunction,
|
94
|
+
expect('def simple(arga) arga.b.c end').to reek_of(:UtilityFunction, name: 'simple')
|
82
95
|
end
|
83
96
|
|
84
97
|
it 'does not report a method that calls super' do
|
@@ -103,11 +116,11 @@ describe UtilityFunction do
|
|
103
116
|
|
104
117
|
context 'when a smells is reported' do
|
105
118
|
before :each do
|
106
|
-
src =
|
107
|
-
def simple(arga)
|
108
|
-
|
109
|
-
end
|
110
|
-
EOS
|
119
|
+
src = <<-EOS
|
120
|
+
def simple(arga)
|
121
|
+
arga.b.c
|
122
|
+
end
|
123
|
+
EOS
|
111
124
|
source = src.to_reek_source
|
112
125
|
sniffer = Sniffer.new(source)
|
113
126
|
mctx = CodeParser.new(sniffer).process_def(source.syntax_tree)
|
@@ -11,11 +11,13 @@ describe ShouldReekOf do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'reports duplicate calls to @other.thing' do
|
14
|
-
expect(@ruby).to reek_of(:Duplication,
|
14
|
+
expect(@ruby).to reek_of(:Duplication, name: '@other.thing')
|
15
15
|
end
|
16
|
+
|
16
17
|
it 'reports duplicate calls to @other.thing.foo' do
|
17
|
-
expect(@ruby).to reek_of(:Duplication,
|
18
|
+
expect(@ruby).to reek_of(:Duplication, name: '@other.thing.foo')
|
18
19
|
end
|
20
|
+
|
19
21
|
it 'does not report any feature envy' do
|
20
22
|
expect(@ruby).not_to reek_of(:FeatureEnvy)
|
21
23
|
end
|
@@ -25,7 +27,7 @@ describe ShouldReekOf do
|
|
25
27
|
before :each do
|
26
28
|
@clean_code = 'def good() true; end'
|
27
29
|
@smelly_code = 'def x() y = 4; end'
|
28
|
-
@matcher = ShouldReekOf.new(:UncommunicativeVariableName,
|
30
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, name: 'y')
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'matches a smelly String' do
|
@@ -42,11 +44,22 @@ describe ShouldReekOf do
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
context 'passing in smell_details with unknown parameter name' do
|
48
|
+
before :each do
|
49
|
+
@smelly_code = 'def x() y = 4; end'
|
50
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, foo: 'y')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises ArgumentError' do
|
54
|
+
expect { @matcher.matches?(@smelly_code) }.to raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
45
58
|
context 'checking code in a Dir' do
|
46
59
|
before :each do
|
47
60
|
@clean_dir = Dir['spec/samples/three_clean_files/*.rb']
|
48
61
|
@smelly_dir = Dir['spec/samples/two_smelly_files/*.rb']
|
49
|
-
@matcher = ShouldReekOf.new(:UncommunicativeVariableName,
|
62
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, name: '@s')
|
50
63
|
end
|
51
64
|
|
52
65
|
it 'matches a smelly String' do
|
@@ -62,7 +75,7 @@ describe ShouldReekOf do
|
|
62
75
|
before :each do
|
63
76
|
@clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
|
64
77
|
@smelly_file = File.new(Dir['spec/samples/two_smelly_files/*.rb'][0])
|
65
|
-
@matcher = ShouldReekOf.new(:UncommunicativeVariableName,
|
78
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, name: '@s')
|
66
79
|
end
|
67
80
|
|
68
81
|
it 'matches a smelly String' do
|