reek 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -0
- data/README.md +15 -9
- data/bin/reek +1 -1
- data/config/defaults.reek +71 -86
- data/features/command_line_interface/options.feature +0 -15
- data/features/reports/reports.feature +23 -0
- data/features/samples.feature +3 -12
- data/lib/reek.rb +3 -3
- data/lib/reek/cli/application.rb +1 -1
- data/lib/reek/cli/command_line.rb +10 -8
- data/lib/reek/cli/reek_command.rb +6 -7
- data/lib/reek/cli/report.rb +34 -38
- data/lib/reek/cli/version_command.rb +1 -1
- data/lib/reek/cli/yaml_command.rb +1 -1
- data/lib/reek/core/code_parser.rb +4 -4
- data/lib/reek/core/hash_extensions.rb +2 -2
- data/lib/reek/core/method_context.rb +2 -2
- data/lib/reek/core/module_context.rb +4 -4
- data/lib/reek/core/singleton_method_context.rb +1 -1
- data/lib/reek/core/smell_repository.rb +7 -6
- data/lib/reek/core/sniffer.rb +4 -4
- data/lib/reek/examiner.rb +10 -3
- data/lib/reek/smell_warning.rb +0 -2
- data/lib/reek/smells.rb +22 -21
- data/lib/reek/smells/attribute.rb +4 -8
- data/lib/reek/smells/boolean_parameter.rb +2 -2
- data/lib/reek/smells/class_variable.rb +3 -2
- data/lib/reek/smells/{control_couple.rb → control_parameter.rb} +5 -5
- data/lib/reek/smells/data_clump.rb +13 -29
- data/lib/reek/smells/{duplication.rb → duplicate_method_call.rb} +9 -11
- data/lib/reek/smells/feature_envy.rb +2 -2
- data/lib/reek/smells/irresponsible_module.rb +3 -2
- data/lib/reek/smells/long_parameter_list.rb +6 -10
- data/lib/reek/smells/long_yield_list.rb +4 -8
- data/lib/reek/smells/nested_iterators.rb +31 -25
- data/lib/reek/smells/nil_check.rb +11 -12
- data/lib/reek/smells/{simulated_polymorphism.rb → repeated_conditional.rb} +6 -10
- data/lib/reek/smells/smell_detector.rb +3 -6
- data/lib/reek/smells/too_many_instance_variables.rb +60 -0
- data/lib/reek/smells/too_many_methods.rb +62 -0
- data/lib/reek/smells/{long_method.rb → too_many_statements.rb} +7 -12
- data/lib/reek/smells/uncommunicative_method_name.rb +3 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +3 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
- data/lib/reek/smells/uncommunicative_variable_name.rb +5 -9
- data/lib/reek/smells/unused_parameters.rb +62 -13
- data/lib/reek/smells/utility_function.rb +3 -7
- data/lib/reek/source.rb +8 -8
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/source_code.rb +2 -2
- data/lib/reek/source/source_file.rb +2 -2
- data/lib/reek/source/source_locator.rb +1 -1
- data/lib/reek/source/source_repository.rb +4 -2
- data/lib/reek/spec.rb +9 -3
- data/lib/reek/spec/should_reek.rb +2 -2
- data/lib/reek/spec/should_reek_of.rb +1 -1
- data/lib/reek/spec/should_reek_only_of.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +3 -1
- data/spec/gem/updates_spec.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/matchers/smell_of_matcher.rb +53 -19
- data/spec/reek/cli/help_command_spec.rb +2 -2
- data/spec/reek/cli/reek_command_spec.rb +6 -6
- data/spec/reek/cli/report_spec.rb +6 -6
- data/spec/reek/cli/version_command_spec.rb +2 -2
- data/spec/reek/cli/yaml_command_spec.rb +2 -2
- data/spec/reek/core/code_context_spec.rb +4 -4
- data/spec/reek/core/code_parser_spec.rb +2 -2
- data/spec/reek/core/config_spec.rb +4 -4
- data/spec/reek/core/method_context_spec.rb +3 -3
- data/spec/reek/core/module_context_spec.rb +3 -3
- data/spec/reek/core/object_refs_spec.rb +3 -3
- data/spec/reek/core/singleton_method_context_spec.rb +4 -4
- data/spec/reek/core/smell_configuration_spec.rb +2 -2
- 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 +13 -4
- data/spec/reek/smell_warning_spec.rb +2 -2
- data/spec/reek/smells/attribute_spec.rb +4 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +3 -3
- data/spec/reek/smells/class_variable_spec.rb +4 -4
- data/spec/reek/smells/{control_couple_spec.rb → control_parameter_spec.rb} +10 -10
- data/spec/reek/smells/data_clump_spec.rb +3 -3
- data/spec/reek/smells/{duplication_spec.rb → duplicate_method_call_spec.rb} +42 -26
- data/spec/reek/smells/feature_envy_spec.rb +3 -3
- data/spec/reek/smells/irresponsible_module_spec.rb +3 -3
- data/spec/reek/smells/long_parameter_list_spec.rb +3 -3
- data/spec/reek/smells/long_yield_list_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +42 -4
- data/spec/reek/smells/nil_check_spec.rb +23 -11
- data/spec/reek/smells/{simulated_polymorphism_spec.rb → repeated_conditional_spec.rb} +6 -6
- data/spec/reek/smells/smell_detector_shared.rb +2 -2
- data/spec/reek/smells/too_many_instance_variables_spec.rb +62 -0
- data/spec/reek/smells/{large_class_spec.rb → too_many_methods_spec.rb} +11 -56
- data/spec/reek/smells/{long_method_spec.rb → too_many_statements_spec.rb} +17 -17
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +5 -5
- 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 +5 -5
- data/spec/reek/smells/unused_parameters_spec.rb +19 -4
- data/spec/reek/smells/utility_function_spec.rb +3 -3
- data/spec/reek/source/code_comment_spec.rb +2 -2
- data/spec/reek/source/object_source_spec.rb +1 -1
- data/spec/reek/source/reference_collector_spec.rb +2 -2
- data/spec/reek/source/sexp_formatter_spec.rb +2 -2
- data/spec/reek/source/source_code_spec.rb +2 -2
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +2 -2
- data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
- data/spec/reek/spec/should_reek_spec.rb +2 -2
- data/spec/samples/all_but_one_masked/masked.reek +1 -1
- data/spec/samples/clean_due_to_masking/masked.reek +1 -1
- data/spec/samples/config/allow_duplication.reek +2 -2
- data/spec/samples/inline_config/dirty.rb +2 -2
- data/spec/samples/mask_some/some.reek +1 -1
- data/spec/samples/masked_by_dotfile/dirty.rb +8 -0
- data/spec/samples/not_quite_masked/smelly.rb +3 -0
- data/spec/samples/overrides/masked/lower.reek +1 -1
- data/spec/samples/overrides/upper.reek +1 -1
- data/spec/spec_helper.rb +4 -9
- data/tasks/test.rake +0 -2
- metadata +253 -263
- data/lib/reek/smells/large_class.rb +0 -87
- data/lib/xp.reek +0 -66
- data/spec/gem/manifest_spec.rb +0 -22
- data/spec/spec.opts +0 -1
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/cli/help_command'
|
3
3
|
|
4
4
|
include Reek::Cli
|
5
5
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/cli/reek_command'
|
3
|
+
require 'reek/cli/report'
|
4
|
+
require 'reek/examiner'
|
5
5
|
|
6
6
|
include Reek
|
7
7
|
include Reek::Cli
|
@@ -14,7 +14,7 @@ describe ReekCommand do
|
|
14
14
|
context 'with smells' do
|
15
15
|
before :each do
|
16
16
|
examiner = Examiner.new('def x(); end')
|
17
|
-
@cmd = ReekCommand.new(QuietReport, ['def x(); end'])
|
17
|
+
@cmd = ReekCommand.new(QuietReport.new, ['def x(); end'])
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'displays the correct text on the view' do
|
@@ -30,7 +30,7 @@ describe ReekCommand do
|
|
30
30
|
|
31
31
|
context 'with no smells' do
|
32
32
|
before :each do
|
33
|
-
@cmd = ReekCommand.new(QuietReport, ['def clean(); end'])
|
33
|
+
@cmd = ReekCommand.new(QuietReport.new, ['def clean(); end'])
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'displays nothing on the view' do
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/examiner'
|
3
|
+
require 'reek/cli/report'
|
4
4
|
|
5
5
|
include Reek
|
6
6
|
include Reek::Cli
|
@@ -9,15 +9,15 @@ describe QuietReport, " when empty" do
|
|
9
9
|
context 'empty source' do
|
10
10
|
it 'has an empty quiet_report' do
|
11
11
|
examiner = Examiner.new('')
|
12
|
-
QuietReport.new(examiner).
|
12
|
+
QuietReport.new.report(examiner).should == ''
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with a couple of smells' do
|
17
17
|
before :each do
|
18
18
|
examiner = Examiner.new('def simple(a) a[3] end')
|
19
|
-
rpt = QuietReport.new
|
20
|
-
@lines = rpt.report.split("\n")
|
19
|
+
rpt = QuietReport.new
|
20
|
+
@lines = rpt.report(examiner).split("\n")
|
21
21
|
end
|
22
22
|
it 'has a header and a list of smells' do
|
23
23
|
@lines.should have_at_least(3).lines
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/cli/version_command'
|
3
3
|
|
4
4
|
include Reek
|
5
5
|
include Reek::Cli
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/cli/yaml_command'
|
3
3
|
|
4
4
|
include Reek
|
5
5
|
include Reek::Cli
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/method_context'
|
3
|
+
require 'reek/core/module_context'
|
4
|
+
require 'reek/core/stop_context'
|
5
5
|
|
6
6
|
include Reek::Core
|
7
7
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/code_parser'
|
3
3
|
|
4
4
|
include Reek::Core
|
5
5
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/sniffer'
|
3
3
|
|
4
4
|
describe Hash do
|
5
5
|
before :each do
|
@@ -17,12 +17,12 @@ describe Hash do
|
|
17
17
|
@first['two']['four'].should == false
|
18
18
|
@first['one'].keys.length.should == 3
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'should deep copy Hashes' do
|
22
22
|
second = @first.deep_copy
|
23
23
|
second['two'].object_id.should_not be_eql(@first['two'].object_id)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it 'should merge array values' do
|
27
27
|
@first['three'] = [1,2,3]
|
28
28
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/method_context'
|
3
|
+
require 'reek/core/stop_context'
|
4
4
|
|
5
5
|
include Reek::Core
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/module_context'
|
3
|
+
require 'reek/core/stop_context'
|
4
4
|
|
5
5
|
include Reek::Core
|
6
6
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/object_refs'
|
3
3
|
|
4
4
|
include Reek::Core
|
5
5
|
|
@@ -33,7 +33,7 @@ describe ObjectRefs do
|
|
33
33
|
it 'should not report self as the max' do
|
34
34
|
@refs.self_is_max?.should == false
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context "with one reference to self" do
|
38
38
|
before(:each) do
|
39
39
|
@refs.record_reference_to(:self)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/module_context'
|
3
|
+
require 'reek/core/singleton_method_context'
|
4
|
+
require 'reek/core/stop_context'
|
5
5
|
|
6
6
|
include Reek::Core
|
7
7
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/smell_configuration'
|
3
3
|
|
4
4
|
include Reek::Core
|
5
5
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/stop_context'
|
3
3
|
|
4
4
|
include Reek
|
5
5
|
include Reek::Core
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/core/warning_collector'
|
3
|
+
require 'reek/smell_warning'
|
4
4
|
|
5
5
|
include Reek::Core
|
6
6
|
|
data/spec/reek/examiner_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/examiner'
|
3
3
|
|
4
4
|
include Reek
|
5
5
|
|
@@ -65,7 +65,7 @@ describe Examiner do
|
|
65
65
|
it_should_behave_like 'one smell found'
|
66
66
|
end
|
67
67
|
|
68
|
-
context 'with a smelly Dir' do
|
68
|
+
context 'with a partially masked smelly Dir' do
|
69
69
|
before :each do
|
70
70
|
smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
|
71
71
|
@examiner = Examiner.new(smelly_dir)
|
@@ -83,7 +83,16 @@ describe Examiner do
|
|
83
83
|
it_should_behave_like 'no smells found'
|
84
84
|
end
|
85
85
|
|
86
|
-
context 'with a smelly
|
86
|
+
context 'with a smelly Dir masked by a dotfile' do
|
87
|
+
before :each do
|
88
|
+
smelly_dir = Dir['spec/samples/masked_by_dotfile/*.rb']
|
89
|
+
@examiner = Examiner.new(smelly_dir)
|
90
|
+
end
|
91
|
+
|
92
|
+
it_should_behave_like 'one smell found'
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with a partially masked smelly File' do
|
87
96
|
before :each do
|
88
97
|
smelly_file = File.new(Dir['spec/samples/all_but_one_masked/d*.rb'][0])
|
89
98
|
@examiner = Examiner.new(smelly_file)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smell_warning'
|
3
3
|
|
4
4
|
include Reek
|
5
5
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/attribute'
|
3
|
+
require 'reek/core/module_context'
|
4
|
+
require 'reek/smells/smell_detector_shared'
|
5
5
|
|
6
6
|
include Reek::Core
|
7
7
|
include Reek::Smells
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/boolean_parameter'
|
3
|
+
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
5
|
include Reek::Smells
|
6
6
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/class_variable'
|
3
|
+
require 'reek/core/module_context'
|
4
|
+
require 'reek/smells/smell_detector_shared'
|
5
5
|
|
6
6
|
include Reek::Core
|
7
7
|
include Reek::Smells
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/control_parameter'
|
3
|
+
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
5
|
include Reek::Smells
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe ControlParameter do
|
8
8
|
before(:each) do
|
9
9
|
@source_name = 'lets get married'
|
10
|
-
@detector =
|
10
|
+
@detector = ControlParameter.new(@source_name)
|
11
11
|
end
|
12
12
|
|
13
13
|
it_should_behave_like 'SmellDetector'
|
@@ -15,19 +15,19 @@ describe ControlCouple do
|
|
15
15
|
context 'conditional on a parameter' do
|
16
16
|
it 'should report a ternary check on a parameter' do
|
17
17
|
src = 'def simple(arga) arga ? @ivar : 3 end'
|
18
|
-
src.should smell_of(
|
18
|
+
src.should smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arga')
|
19
19
|
end
|
20
20
|
it 'should not report a ternary check on an ivar' do
|
21
21
|
src = 'def simple(arga) @ivar ? arga : 3 end'
|
22
|
-
src.should_not smell_of(
|
22
|
+
src.should_not smell_of(ControlParameter)
|
23
23
|
end
|
24
24
|
it 'should not report a ternary check on a lvar' do
|
25
25
|
src = 'def simple(arga) lvar = 27; lvar ? arga : @ivar end'
|
26
|
-
src.should_not smell_of(
|
26
|
+
src.should_not smell_of(ControlParameter)
|
27
27
|
end
|
28
28
|
it 'should spot a couple inside a block' do
|
29
29
|
src = 'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end'
|
30
|
-
src.should smell_of(
|
30
|
+
src.should smell_of(ControlParameter, ControlParameter::PARAMETER_KEY => 'arg')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -50,7 +50,7 @@ EOS
|
|
50
50
|
it_should_behave_like 'common fields set correctly'
|
51
51
|
|
52
52
|
it 'has the correct fields' do
|
53
|
-
@warning.smell[
|
53
|
+
@warning.smell[ControlParameter::PARAMETER_KEY].should == 'arg'
|
54
54
|
@warning.lines.should == [3, 5]
|
55
55
|
end
|
56
56
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/data_clump'
|
3
|
+
require 'reek/smells/smell_detector_shared'
|
4
4
|
|
5
5
|
include Reek::Smells
|
6
6
|
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reek/smells/duplicate_method_call'
|
3
|
+
require 'reek/core/code_parser'
|
4
|
+
require 'reek/core/sniffer'
|
5
|
+
require 'reek/smells/smell_detector_shared'
|
6
6
|
|
7
7
|
include Reek
|
8
8
|
include Reek::Smells
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe DuplicateMethodCall do
|
11
11
|
|
12
12
|
context 'when a smell is reported' do
|
13
13
|
before :each do
|
14
14
|
@source_name = 'copy-cat'
|
15
|
-
@detector =
|
15
|
+
@detector = DuplicateMethodCall.new(@source_name)
|
16
16
|
src = <<EOS
|
17
17
|
def double_thing(other)
|
18
18
|
other[@thing]
|
@@ -30,7 +30,7 @@ EOS
|
|
30
30
|
it_should_behave_like 'common fields set correctly'
|
31
31
|
|
32
32
|
it 'reports the call' do
|
33
|
-
@warning.smell[
|
33
|
+
@warning.smell[DuplicateMethodCall::CALL_KEY].should == 'other[@thing]'
|
34
34
|
end
|
35
35
|
it 'reports the correct lines' do
|
36
36
|
@warning.lines.should == [2,4]
|
@@ -40,31 +40,47 @@ EOS
|
|
40
40
|
context "with repeated method calls" do
|
41
41
|
it 'reports repeated call' do
|
42
42
|
src = 'def double_thing() @other.thing + @other.thing end'
|
43
|
-
src.should smell_of(
|
43
|
+
src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing')
|
44
44
|
end
|
45
45
|
it 'reports repeated call to lvar' do
|
46
46
|
src = 'def double_thing(other) other[@thing] + other[@thing] end'
|
47
|
-
src.should smell_of(
|
47
|
+
src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => 'other[@thing]')
|
48
48
|
end
|
49
49
|
it 'reports call parameters' do
|
50
50
|
src = 'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'
|
51
|
-
src.should smell_of(
|
51
|
+
src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing(2, 3)')
|
52
52
|
end
|
53
53
|
it 'should report nested calls' do
|
54
54
|
src = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
55
|
-
src.should smell_of(
|
56
|
-
{
|
55
|
+
src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'},
|
56
|
+
{DuplicateMethodCall::CALL_KEY => '@other.thing.foo'})
|
57
57
|
end
|
58
58
|
it 'should ignore calls to new' do
|
59
59
|
src = 'def double_thing() @other.new + @other.new end'
|
60
|
-
src.should_not smell_of(
|
60
|
+
src.should_not smell_of(DuplicateMethodCall)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with repeated simple method calls" do
|
65
|
+
it 'reports no smell' do
|
66
|
+
src = <<-EOS
|
67
|
+
def foo
|
68
|
+
case bar
|
69
|
+
when :baz
|
70
|
+
:qux
|
71
|
+
else
|
72
|
+
bar
|
73
|
+
end
|
74
|
+
end
|
75
|
+
EOS
|
76
|
+
src.should_not smell_of(DuplicateMethodCall)
|
61
77
|
end
|
62
78
|
end
|
63
79
|
|
64
80
|
context 'with repeated attribute assignment' do
|
65
81
|
it 'reports repeated assignment' do
|
66
82
|
src = 'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'
|
67
|
-
src.should smell_of(
|
83
|
+
src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other[thing] = true')
|
68
84
|
end
|
69
85
|
it 'does not report multi-assignments' do
|
70
86
|
src = <<EOS
|
@@ -73,54 +89,54 @@ def _parse ctxt
|
|
73
89
|
error, ctxt.index = @err, @err_ind
|
74
90
|
end
|
75
91
|
EOS
|
76
|
-
src.should_not smell_of(
|
92
|
+
src.should_not smell_of(DuplicateMethodCall)
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
80
96
|
context "non-repeated method calls" do
|
81
97
|
it 'should not report similar calls' do
|
82
98
|
src = 'def equals(other) other.thing == self.thing end'
|
83
|
-
src.should_not smell_of(
|
99
|
+
src.should_not smell_of(DuplicateMethodCall)
|
84
100
|
end
|
85
101
|
it 'should respect call parameters' do
|
86
102
|
src = 'def double_thing() @other.thing(3) + @other.thing(2) end'
|
87
|
-
src.should_not smell_of(
|
103
|
+
src.should_not smell_of(DuplicateMethodCall)
|
88
104
|
end
|
89
105
|
end
|
90
106
|
|
91
107
|
context "allowing up to 3 calls" do
|
92
108
|
before :each do
|
93
|
-
@config = {
|
109
|
+
@config = {DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3}
|
94
110
|
end
|
95
111
|
it 'does not report double calls' do
|
96
112
|
src = 'def double_thing() @other.thing + @other.thing end'
|
97
|
-
src.should_not smell_of(
|
113
|
+
src.should_not smell_of(DuplicateMethodCall).with_config(@config)
|
98
114
|
end
|
99
115
|
it 'does not report triple calls' do
|
100
116
|
src = 'def double_thing() @other.thing + @other.thing + @other.thing end'
|
101
|
-
src.should_not smell_of(
|
117
|
+
src.should_not smell_of(DuplicateMethodCall).with_config(@config)
|
102
118
|
end
|
103
119
|
it 'reports quadruple calls' do
|
104
120
|
src = 'def double_thing() @other.thing + @other.thing + @other.thing + @other.thing end'
|
105
|
-
src.should smell_of(
|
121
|
+
src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing', DuplicateMethodCall::OCCURRENCES_KEY => 4}).with_config(@config)
|
106
122
|
end
|
107
123
|
end
|
108
124
|
|
109
125
|
context "allowing calls to some methods" do
|
110
126
|
before :each do
|
111
|
-
@config = {
|
127
|
+
@config = {DuplicateMethodCall::ALLOW_CALLS_KEY => ['@some.thing',/puts/]}
|
112
128
|
end
|
113
129
|
it 'does not report calls to some methods' do
|
114
130
|
src = 'def double_some_thing() @some.thing + @some.thing end'
|
115
|
-
src.should_not smell_of(
|
131
|
+
src.should_not smell_of(DuplicateMethodCall).with_config(@config)
|
116
132
|
end
|
117
133
|
it 'reports calls to other methods' do
|
118
134
|
src = 'def double_other_thing() @other.thing + @other.thing end'
|
119
|
-
src.should smell_of(
|
135
|
+
src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'}).with_config(@config)
|
120
136
|
end
|
121
137
|
it 'does not report calls to methods specifed with a regular expression' do
|
122
138
|
src = 'def double_puts() puts @other.thing; puts @other.thing end'
|
123
|
-
src.should smell_of(
|
139
|
+
src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'}).with_config(@config)
|
124
140
|
end
|
125
141
|
end
|
126
142
|
end
|