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
@@ -1,16 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'reek/smells/uncommunicative_method_name'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
|
-
require 'reek/core/code_parser'
|
5
|
-
require 'reek/core/sniffer'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
before :each do
|
12
|
-
@source_name = 'wallamalloo'
|
13
|
-
@detector = UncommunicativeMethodName.new(@source_name)
|
5
|
+
describe Reek::Smells::UncommunicativeMethodName do
|
6
|
+
before do
|
7
|
+
@source_name = 'dummy_source'
|
8
|
+
@detector = build(:smell_detector, smell_type: :UncommunicativeMethodName, source: @source_name)
|
14
9
|
end
|
15
10
|
|
16
11
|
it_should_behave_like 'SmellDetector'
|
@@ -18,7 +13,7 @@ describe UncommunicativeMethodName do
|
|
18
13
|
['help', '+', '-', '/', '*'].each do |method_name|
|
19
14
|
it "accepts the method name '#{method_name}'" do
|
20
15
|
src = "def #{method_name}(fred) basics(17) end"
|
21
|
-
expect(src).not_to reek_of(UncommunicativeMethodName)
|
16
|
+
expect(src).not_to reek_of(:UncommunicativeMethodName)
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
@@ -26,7 +21,7 @@ describe UncommunicativeMethodName do
|
|
26
21
|
context 'with a bad name' do
|
27
22
|
before do
|
28
23
|
src = "def #{method_name}; end"
|
29
|
-
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
24
|
+
ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
30
25
|
smells = @detector.examine_context(ctx)
|
31
26
|
@warning = smells[0]
|
32
27
|
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'reek/smells/uncommunicative_module_name'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
|
-
require 'reek/core/
|
5
|
-
require 'reek/core/sniffer'
|
4
|
+
require 'reek/core/code_context'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
before :each do
|
12
|
-
@source_name = 'classy'
|
13
|
-
@detector = UncommunicativeModuleName.new(@source_name)
|
6
|
+
describe Reek::Smells::UncommunicativeModuleName do
|
7
|
+
before do
|
8
|
+
@source_name = 'dummy_source'
|
9
|
+
@detector = build(:smell_detector, smell_type: :UncommunicativeModuleName, source: @source_name)
|
14
10
|
end
|
15
11
|
|
16
12
|
it_should_behave_like 'SmellDetector'
|
@@ -34,11 +30,11 @@ describe UncommunicativeModuleName do
|
|
34
30
|
|
35
31
|
it 'reports a bad scoped name' do
|
36
32
|
src = "#{type} Foo::X; end"
|
37
|
-
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
33
|
+
ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
38
34
|
smells = @detector.examine_context(ctx)
|
39
35
|
expect(smells.length).to eq(1)
|
40
|
-
expect(smells[0].smell_category).to eq(UncommunicativeModuleName.smell_category)
|
41
|
-
expect(smells[0].smell_type).to eq(UncommunicativeModuleName.smell_type)
|
36
|
+
expect(smells[0].smell_category).to eq(Reek::Smells::UncommunicativeModuleName.smell_category)
|
37
|
+
expect(smells[0].smell_type).to eq(Reek::Smells::UncommunicativeModuleName.smell_type)
|
42
38
|
expect(smells[0].parameters[:name]).to eq('X')
|
43
39
|
expect(smells[0].context).to match(/#{smells[0].parameters[:name]}/)
|
44
40
|
end
|
@@ -47,7 +43,7 @@ describe UncommunicativeModuleName do
|
|
47
43
|
context 'accepting names' do
|
48
44
|
it 'accepts Inline::C' do
|
49
45
|
src = 'module Inline::C; end'
|
50
|
-
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
46
|
+
ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
51
47
|
expect(@detector.examine_context(ctx)).to be_empty
|
52
48
|
end
|
53
49
|
end
|
@@ -55,7 +51,7 @@ describe UncommunicativeModuleName do
|
|
55
51
|
context 'looking at the YAML' do
|
56
52
|
before :each do
|
57
53
|
src = 'module Printer2; end'
|
58
|
-
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
54
|
+
ctx = Reek::Core::CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
59
55
|
smells = @detector.examine_context(ctx)
|
60
56
|
@warning = smells[0]
|
61
57
|
end
|
@@ -3,13 +3,12 @@ require 'reek/smells/uncommunicative_parameter_name'
|
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
require 'reek/core/method_context'
|
5
5
|
|
6
|
-
|
7
|
-
include Reek::Smells
|
8
|
-
|
9
|
-
describe UncommunicativeParameterName do
|
6
|
+
describe Reek::Smells::UncommunicativeParameterName do
|
10
7
|
before :each do
|
11
|
-
@source_name = '
|
12
|
-
@detector =
|
8
|
+
@source_name = 'dummy_source'
|
9
|
+
@detector = build(:smell_detector,
|
10
|
+
smell_type: :UncommunicativeParameterName,
|
11
|
+
source: @source_name)
|
13
12
|
end
|
14
13
|
|
15
14
|
it_should_behave_like 'SmellDetector'
|
@@ -19,50 +18,50 @@ describe UncommunicativeParameterName do
|
|
19
18
|
context "in a method definition #{description}" do
|
20
19
|
it 'does not recognise *' do
|
21
20
|
expect("def #{host}help(xray, *) basics(17) end").
|
22
|
-
not_to reek_of(UncommunicativeParameterName)
|
21
|
+
not_to reek_of(:UncommunicativeParameterName)
|
23
22
|
end
|
24
23
|
|
25
24
|
it "reports parameter's name" do
|
26
25
|
src = "def #{host}help(x) basics(x) end"
|
27
|
-
expect(src).to reek_of(UncommunicativeParameterName,
|
26
|
+
expect(src).to reek_of(:UncommunicativeParameterName,
|
28
27
|
name: 'x')
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'does not report unused parameters' do
|
32
31
|
src = "def #{host}help(x) basics(17) end"
|
33
|
-
expect(src).not_to reek_of(UncommunicativeParameterName)
|
32
|
+
expect(src).not_to reek_of(:UncommunicativeParameterName)
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'does not report two-letter parameter names' do
|
37
36
|
expect("def #{host}help(ab) basics(ab) end").
|
38
|
-
not_to reek_of(UncommunicativeParameterName)
|
37
|
+
not_to reek_of(:UncommunicativeParameterName)
|
39
38
|
end
|
40
39
|
|
41
40
|
it 'reports names of the form "x2"' do
|
42
41
|
src = "def #{host}help(x2) basics(x2) end"
|
43
|
-
expect(src).to reek_of(UncommunicativeParameterName,
|
42
|
+
expect(src).to reek_of(:UncommunicativeParameterName,
|
44
43
|
name: 'x2')
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'reports long name ending in a number' do
|
48
47
|
src = "def #{host}help(param2) basics(param2) end"
|
49
|
-
expect(src).to reek_of(UncommunicativeParameterName,
|
48
|
+
expect(src).to reek_of(:UncommunicativeParameterName,
|
50
49
|
name: 'param2')
|
51
50
|
end
|
52
51
|
|
53
52
|
it 'does not report unused anonymous parameter' do
|
54
53
|
expect("def #{host}help(_) basics(17) end").
|
55
|
-
not_to reek_of(UncommunicativeParameterName)
|
54
|
+
not_to reek_of(:UncommunicativeParameterName)
|
56
55
|
end
|
57
56
|
|
58
57
|
it 'reports used anonymous parameter' do
|
59
58
|
expect("def #{host}help(_) basics(_) end").
|
60
|
-
to reek_of(UncommunicativeParameterName)
|
59
|
+
to reek_of(:UncommunicativeParameterName)
|
61
60
|
end
|
62
61
|
|
63
62
|
it 'reports used parameters marked as unused' do
|
64
63
|
expect("def #{host}help(_unused) basics(_unused) end").
|
65
|
-
to reek_of(UncommunicativeParameterName)
|
64
|
+
to reek_of(:UncommunicativeParameterName)
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
@@ -70,7 +69,7 @@ describe UncommunicativeParameterName do
|
|
70
69
|
context 'looking at the smell result fields' do
|
71
70
|
before :each do
|
72
71
|
src = 'def bad(good, bad2, good_again); basics(good, bad2, good_again); end'
|
73
|
-
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
72
|
+
ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
74
73
|
@smells = @detector.examine_context(ctx)
|
75
74
|
@warning = @smells[0]
|
76
75
|
end
|
@@ -1,16 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'reek/smells/uncommunicative_variable_name'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
|
-
require 'reek/core/code_parser'
|
5
|
-
require 'reek/core/sniffer'
|
6
4
|
|
7
|
-
|
8
|
-
include Reek::Smells
|
9
|
-
|
10
|
-
describe UncommunicativeVariableName do
|
5
|
+
describe Reek::Smells::UncommunicativeVariableName do
|
11
6
|
before :each do
|
12
|
-
@source_name = '
|
13
|
-
@detector =
|
7
|
+
@source_name = 'dummy_source'
|
8
|
+
@detector = build(:smell_detector,
|
9
|
+
smell_type: :UncommunicativeVariableName,
|
10
|
+
source: @source_name)
|
14
11
|
end
|
15
12
|
|
16
13
|
it_should_behave_like 'SmellDetector'
|
@@ -29,27 +26,27 @@ describe UncommunicativeVariableName do
|
|
29
26
|
context 'local variable name' do
|
30
27
|
it 'does not report one-word variable name' do
|
31
28
|
expect('def help(fred) simple = jim(45) end').
|
32
|
-
not_to reek_of(UncommunicativeVariableName)
|
29
|
+
not_to reek_of(:UncommunicativeVariableName)
|
33
30
|
end
|
34
31
|
|
35
32
|
it 'does not report single underscore as a variable name' do
|
36
|
-
expect('def help(fred) _ = jim(45) end').not_to reek_of(UncommunicativeVariableName)
|
33
|
+
expect('def help(fred) _ = jim(45) end').not_to reek_of(:UncommunicativeVariableName)
|
37
34
|
end
|
38
35
|
|
39
36
|
it 'reports one-letter variable name' do
|
40
37
|
src = 'def simple(fred) x = jim(45) end'
|
41
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
38
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
42
39
|
end
|
43
40
|
|
44
41
|
it 'reports name of the form "x2"' do
|
45
42
|
src = 'def simple(fred) x2 = jim(45) end'
|
46
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x2')
|
43
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x2')
|
47
44
|
end
|
48
45
|
|
49
46
|
it 'reports long name ending in a number' do
|
50
47
|
@bad_var = 'var123'
|
51
48
|
src = "def simple(fred) #{@bad_var} = jim(45) end"
|
52
|
-
expect(src).to reek_of(UncommunicativeVariableName,
|
49
|
+
expect(src).to reek_of(:UncommunicativeVariableName,
|
53
50
|
name: @bad_var)
|
54
51
|
end
|
55
52
|
|
@@ -58,14 +55,14 @@ describe UncommunicativeVariableName do
|
|
58
55
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
59
56
|
smells = @detector.examine_context(ctx)
|
60
57
|
expect(smells.length).to eq(1)
|
61
|
-
expect(smells[0].smell_type).to eq(
|
58
|
+
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
62
59
|
expect(smells[0].parameters[:name]).to eq('x')
|
63
60
|
expect(smells[0].lines).to eq([1, 1])
|
64
61
|
end
|
65
62
|
|
66
63
|
it 'reports a bad name inside a block' do
|
67
64
|
src = 'def clean(text) text.each { q2 = 3 } end'
|
68
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'q2')
|
65
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'q2')
|
69
66
|
end
|
70
67
|
|
71
68
|
it 'reports variable name outside any method' do
|
@@ -82,7 +79,7 @@ describe UncommunicativeVariableName do
|
|
82
79
|
end
|
83
80
|
end
|
84
81
|
EOS
|
85
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
82
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
86
83
|
end
|
87
84
|
|
88
85
|
it 'reports all relevant block parameters' do
|
@@ -91,8 +88,8 @@ describe UncommunicativeVariableName do
|
|
91
88
|
@foo.map { |x, y| x + y }
|
92
89
|
end
|
93
90
|
EOS
|
94
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
95
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
91
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
92
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'y')
|
96
93
|
end
|
97
94
|
|
98
95
|
it 'reports block parameters used outside of methods' do
|
@@ -101,7 +98,7 @@ describe UncommunicativeVariableName do
|
|
101
98
|
@foo.map { |x| x * 2 }
|
102
99
|
end
|
103
100
|
EOS
|
104
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
101
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
105
102
|
end
|
106
103
|
|
107
104
|
it 'reports splatted block parameters correctly' do
|
@@ -110,7 +107,7 @@ describe UncommunicativeVariableName do
|
|
110
107
|
@foo.map { |*y| y << 1 }
|
111
108
|
end
|
112
109
|
EOS
|
113
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
110
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'y')
|
114
111
|
end
|
115
112
|
|
116
113
|
it 'reports nested block parameters' do
|
@@ -119,8 +116,8 @@ describe UncommunicativeVariableName do
|
|
119
116
|
@foo.map { |(x, y)| x + y }
|
120
117
|
end
|
121
118
|
EOS
|
122
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
123
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
119
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
120
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'y')
|
124
121
|
end
|
125
122
|
|
126
123
|
it 'reports splatted nested block parameters' do
|
@@ -129,8 +126,8 @@ describe UncommunicativeVariableName do
|
|
129
126
|
@foo.map { |(x, *y)| x + y }
|
130
127
|
end
|
131
128
|
EOS
|
132
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'x')
|
133
|
-
expect(src).to reek_of(UncommunicativeVariableName, name: 'y')
|
129
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
130
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'y')
|
134
131
|
end
|
135
132
|
|
136
133
|
it 'reports deeply nested block parameters' do
|
@@ -139,23 +136,23 @@ describe UncommunicativeVariableName do
|
|
139
136
|
@foo.map { |(x, (y, z))| x + y + z }
|
140
137
|
end
|
141
138
|
EOS
|
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')
|
139
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'x')
|
140
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'y')
|
141
|
+
expect(src).to reek_of(:UncommunicativeVariableName, name: 'z')
|
145
142
|
end
|
146
143
|
end
|
147
144
|
|
148
145
|
context 'when a smell is reported' do
|
149
146
|
before :each do
|
150
|
-
src =
|
151
|
-
def bad
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
EOS
|
147
|
+
src = <<-EOS
|
148
|
+
def bad
|
149
|
+
unless @mod then
|
150
|
+
x2 = xy.to_s
|
151
|
+
x2
|
152
|
+
x2 = 56
|
153
|
+
end
|
154
|
+
end
|
155
|
+
EOS
|
159
156
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
160
157
|
@smells = @detector.examine_context(ctx)
|
161
158
|
@warning = @smells[0]
|
@@ -2,72 +2,69 @@ require 'spec_helper'
|
|
2
2
|
require 'reek/smells/unused_parameters'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
|
-
|
6
|
-
include Reek::Smells
|
7
|
-
|
8
|
-
describe UnusedParameters do
|
5
|
+
describe Reek::Smells::UnusedParameters do
|
9
6
|
context 'for methods' do
|
10
7
|
it 'reports nothing for no parameters' do
|
11
|
-
expect('def simple; true end').not_to reek_of(UnusedParameters)
|
8
|
+
expect('def simple; true end').not_to reek_of(:UnusedParameters)
|
12
9
|
end
|
13
10
|
|
14
11
|
it 'reports nothing for used parameter' do
|
15
|
-
expect('def simple(sum); sum end').not_to reek_of(UnusedParameters)
|
12
|
+
expect('def simple(sum); sum end').not_to reek_of(:UnusedParameters)
|
16
13
|
end
|
17
14
|
|
18
15
|
it 'reports for 1 used and 2 unused parameter' do
|
19
16
|
src = 'def simple(num,sum,denum); sum end'
|
20
|
-
expect(src).to reek_of(UnusedParameters, name: 'num')
|
21
|
-
expect(src).to reek_of(UnusedParameters, name: 'denum')
|
17
|
+
expect(src).to reek_of(:UnusedParameters, name: 'num')
|
18
|
+
expect(src).to reek_of(:UnusedParameters, name: 'denum')
|
22
19
|
end
|
23
20
|
|
24
21
|
it 'reports for 3 used and 1 unused parameter' do
|
25
22
|
src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
|
26
|
-
expect(src).to reek_of(UnusedParameters,
|
23
|
+
expect(src).to reek_of(:UnusedParameters,
|
27
24
|
name: 'quotient')
|
28
25
|
end
|
29
26
|
|
30
27
|
it 'reports nothing for used splatted parameter' do
|
31
|
-
expect('def simple(*sum); sum end').not_to reek_of(UnusedParameters)
|
28
|
+
expect('def simple(*sum); sum end').not_to reek_of(:UnusedParameters)
|
32
29
|
end
|
33
30
|
|
34
31
|
it 'reports nothing for unused anonymous parameter' do
|
35
|
-
expect('def simple(_); end').not_to reek_of(UnusedParameters)
|
32
|
+
expect('def simple(_); end').not_to reek_of(:UnusedParameters)
|
36
33
|
end
|
37
34
|
|
38
35
|
it 'reports nothing for named parameters prefixed with _' do
|
39
|
-
expect('def simple(_name); end').not_to reek_of(UnusedParameters)
|
36
|
+
expect('def simple(_name); end').not_to reek_of(:UnusedParameters)
|
40
37
|
end
|
41
38
|
|
42
39
|
it 'reports nothing for unused anonymous splatted parameter' do
|
43
|
-
expect('def simple(*); end').not_to reek_of(UnusedParameters)
|
40
|
+
expect('def simple(*); end').not_to reek_of(:UnusedParameters)
|
44
41
|
end
|
45
42
|
|
46
43
|
it 'reports nothing when using super with implicit arguments' do
|
47
|
-
expect('def simple(*args); super; end').not_to reek_of(UnusedParameters)
|
44
|
+
expect('def simple(*args); super; end').not_to reek_of(:UnusedParameters)
|
48
45
|
end
|
49
46
|
|
50
47
|
it 'reports something when using super explicitely passing no arguments' do
|
51
|
-
expect('def simple(*args); super(); end').to reek_of(UnusedParameters)
|
48
|
+
expect('def simple(*args); super(); end').to reek_of(:UnusedParameters)
|
52
49
|
end
|
53
50
|
|
54
51
|
it 'reports nothing when using super explicitely passing all arguments' do
|
55
|
-
expect('def simple(*args); super(*args); end').not_to reek_of(UnusedParameters)
|
52
|
+
expect('def simple(*args); super(*args); end').not_to reek_of(:UnusedParameters)
|
56
53
|
end
|
57
54
|
|
58
55
|
it 'reports nothing when using super in a nested context' do
|
59
56
|
expect('def simple(*args); call_other("something", super); end').
|
60
|
-
not_to reek_of(UnusedParameters)
|
57
|
+
not_to reek_of(:UnusedParameters)
|
61
58
|
end
|
62
59
|
|
63
60
|
it 'reports something when not using a keyword argument with splat' do
|
64
61
|
expect('def simple(var, kw: :val, **args); @var, @kw = var, kw; end').
|
65
|
-
to reek_of(UnusedParameters)
|
62
|
+
to reek_of(:UnusedParameters)
|
66
63
|
end
|
67
64
|
|
68
65
|
it 'reports nothing when using a keyword argument with splat' do
|
69
66
|
expect('def simple(var, kw: :val, **args); @var, @kw, @args = var, kw, args; end').
|
70
|
-
not_to reek_of(UnusedParameters)
|
67
|
+
not_to reek_of(:UnusedParameters)
|
71
68
|
end
|
72
69
|
end
|
73
70
|
end
|
@@ -2,13 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'reek/smells/utility_function'
|
3
3
|
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
|
-
|
6
|
-
include Reek::Smells
|
7
|
-
|
8
|
-
describe UtilityFunction do
|
5
|
+
describe Reek::Smells::UtilityFunction do
|
9
6
|
before(:each) do
|
10
|
-
@source_name = '
|
11
|
-
@detector = UtilityFunction
|
7
|
+
@source_name = 'dummy_source'
|
8
|
+
@detector = build(:smell_detector, smell_type: :UtilityFunction, source: @source_name)
|
12
9
|
end
|
13
10
|
|
14
11
|
it_should_behave_like 'SmellDetector'
|
@@ -17,7 +14,7 @@ describe UtilityFunction do
|
|
17
14
|
['self', 'local_call', '$global'].each do |receiver|
|
18
15
|
it 'ignores the receiver' do
|
19
16
|
src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end"
|
20
|
-
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
17
|
+
ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
21
18
|
expect(@detector.examine_context(ctx)).to be_empty
|
22
19
|
end
|
23
20
|
end
|
@@ -26,7 +23,7 @@ describe UtilityFunction do
|
|
26
23
|
context 'with no calls' do
|
27
24
|
it 'does not report empty method' do
|
28
25
|
src = 'def simple(arga) end'
|
29
|
-
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
26
|
+
ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
30
27
|
expect(@detector.examine_context(ctx)).to be_empty
|
31
28
|
end
|
32
29
|
|
@@ -122,8 +119,8 @@ describe UtilityFunction do
|
|
122
119
|
end
|
123
120
|
EOS
|
124
121
|
source = src.to_reek_source
|
125
|
-
sniffer = Sniffer.new(source)
|
126
|
-
mctx =
|
122
|
+
sniffer = Reek::Core::Sniffer.new(source)
|
123
|
+
mctx = Reek::Core::TreeWalker.new(sniffer).process_def(source.syntax_tree)
|
127
124
|
@warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
|
128
125
|
end
|
129
126
|
|