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
@@ -18,50 +18,50 @@ describe IrresponsibleModule do
|
|
18
18
|
|
19
19
|
class C; def foo; end; end
|
20
20
|
EOS
|
21
|
-
src.
|
21
|
+
expect(src).not_to reek_of(:IrresponsibleModule)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'does not report a class having a comment' do
|
25
25
|
src = <<EOS
|
26
26
|
# test class
|
27
27
|
class Responsible; end
|
28
28
|
EOS
|
29
29
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
30
|
-
@detector.examine_context(ctx).
|
30
|
+
expect(@detector.examine_context(ctx)).to be_empty
|
31
31
|
end
|
32
|
-
it
|
32
|
+
it 'reports a class without a comment' do
|
33
33
|
src = "class #{@bad_module_name}; end"
|
34
34
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
35
35
|
smells = @detector.examine_context(ctx)
|
36
|
-
smells.length.
|
37
|
-
smells[0].smell_class.
|
38
|
-
smells[0].subclass.
|
39
|
-
smells[0].lines.
|
40
|
-
smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY].
|
36
|
+
expect(smells.length).to eq(1)
|
37
|
+
expect(smells[0].smell_class).to eq(IrresponsibleModule::SMELL_CLASS)
|
38
|
+
expect(smells[0].subclass).to eq(IrresponsibleModule::SMELL_SUBCLASS)
|
39
|
+
expect(smells[0].lines).to eq([1])
|
40
|
+
expect(smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]).to eq(@bad_module_name)
|
41
41
|
end
|
42
|
-
it
|
42
|
+
it 'reports a class with an empty comment' do
|
43
43
|
src = <<EOS
|
44
44
|
#
|
45
45
|
#
|
46
|
-
#
|
46
|
+
#
|
47
47
|
class #{@bad_module_name}; end
|
48
48
|
EOS
|
49
49
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
50
50
|
smells = @detector.examine_context(ctx)
|
51
|
-
smells.length.
|
52
|
-
smells[0].smell_class.
|
53
|
-
smells[0].subclass.
|
54
|
-
smells[0].lines.
|
55
|
-
smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY].
|
51
|
+
expect(smells.length).to eq(1)
|
52
|
+
expect(smells[0].smell_class).to eq(IrresponsibleModule::SMELL_CLASS)
|
53
|
+
expect(smells[0].subclass).to eq(IrresponsibleModule::SMELL_SUBCLASS)
|
54
|
+
expect(smells[0].lines).to eq([4])
|
55
|
+
expect(smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]).to eq(@bad_module_name)
|
56
56
|
end
|
57
57
|
it 'reports a fq module name correctly' do
|
58
58
|
src = 'class Foo::Bar; end'
|
59
59
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
60
60
|
smells = @detector.examine_context(ctx)
|
61
|
-
smells.length.
|
62
|
-
smells[0].smell_class.
|
63
|
-
smells[0].subclass.
|
64
|
-
smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY].
|
65
|
-
smells[0].context.
|
61
|
+
expect(smells.length).to eq(1)
|
62
|
+
expect(smells[0].smell_class).to eq(IrresponsibleModule::SMELL_CLASS)
|
63
|
+
expect(smells[0].subclass).to eq(IrresponsibleModule::SMELL_SUBCLASS)
|
64
|
+
expect(smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]).to eq('Foo::Bar')
|
65
|
+
expect(smells[0].context).to match(/#{smells[0].smell[IrresponsibleModule::MODULE_NAME_KEY]}/)
|
66
66
|
end
|
67
67
|
end
|
@@ -9,31 +9,31 @@ describe LongParameterList do
|
|
9
9
|
|
10
10
|
context 'for methods with few parameters' do
|
11
11
|
it 'should report nothing for no parameters' do
|
12
|
-
'def simple; f(3);true; end'.
|
12
|
+
expect('def simple; f(3);true; end').not_to smell_of(LongParameterList)
|
13
13
|
end
|
14
14
|
it 'should report nothing for 1 parameter' do
|
15
|
-
'def simple(yep) f(3);true end'.
|
15
|
+
expect('def simple(yep) f(3);true end').not_to smell_of(LongParameterList)
|
16
16
|
end
|
17
17
|
it 'should report nothing for 2 parameters' do
|
18
|
-
'def simple(yep,zero) f(3);true end'.
|
18
|
+
expect('def simple(yep,zero) f(3);true end').not_to smell_of(LongParameterList)
|
19
19
|
end
|
20
20
|
it 'should not count an optional block' do
|
21
|
-
'def simple(alpha, yep, zero, &opt) f(3);true end'.
|
21
|
+
expect('def simple(alpha, yep, zero, &opt) f(3);true end').not_to smell_of(LongParameterList)
|
22
22
|
end
|
23
23
|
it 'should not report inner block with too many parameters' do
|
24
24
|
src = 'def simple(yep,zero); m[3]; rand(34); f.each { |arga, argb, argc, argd| true}; end'
|
25
|
-
src.
|
25
|
+
expect(src).not_to smell_of(LongParameterList)
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'and default values' do
|
29
29
|
it 'should report nothing for 1 parameter' do
|
30
|
-
'def simple(zero=nil) f(3);false end'.
|
30
|
+
expect('def simple(zero=nil) f(3);false end').not_to smell_of(LongParameterList)
|
31
31
|
end
|
32
32
|
it 'should report nothing for 2 parameters with 1 default' do
|
33
|
-
'def simple(yep, zero=nil) f(3);false end'.
|
33
|
+
expect('def simple(yep, zero=nil) f(3);false end').not_to smell_of(LongParameterList)
|
34
34
|
end
|
35
35
|
it 'should report nothing for 2 defaulted parameters' do
|
36
|
-
'def simple(yep=4, zero=nil) f(3);false end'.
|
36
|
+
expect('def simple(yep=4, zero=nil) f(3);false end').not_to smell_of(LongParameterList)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -41,21 +41,21 @@ describe LongParameterList do
|
|
41
41
|
describe 'for methods with too many parameters' do
|
42
42
|
it 'should report 4 parameters' do
|
43
43
|
src = 'def simple(arga, argb, argc, argd) f(3);true end'
|
44
|
-
src.
|
44
|
+
expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
|
45
45
|
end
|
46
46
|
it 'should report 8 parameters' do
|
47
47
|
src = 'def simple(arga, argb, argc, argd,arge, argf, argg, argh) f(3);true end'
|
48
|
-
src.
|
48
|
+
expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 8)
|
49
49
|
end
|
50
50
|
|
51
51
|
describe 'and default values' do
|
52
52
|
it 'should report 3 with 1 defaulted' do
|
53
53
|
src = 'def simple(polly, queue, yep, zero=nil) f(3);false end'
|
54
|
-
src.
|
54
|
+
expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
|
55
55
|
end
|
56
56
|
it 'should report with 3 defaulted' do
|
57
57
|
src = 'def simple(aarg, polly=2, yep=:truth, zero=nil) f(3);false end'
|
58
|
-
src.
|
58
|
+
expect(src).to smell_of(LongParameterList, LongParameterList::PARAMETER_COUNT_KEY => 4)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -85,10 +85,10 @@ EOS
|
|
85
85
|
it_should_behave_like 'common fields set correctly'
|
86
86
|
|
87
87
|
it 'reports the number of parameters' do
|
88
|
-
@warning.smell[LongParameterList::PARAMETER_COUNT_KEY].
|
88
|
+
expect(@warning.smell[LongParameterList::PARAMETER_COUNT_KEY]).to eq(4)
|
89
89
|
end
|
90
90
|
it 'reports the line number of the method' do
|
91
|
-
@warning.lines.
|
91
|
+
expect(@warning.lines).to eq([1])
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -18,19 +18,19 @@ describe LongYieldList do
|
|
18
18
|
context 'yield' do
|
19
19
|
it 'should not report yield with no parameters' do
|
20
20
|
src = 'def simple(arga, argb, &blk) f(3);yield; end'
|
21
|
-
src.
|
21
|
+
expect(src).not_to smell_of(LongYieldList)
|
22
22
|
end
|
23
23
|
it 'should not report yield with few parameters' do
|
24
24
|
src = 'def simple(arga, argb, &blk) f(3);yield a,b; end'
|
25
|
-
src.
|
25
|
+
expect(src).not_to smell_of(LongYieldList)
|
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
|
-
src.
|
29
|
+
expect(src).to smell_of(LongYieldList, LongYieldList::PARAMETER_COUNT_KEY => 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'
|
33
|
-
src.
|
33
|
+
expect(src).not_to smell_of(LongYieldList)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -50,8 +50,8 @@ EOS
|
|
50
50
|
it_should_behave_like 'common fields set correctly'
|
51
51
|
|
52
52
|
it 'reports the correct values' do
|
53
|
-
@warning.smell['parameter_count'].
|
54
|
-
@warning.lines.
|
53
|
+
expect(@warning.smell['parameter_count']).to eq(4)
|
54
|
+
expect(@warning.lines).to eq([3])
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -9,20 +9,20 @@ describe NestedIterators do
|
|
9
9
|
context 'with no iterators' do
|
10
10
|
it 'reports no smells' do
|
11
11
|
src = 'def fred() nothing = true; end'
|
12
|
-
src.
|
12
|
+
expect(src).not_to smell_of(NestedIterators)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with one iterator' do
|
17
17
|
it 'reports no smells' do
|
18
18
|
src = 'def fred() nothing.each {|item| item}; end'
|
19
|
-
src.
|
19
|
+
expect(src).not_to smell_of(NestedIterators)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should report nested iterators in a method' do
|
24
24
|
src = 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ting} } end'
|
25
|
-
src.
|
25
|
+
expect(src).to smell_of(NestedIterators)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should not report method with successive iterators' do
|
@@ -32,7 +32,7 @@ def bad(fred)
|
|
32
32
|
@jim.each {|ting| ting.each }
|
33
33
|
end
|
34
34
|
EOS
|
35
|
-
src.
|
35
|
+
expect(src).not_to smell_of(NestedIterators)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should not report method with chained iterators' do
|
@@ -41,7 +41,7 @@ def chained
|
|
41
41
|
@sig.keys.sort_by { |xray| xray.to_s }.each { |min| md5 << min.to_s }
|
42
42
|
end
|
43
43
|
EOS
|
44
|
-
src.
|
44
|
+
expect(src).not_to smell_of(NestedIterators)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should report nested iterators only once per method' do
|
@@ -51,7 +51,7 @@ def bad(fred)
|
|
51
51
|
@jim.each {|ting| ting.each {|piece| @hal.send} }
|
52
52
|
end
|
53
53
|
EOS
|
54
|
-
src.
|
54
|
+
expect(src).to smell_of(NestedIterators, {})
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'reports nested iterators only once per method even if levels are different' do
|
@@ -61,7 +61,7 @@ EOS
|
|
61
61
|
@jim.each {|ting| ting.each {|piece| piece.each {|atom| atom.foo } } }
|
62
62
|
end
|
63
63
|
EOS
|
64
|
-
src.
|
64
|
+
expect(src).to smell_of(NestedIterators, {})
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'reports nesting inside iterator arguments' do
|
@@ -76,7 +76,7 @@ EOS
|
|
76
76
|
) { |qux| qux.quuz }
|
77
77
|
end
|
78
78
|
EOS
|
79
|
-
src.
|
79
|
+
expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2)
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'reports the deepest level of nesting only' do
|
@@ -89,12 +89,12 @@ EOS
|
|
89
89
|
}
|
90
90
|
end
|
91
91
|
EOS
|
92
|
-
src.
|
92
|
+
expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 3)
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'when the allowed nesting depth is 3' do
|
96
96
|
before :each do
|
97
|
-
@config = {NestedIterators::MAX_ALLOWED_NESTING_KEY => 3}
|
97
|
+
@config = { NestedIterators::MAX_ALLOWED_NESTING_KEY => 3 }
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should not report nested iterators 2 levels deep' do
|
@@ -103,7 +103,7 @@ def bad(fred)
|
|
103
103
|
@fred.each {|one| one.each {|two| two.two} }
|
104
104
|
end
|
105
105
|
EOS
|
106
|
-
src.
|
106
|
+
expect(src).not_to smell_of(NestedIterators).with_config(@config)
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should not report nested iterators 3 levels deep' do
|
@@ -112,7 +112,7 @@ def bad(fred)
|
|
112
112
|
@fred.each {|one| one.each {|two| two.each {|three| three.three} } }
|
113
113
|
end
|
114
114
|
EOS
|
115
|
-
src.
|
115
|
+
expect(src).not_to smell_of(NestedIterators).with_config(@config)
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should report nested iterators 4 levels deep' do
|
@@ -121,38 +121,38 @@ def bad(fred)
|
|
121
121
|
@fred.each {|one| one.each {|two| two.each {|three| three.each {|four| four.four} } } }
|
122
122
|
end
|
123
123
|
EOS
|
124
|
-
src.
|
124
|
+
expect(src).to smell_of(NestedIterators).with_config(@config)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
context 'when ignoring iterators' do
|
129
129
|
before :each do
|
130
|
-
@config = {NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me']}
|
130
|
+
@config = { NestedIterators::IGNORE_ITERATORS_KEY => ['ignore_me'] }
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'should not report nesting the ignored iterator inside another' do
|
134
134
|
src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting} } end'
|
135
|
-
src.
|
135
|
+
expect(src).not_to smell_of(NestedIterators).with_config(@config)
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should not report nesting inside the ignored iterator' do
|
139
139
|
src = 'def bad(fred) @fred.ignore_me {|item| item.each {|ting| ting.ting} } end'
|
140
|
-
src.
|
140
|
+
expect(src).not_to smell_of(NestedIterators).with_config(@config)
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'should report nested iterators inside the ignored iterator' do
|
144
144
|
src = 'def bad(fred) @fred.ignore_me {|item| item.each {|ting| ting.each {|other| other.other} } } end'
|
145
|
-
src.
|
145
|
+
expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'should report nested iterators outside the ignored iterator' do
|
149
149
|
src = 'def bad(fred) @fred.each {|item| item.each {|ting| ting.ignore_me {|other| other.other} } } end'
|
150
|
-
src.
|
150
|
+
expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'should report nested iterators with the ignored iterator between them' do
|
154
154
|
src = 'def bad(fred) @fred.each {|item| item.ignore_me {|ting| ting.ting {|other| other.other} } } end'
|
155
|
-
src.
|
155
|
+
expect(src).to smell_of(NestedIterators, NestedIterators::NESTING_DEPTH_KEY => 2).with_config(@config)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -181,8 +181,8 @@ EOS
|
|
181
181
|
it_should_behave_like 'common fields set correctly'
|
182
182
|
|
183
183
|
it 'reports correct values' do
|
184
|
-
@warning.smell[NestedIterators::NESTING_DEPTH_KEY].
|
185
|
-
@warning.lines.
|
184
|
+
expect(@warning.smell[NestedIterators::NESTING_DEPTH_KEY]).to eq(2)
|
185
|
+
expect(@warning.lines).to eq([3])
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
@@ -18,14 +18,14 @@ describe NilCheck do
|
|
18
18
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
19
19
|
detector = NilCheck.new('source_name')
|
20
20
|
smells = detector.examine_context(ctx)
|
21
|
-
smells[0].lines.
|
21
|
+
expect(smells[0].lines).to eq [2]
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
25
|
-
'def no_nils; end'.
|
24
|
+
it 'reports nothing when scope includes no nil checks' do
|
25
|
+
expect('def no_nils; end').not_to smell_of(NilCheck)
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
28
|
+
it 'reports when scope uses multiple nil? methods' do
|
29
29
|
src = <<-eos
|
30
30
|
def chk_multi_nil(para)
|
31
31
|
para.nil?
|
@@ -33,26 +33,24 @@ describe NilCheck do
|
|
33
33
|
\"\".nil?
|
34
34
|
end
|
35
35
|
eos
|
36
|
-
src.
|
37
|
-
{NilCheck => nil}, {NilCheck => nil})
|
36
|
+
expect(src).to smell_of(NilCheck, {}, {})
|
38
37
|
end
|
39
38
|
|
40
|
-
it '
|
41
|
-
src= <<-eos
|
39
|
+
it 'reports twice when scope uses == nil and === nil' do
|
40
|
+
src = <<-eos
|
42
41
|
def chk_eq_nil(para)
|
43
42
|
para == nil
|
44
43
|
para === nil
|
45
44
|
end
|
46
45
|
eos
|
47
|
-
src.
|
48
|
-
{NilCheck => nil}, {NilCheck => nil})
|
46
|
+
expect(src).to smell_of(NilCheck, {}, {})
|
49
47
|
end
|
50
48
|
|
51
|
-
it '
|
52
|
-
'def chk_eq_nil_rev(para); nil == para; end'.
|
49
|
+
it 'reports when scope uses nil ==' do
|
50
|
+
expect('def chk_eq_nil_rev(para); nil == para; end').to smell_of(NilCheck)
|
53
51
|
end
|
54
52
|
|
55
|
-
it '
|
53
|
+
it 'reports when scope uses multiple case-clauses checking nil' do
|
56
54
|
src = <<-eos
|
57
55
|
def case_nil
|
58
56
|
case @inst_var
|
@@ -65,8 +63,18 @@ describe NilCheck do
|
|
65
63
|
end
|
66
64
|
end
|
67
65
|
eos
|
68
|
-
src.
|
69
|
-
|
66
|
+
expect(src).to smell_of(NilCheck, {}, {})
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'reports a when clause that checks nil and other values' do
|
70
|
+
src = <<-eos
|
71
|
+
def case_nil
|
72
|
+
case @inst_var
|
73
|
+
when nil, false then puts "Hello"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
eos
|
77
|
+
expect(src).to smell_of(NilCheck)
|
70
78
|
end
|
71
79
|
end
|
72
80
|
end
|
@@ -7,11 +7,11 @@ include Reek::Smells
|
|
7
7
|
|
8
8
|
describe PrimaDonnaMethod do
|
9
9
|
it 'should report nothing when method and bang counterpart exist' do
|
10
|
-
'class C; def m; end; def m!; end; end'.
|
10
|
+
expect('class C; def m; end; def m!; end; end').not_to smell_of(PrimaDonnaMethod)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should report PrimaDonnaMethod when only bang method exists' do
|
14
|
-
'class C; def m!; end; end'.
|
14
|
+
expect('class C; def m!; end; end').to smell_of(PrimaDonnaMethod)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'the right smell' do
|
@@ -23,9 +23,9 @@ describe PrimaDonnaMethod do
|
|
23
23
|
smells = detector.examine_context(ctx)
|
24
24
|
warning = smells[0]
|
25
25
|
|
26
|
-
warning.smell['class'].
|
27
|
-
warning.smell['subclass'].
|
28
|
-
warning.lines.
|
26
|
+
expect(warning.smell['class']).to eq('PrimaDonnaMethod')
|
27
|
+
expect(warning.smell['subclass']).to eq('PrimaDonnaMethod')
|
28
|
+
expect(warning.lines).to eq([1])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -18,7 +18,7 @@ describe RepeatedConditional do
|
|
18
18
|
it 'gathers an empty hash' do
|
19
19
|
ast = 'module Stable; end'.to_reek_source.syntax_tree
|
20
20
|
ctx = CodeContext.new(nil, ast)
|
21
|
-
@detector.conditional_counts(ctx).length.
|
21
|
+
expect(@detector.conditional_counts(ctx).length).to eq(0)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,7 @@ describe RepeatedConditional do
|
|
26
26
|
it 'does not record the condition' do
|
27
27
|
ast = 'def fred() yield(3) if block_given?; end'.to_reek_source.syntax_tree
|
28
28
|
ctx = CodeContext.new(nil, ast)
|
29
|
-
@detector.conditional_counts(ctx).length.
|
29
|
+
expect(@detector.conditional_counts(ctx).length).to eq(0)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ describe RepeatedConditional do
|
|
34
34
|
it 'does not record the condition' do
|
35
35
|
ast = 'def fred() case; when 3; end; end'.to_reek_source.syntax_tree
|
36
36
|
ctx = CodeContext.new(nil, ast)
|
37
|
-
@detector.conditional_counts(ctx).length.
|
37
|
+
expect(@detector.conditional_counts(ctx).length).to eq(0)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -64,10 +64,10 @@ EOS
|
|
64
64
|
@conds = @detector.conditional_counts(@ctx)
|
65
65
|
end
|
66
66
|
it 'finds both conditionals' do
|
67
|
-
@conds.length.
|
67
|
+
expect(@conds.length).to eq(2)
|
68
68
|
end
|
69
69
|
it 'knows there are three copies' do
|
70
|
-
@conds[@cond_expr].length.
|
70
|
+
expect(@conds[@cond_expr].length).to eq(3)
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'looking at the YAML' do
|
@@ -77,22 +77,22 @@ EOS
|
|
77
77
|
@yaml = warning.to_yaml
|
78
78
|
end
|
79
79
|
it 'reports the source' do
|
80
|
-
@yaml.
|
80
|
+
expect(@yaml).to match(/source:\s*#{@source_name}/)
|
81
81
|
end
|
82
82
|
it 'reports the class' do
|
83
|
-
@yaml.
|
83
|
+
expect(@yaml).to match(/class:\s*SimulatedPolymorphism/)
|
84
84
|
end
|
85
85
|
it 'reports the subclass' do
|
86
|
-
@yaml.
|
86
|
+
expect(@yaml).to match(/subclass:\s*RepeatedConditional/)
|
87
87
|
end
|
88
88
|
it 'reports the expression' do
|
89
|
-
@yaml.
|
89
|
+
expect(@yaml).to match(/expression:\s*"?\(#{@cond}\)"?/)
|
90
90
|
end
|
91
91
|
it 'reports the number of occurrences' do
|
92
|
-
@yaml.
|
92
|
+
expect(@yaml).to match(/occurrences:\s*3/)
|
93
93
|
end
|
94
94
|
it 'reports the referring lines' do
|
95
|
-
@yaml.
|
95
|
+
expect(@yaml).to match(/lines:\s*- 4\s*- 7\s*- 12/)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -120,13 +120,13 @@ EOS
|
|
120
120
|
@conds = @detector.conditional_counts(ctx)
|
121
121
|
end
|
122
122
|
it 'finds exactly one conditional' do
|
123
|
-
@conds.length.
|
123
|
+
expect(@conds.length).to eq(1)
|
124
124
|
end
|
125
125
|
it 'returns the condition expr' do
|
126
|
-
@conds.keys[0].
|
126
|
+
expect(@conds.keys[0]).to eq(@cond_expr)
|
127
127
|
end
|
128
128
|
it 'knows there are three copies' do
|
129
|
-
@conds[@cond_expr].length.
|
129
|
+
expect(@conds[@cond_expr].length).to eq(2)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|