reek 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +10 -0
- data/History.txt +20 -0
- data/README.md +90 -0
- data/bin/reek +2 -2
- data/config/defaults.reek +34 -4
- data/features/masking_smells.feature +35 -15
- data/features/options.feature +2 -0
- data/features/rake_task.feature +11 -18
- data/features/reports.feature +13 -15
- data/features/samples.feature +90 -105
- data/features/stdin.feature +3 -6
- data/features/step_definitions/reek_steps.rb +8 -4
- data/features/support/env.rb +2 -3
- data/features/yaml.feature +124 -0
- data/lib/reek.rb +8 -4
- data/lib/reek/cli/application.rb +46 -0
- data/lib/reek/cli/command_line.rb +106 -0
- data/lib/reek/cli/help_command.rb +18 -0
- data/lib/reek/cli/reek_command.rb +37 -0
- data/lib/reek/cli/report.rb +91 -0
- data/lib/reek/cli/version_command.rb +19 -0
- data/lib/reek/cli/yaml_command.rb +32 -0
- data/lib/reek/core/block_context.rb +18 -0
- data/lib/reek/core/class_context.rb +23 -0
- data/lib/reek/core/code_context.rb +72 -0
- data/lib/reek/core/code_parser.rb +192 -0
- data/lib/reek/core/detector_stack.rb +29 -0
- data/lib/reek/core/masking_collection.rb +46 -0
- data/lib/reek/core/method_context.rb +132 -0
- data/lib/reek/core/module_context.rb +64 -0
- data/lib/reek/{object_refs.rb → core/object_refs.rb} +8 -6
- data/lib/reek/{singleton_method_context.rb → core/singleton_method_context.rb} +10 -5
- data/lib/reek/core/smell_configuration.rb +66 -0
- data/lib/reek/core/sniffer.rb +110 -0
- data/lib/reek/core/stop_context.rb +26 -0
- data/lib/reek/examiner.rb +88 -0
- data/lib/reek/rake/task.rb +124 -0
- data/lib/reek/smell_warning.rb +69 -13
- data/lib/reek/smells.rb +29 -0
- data/lib/reek/smells/attribute.rb +13 -14
- data/lib/reek/smells/boolean_parameter.rb +33 -0
- data/lib/reek/smells/class_variable.rb +8 -6
- data/lib/reek/smells/control_couple.rb +33 -17
- data/lib/reek/smells/data_clump.rb +10 -6
- data/lib/reek/smells/duplication.rb +24 -14
- data/lib/reek/smells/feature_envy.rb +11 -6
- data/lib/reek/smells/irresponsible_module.rb +28 -0
- data/lib/reek/smells/large_class.rb +9 -7
- data/lib/reek/smells/long_method.rb +6 -5
- data/lib/reek/smells/long_parameter_list.rb +11 -9
- data/lib/reek/smells/long_yield_list.rb +37 -7
- data/lib/reek/smells/nested_iterators.rb +34 -9
- data/lib/reek/smells/simulated_polymorphism.rb +15 -11
- data/lib/reek/smells/smell_detector.rb +24 -12
- data/lib/reek/smells/uncommunicative_method_name.rb +76 -0
- data/lib/reek/smells/uncommunicative_module_name.rb +76 -0
- data/lib/reek/smells/{uncommunicative_name.rb → uncommunicative_parameter_name.rb} +14 -26
- data/lib/reek/smells/uncommunicative_variable_name.rb +90 -0
- data/lib/reek/smells/utility_function.rb +33 -9
- data/lib/reek/source.rb +18 -0
- data/lib/reek/source/code_comment.rb +19 -0
- data/lib/reek/source/config_file.rb +72 -0
- data/lib/reek/source/core_extras.rb +46 -0
- data/lib/reek/source/sexp_formatter.rb +16 -0
- data/lib/reek/source/source_code.rb +44 -0
- data/lib/reek/source/source_file.rb +32 -0
- data/lib/reek/source/source_locator.rb +36 -0
- data/lib/reek/source/tree_dresser.rb +128 -0
- data/lib/reek/spec.rb +51 -0
- data/lib/reek/spec/should_reek.rb +34 -0
- data/lib/reek/spec/should_reek_of.rb +37 -0
- data/lib/reek/spec/should_reek_only_of.rb +36 -0
- data/reek.gemspec +5 -5
- data/spec/reek/{help_command_spec.rb → cli/help_command_spec.rb} +3 -4
- data/spec/reek/{reek_command_spec.rb → cli/reek_command_spec.rb} +8 -7
- data/spec/reek/cli/report_spec.rb +26 -0
- data/spec/reek/{version_command_spec.rb → cli/version_command_spec.rb} +3 -3
- data/spec/reek/cli/yaml_command_spec.rb +47 -0
- data/spec/reek/core/block_context_spec.rb +26 -0
- data/spec/reek/core/class_context_spec.rb +53 -0
- data/spec/reek/{code_context_spec.rb → core/code_context_spec.rb} +15 -37
- data/spec/reek/{code_parser_spec.rb → core/code_parser_spec.rb} +5 -5
- data/spec/reek/{config_spec.rb → core/config_spec.rb} +2 -6
- data/spec/reek/{masking_collection_spec.rb → core/masking_collection_spec.rb} +3 -4
- data/spec/reek/{method_context_spec.rb → core/method_context_spec.rb} +6 -7
- data/spec/reek/core/module_context_spec.rb +42 -0
- data/spec/reek/{object_refs_spec.rb → core/object_refs_spec.rb} +5 -6
- data/spec/reek/core/singleton_method_context_spec.rb +15 -0
- data/spec/reek/core/smell_configuration_spec.rb +11 -0
- data/spec/reek/core/stop_context_spec.rb +17 -0
- data/spec/reek/examiner_spec.rb +42 -0
- data/spec/reek/smell_warning_spec.rb +82 -33
- data/spec/reek/smells/attribute_spec.rb +33 -7
- data/spec/reek/smells/boolean_parameter_spec.rb +76 -0
- data/spec/reek/smells/class_variable_spec.rb +15 -6
- data/spec/reek/smells/control_couple_spec.rb +40 -29
- data/spec/reek/smells/data_clump_spec.rb +28 -7
- data/spec/reek/smells/duplication_spec.rb +47 -41
- data/spec/reek/smells/feature_envy_spec.rb +76 -18
- data/spec/reek/smells/irresponsible_module_spec.rb +37 -0
- data/spec/reek/smells/large_class_spec.rb +91 -56
- data/spec/reek/smells/long_method_spec.rb +32 -7
- data/spec/reek/smells/long_parameter_list_spec.rb +42 -13
- data/spec/reek/smells/long_yield_list_spec.rb +65 -0
- data/spec/reek/smells/nested_iterators_spec.rb +94 -3
- data/spec/reek/smells/simulated_polymorphism_spec.rb +48 -20
- data/spec/reek/smells/smell_detector_shared.rb +28 -0
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +57 -0
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +67 -0
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +61 -0
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +124 -0
- data/spec/reek/smells/utility_function_spec.rb +45 -3
- data/spec/reek/source/code_comment_spec.rb +24 -0
- data/spec/reek/source/object_source_spec.rb +20 -0
- data/spec/reek/{adapters/source_spec.rb → source/source_code_spec.rb} +7 -8
- data/spec/reek/source/tree_dresser_spec.rb +165 -0
- data/spec/reek/spec/should_reek_of_spec.rb +76 -0
- data/spec/reek/spec/should_reek_only_of_spec.rb +89 -0
- data/spec/reek/{adapters → spec}/should_reek_spec.rb +8 -32
- data/spec/samples/all_but_one_masked/clean_one.rb +1 -0
- data/spec/samples/all_but_one_masked/dirty.rb +1 -0
- data/spec/samples/all_but_one_masked/masked.reek +5 -1
- data/spec/samples/clean_due_to_masking/clean_one.rb +1 -0
- data/spec/samples/clean_due_to_masking/clean_three.rb +1 -0
- data/spec/samples/clean_due_to_masking/clean_two.rb +1 -0
- data/spec/samples/clean_due_to_masking/dirty_one.rb +1 -1
- data/spec/samples/clean_due_to_masking/dirty_two.rb +1 -1
- data/spec/samples/clean_due_to_masking/masked.reek +5 -1
- data/spec/samples/corrupt_config_file/dirty.rb +1 -1
- data/spec/samples/empty_config_file/dirty.rb +2 -1
- data/spec/samples/exceptions.reek +1 -1
- data/spec/samples/masked/dirty.rb +2 -1
- data/spec/samples/masked/masked.reek +3 -1
- data/spec/samples/mixed_results/clean_one.rb +1 -0
- data/spec/samples/mixed_results/clean_three.rb +1 -0
- data/spec/samples/mixed_results/clean_two.rb +1 -0
- data/spec/samples/mixed_results/dirty_one.rb +1 -0
- data/spec/samples/mixed_results/dirty_two.rb +1 -0
- data/spec/samples/not_quite_masked/dirty.rb +2 -1
- data/spec/samples/not_quite_masked/masked.reek +1 -1
- data/spec/samples/overrides/masked/dirty.rb +2 -1
- data/spec/samples/overrides/masked/lower.reek +3 -1
- data/spec/samples/three_clean_files/clean_one.rb +1 -0
- data/spec/samples/three_clean_files/clean_three.rb +1 -0
- data/spec/samples/three_clean_files/clean_two.rb +1 -0
- data/spec/samples/two_smelly_files/dirty_one.rb +2 -1
- data/spec/samples/two_smelly_files/dirty_two.rb +2 -1
- data/spec/spec_helper.rb +1 -2
- data/tasks/reek.rake +2 -2
- data/tasks/test.rake +12 -3
- metadata +81 -62
- data/README.rdoc +0 -84
- data/lib/reek/adapters/application.rb +0 -46
- data/lib/reek/adapters/command_line.rb +0 -77
- data/lib/reek/adapters/config_file.rb +0 -31
- data/lib/reek/adapters/core_extras.rb +0 -64
- data/lib/reek/adapters/rake_task.rb +0 -121
- data/lib/reek/adapters/report.rb +0 -86
- data/lib/reek/adapters/source.rb +0 -72
- data/lib/reek/adapters/spec.rb +0 -133
- data/lib/reek/block_context.rb +0 -62
- data/lib/reek/class_context.rb +0 -41
- data/lib/reek/code_context.rb +0 -68
- data/lib/reek/code_parser.rb +0 -203
- data/lib/reek/configuration.rb +0 -57
- data/lib/reek/detector_stack.rb +0 -37
- data/lib/reek/help_command.rb +0 -14
- data/lib/reek/if_context.rb +0 -18
- data/lib/reek/masking_collection.rb +0 -33
- data/lib/reek/method_context.rb +0 -138
- data/lib/reek/module_context.rb +0 -49
- data/lib/reek/name.rb +0 -57
- data/lib/reek/reek_command.rb +0 -28
- data/lib/reek/sexp_formatter.rb +0 -10
- data/lib/reek/sniffer.rb +0 -177
- data/lib/reek/stop_context.rb +0 -35
- data/lib/reek/tree_dresser.rb +0 -82
- data/lib/reek/version_command.rb +0 -14
- data/lib/reek/yield_call_context.rb +0 -12
- data/spec/reek/adapters/report_spec.rb +0 -31
- data/spec/reek/adapters/should_reek_of_spec.rb +0 -138
- data/spec/reek/adapters/should_reek_only_of_spec.rb +0 -87
- data/spec/reek/block_context_spec.rb +0 -65
- data/spec/reek/class_context_spec.rb +0 -161
- data/spec/reek/configuration_spec.rb +0 -12
- data/spec/reek/if_context_spec.rb +0 -17
- data/spec/reek/module_context_spec.rb +0 -46
- data/spec/reek/name_spec.rb +0 -37
- data/spec/reek/object_source_spec.rb +0 -23
- data/spec/reek/singleton_method_context_spec.rb +0 -16
- data/spec/reek/smells/smell_detector_spec.rb +0 -36
- data/spec/reek/smells/uncommunicative_name_spec.rb +0 -146
- data/spec/reek/sniffer_spec.rb +0 -11
- data/spec/reek/stop_context_spec.rb +0 -33
- data/spec/reek/tree_dresser_spec.rb +0 -20
@@ -1,12 +1,13 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require '
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'data_clump')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
4
4
|
|
5
5
|
include Reek::Smells
|
6
6
|
|
7
7
|
shared_examples_for 'a data clump detector' do
|
8
8
|
it 'does not report small parameter sets' do
|
9
9
|
src = <<EOS
|
10
|
+
# test module
|
10
11
|
#{@context} Scrunch
|
11
12
|
def first(pa) @field == :sym ? 0 : 3; end
|
12
13
|
def second(pa) @field == :sym; end
|
@@ -17,16 +18,28 @@ EOS
|
|
17
18
|
src.should_not reek
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
context 'with 3 identical pairs' do
|
22
|
+
before :each do
|
23
|
+
@src = <<EOS
|
22
24
|
#{@context} Scrunch
|
23
25
|
def first(pa, pb) @field == :sym ? 0 : 3; end
|
24
26
|
def second(pa, pb) @field == :sym; end
|
25
27
|
def third(pa, pb) pa - pb + @fred; end
|
26
28
|
end
|
27
29
|
EOS
|
28
|
-
|
29
|
-
|
30
|
+
ctx = ModuleContext.from_s(@src)
|
31
|
+
detector = DataClump.new('newt')
|
32
|
+
detector.examine(ctx)
|
33
|
+
warning = detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
34
|
+
@yaml = warning.to_yaml
|
35
|
+
end
|
36
|
+
it 'reports all parameters' do
|
37
|
+
@yaml.should match(/parameters:[\s-]*pa/)
|
38
|
+
@yaml.should match(/parameters:[\spa-]*pb/)
|
39
|
+
end
|
40
|
+
it 'reports the number of occurrences' do
|
41
|
+
@yaml.should match(/occurrences:\s*3/)
|
42
|
+
end
|
30
43
|
end
|
31
44
|
|
32
45
|
it 'reports 3 swapped pairs in a class' do
|
@@ -103,3 +116,11 @@ describe DataClump do
|
|
103
116
|
|
104
117
|
# TODO: include singleton methods in the calcs
|
105
118
|
end
|
119
|
+
|
120
|
+
describe DataClump do
|
121
|
+
before(:each) do
|
122
|
+
@detector = DataClump.new('newt')
|
123
|
+
end
|
124
|
+
|
125
|
+
it_should_behave_like 'SmellDetector'
|
126
|
+
end
|
@@ -1,35 +1,33 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek
|
4
|
-
require 'reek
|
5
|
-
require '
|
6
|
-
require 'reek/smells/duplication'
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'duplication')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_parser')
|
4
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'sniffer')
|
5
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
7
6
|
|
8
7
|
include Reek
|
9
8
|
include Reek::Smells
|
10
9
|
|
11
10
|
describe Duplication, "repeated method calls" do
|
12
|
-
it '
|
11
|
+
it 'reports repeated call' do
|
13
12
|
'def double_thing() @other.thing + @other.thing end'.should reek_only_of(:Duplication, /@other.thing/)
|
14
13
|
end
|
15
|
-
|
16
|
-
it 'should report repeated call to lvar' do
|
14
|
+
it 'reports repeated call to lvar' do
|
17
15
|
'def double_thing(other) other[@thing] + other[@thing] end'.should reek_only_of(:Duplication, /other\[@thing\]/)
|
18
16
|
end
|
19
|
-
|
20
|
-
it 'should report call parameters' do
|
17
|
+
it 'reports call parameters' do
|
21
18
|
'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'.should reek_only_of(:Duplication, /@other.thing\(2, 3\)/)
|
22
19
|
end
|
23
|
-
|
24
20
|
it 'should report nested calls' do
|
25
|
-
ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
21
|
+
ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
26
22
|
ruby.should reek_of(:Duplication, /@other.thing[^\.]/)
|
27
23
|
ruby.should reek_of(:Duplication, /@other.thing.foo/)
|
28
24
|
end
|
29
|
-
|
30
25
|
it 'should ignore calls to new' do
|
31
26
|
'def double_thing() @other.new + @other.new end'.should_not reek
|
32
27
|
end
|
28
|
+
it 'reports repeated assignment' do
|
29
|
+
'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'.should reek_only_of(:Duplication, /@other\[thing\] = true/)
|
30
|
+
end
|
33
31
|
end
|
34
32
|
|
35
33
|
describe Duplication, "non-repeated method calls" do
|
@@ -42,36 +40,44 @@ describe Duplication, "non-repeated method calls" do
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
|
-
describe Duplication
|
46
|
-
before
|
47
|
-
@
|
48
|
-
@
|
43
|
+
describe Duplication do
|
44
|
+
before(:each) do
|
45
|
+
@source_name = 'copy-cat'
|
46
|
+
@detector = Duplication.new(@source_name)
|
49
47
|
end
|
50
48
|
|
51
|
-
|
52
|
-
3.times { @mc.record_call_to(s(:call, nil, :other, s(:arglist)))}
|
53
|
-
@dup.examine(@mc).should == true
|
54
|
-
end
|
49
|
+
it_should_behave_like 'SmellDetector'
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
51
|
+
context 'looking at the YAML' do
|
52
|
+
before :each do
|
53
|
+
src = <<EOS
|
54
|
+
def double_thing(other)
|
55
|
+
other[@thing]
|
56
|
+
not_the_sam(at = all)
|
57
|
+
other[@thing]
|
64
58
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
59
|
+
EOS
|
60
|
+
source = src.to_reek_source
|
61
|
+
sniffer = Core::Sniffer.new(source)
|
62
|
+
@mctx = Core::CodeParser.new(sniffer).process_defn(source.syntax_tree)
|
63
|
+
@detector.examine(@mctx)
|
64
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
65
|
+
@yaml = warning.to_yaml
|
66
|
+
end
|
67
|
+
it 'reports the source' do
|
68
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
69
|
+
end
|
70
|
+
it 'reports the class' do
|
71
|
+
@yaml.should match(/class:\s*Duplication/)
|
72
|
+
end
|
73
|
+
it 'reports the subclass' do
|
74
|
+
@yaml.should match(/subclass:\s*DuplicateMethodCall/)
|
75
|
+
end
|
76
|
+
it 'reports the call' do
|
77
|
+
@yaml.should match(/call:\s*other\[\@thing\]/)
|
78
|
+
end
|
79
|
+
it 'reports the correct lines' do
|
80
|
+
@yaml.should match(/lines:\s*- 2\s*- 4/)
|
81
|
+
end
|
76
82
|
end
|
77
83
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
require 'reek
|
3
|
-
require '
|
4
|
-
require 'reek/stop_context'
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'feature_envy')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
5
4
|
|
6
5
|
include Reek
|
7
6
|
include Reek::Smells
|
@@ -27,8 +26,38 @@ describe FeatureEnvy do
|
|
27
26
|
'def no_envy(arga) arga.barg(@item); arga end'.should_not reek
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
'
|
29
|
+
context 'with 2 calls to a parameter' do
|
30
|
+
it 'reports the smell' do
|
31
|
+
'def envy(arga) arga.b(arga) + arga.c(@fred) end'.should reek_only_of(:FeatureEnvy, /arga/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when an envious receiver exists' do
|
36
|
+
before :each do
|
37
|
+
@source_name = 'green as a cucumber'
|
38
|
+
@receiver = 'blah'
|
39
|
+
@ctx = mock('method_context', :null_object => true)
|
40
|
+
@ctx.should_receive(:envious_receivers).and_return({s(:lvar, @receiver) => 4})
|
41
|
+
@detector = FeatureEnvy.new(@source_name)
|
42
|
+
@detector.examine_context(@ctx)
|
43
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
44
|
+
@yaml = warning.to_yaml
|
45
|
+
end
|
46
|
+
it 'reports the source' do
|
47
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
48
|
+
end
|
49
|
+
it 'reports the class' do
|
50
|
+
@yaml.should match(/\sclass:\s*LowCohesion/)
|
51
|
+
end
|
52
|
+
it 'reports the subclass' do
|
53
|
+
@yaml.should match(/subclass:\s*FeatureEnvy/)
|
54
|
+
end
|
55
|
+
it 'reports the envious receiver' do
|
56
|
+
@yaml.should match(/receiver:[\s]*#{@receiver}/)
|
57
|
+
end
|
58
|
+
it 'reports the number of references' do
|
59
|
+
@yaml.should match(/references:\s*4/)
|
60
|
+
end
|
32
61
|
end
|
33
62
|
|
34
63
|
it 'should report highest affinity' do
|
@@ -178,20 +207,49 @@ EOS
|
|
178
207
|
end
|
179
208
|
end
|
180
209
|
|
181
|
-
describe FeatureEnvy
|
182
|
-
|
183
|
-
|
184
|
-
@
|
185
|
-
@fe = FeatureEnvy.new
|
210
|
+
describe FeatureEnvy do
|
211
|
+
before(:each) do
|
212
|
+
@source_name = 'green as a cucumber'
|
213
|
+
@detector = FeatureEnvy.new(@source_name)
|
186
214
|
end
|
187
215
|
|
188
|
-
|
189
|
-
@context.refs.record_ref([:lvar, :thing])
|
190
|
-
@context.refs.record_ref([:lvar, :thing])
|
191
|
-
@fe.examine(@context).should == true
|
192
|
-
end
|
216
|
+
it_should_behave_like 'SmellDetector'
|
193
217
|
|
194
|
-
|
195
|
-
|
218
|
+
context 'when reporting yaml' do
|
219
|
+
before :each do
|
220
|
+
src = <<EOS
|
221
|
+
def envious(other)
|
222
|
+
other.call
|
223
|
+
self.do_nothing
|
224
|
+
other.other
|
225
|
+
other.fred
|
226
|
+
end
|
227
|
+
EOS
|
228
|
+
source = src.to_reek_source
|
229
|
+
sniffer = Sniffer.new(source)
|
230
|
+
@mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
|
231
|
+
@detector.examine_context(@mctx)
|
232
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
233
|
+
@yaml = warning.to_yaml
|
234
|
+
end
|
235
|
+
it 'reports the source' do
|
236
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
237
|
+
end
|
238
|
+
it 'reports the class' do
|
239
|
+
@yaml.should match(/class:\s*LowCohesion/)
|
240
|
+
end
|
241
|
+
it 'reports the subclass' do
|
242
|
+
@yaml.should match(/subclass:\s*FeatureEnvy/)
|
243
|
+
end
|
244
|
+
it 'reports the envious receiver' do
|
245
|
+
@yaml.should match(/receiver:\s*other/)
|
246
|
+
end
|
247
|
+
it 'reports the number of references' do
|
248
|
+
@yaml.should match(/references:\s*3/)
|
249
|
+
end
|
250
|
+
it 'reports the referring lines' do
|
251
|
+
pending
|
252
|
+
@yaml.should match(/lines:\s*- 2\s*- 4\s*- 5/)
|
253
|
+
end
|
196
254
|
end
|
197
255
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'irresponsible_module')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
4
|
+
|
5
|
+
include Reek::Smells
|
6
|
+
|
7
|
+
describe IrresponsibleModule do
|
8
|
+
['class'].each do |unit|
|
9
|
+
it "does not report a #{unit} having a comment" do
|
10
|
+
src = <<EOS
|
11
|
+
# test #{unit}
|
12
|
+
#{unit} Responsible; end
|
13
|
+
EOS
|
14
|
+
src.should_not reek
|
15
|
+
end
|
16
|
+
it "reports a #{unit} without a comment" do
|
17
|
+
"#{unit} Responsible; end".should reek_only_of(:IrresponsibleModule, /Responsible/)
|
18
|
+
end
|
19
|
+
it "reports a #{unit} with an empty comment" do
|
20
|
+
src = <<EOS
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#
|
24
|
+
#{unit} Responsible; end
|
25
|
+
EOS
|
26
|
+
src.should reek_only_of(:IrresponsibleModule, /Responsible/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe IrresponsibleModule do
|
32
|
+
before(:each) do
|
33
|
+
@detector = IrresponsibleModule.new('yoof')
|
34
|
+
end
|
35
|
+
|
36
|
+
it_should_behave_like 'SmellDetector'
|
37
|
+
end
|
@@ -1,78 +1,37 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek
|
4
|
-
require 'reek
|
5
|
-
require '
|
6
|
-
require 'reek/smells/large_class'
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'large_class')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'examiner')
|
4
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_parser')
|
5
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
7
6
|
|
8
7
|
include Reek
|
9
8
|
include Reek::Smells
|
10
9
|
|
11
|
-
describe LargeClass, 'when exceptions are listed' do
|
12
|
-
before(:each) do
|
13
|
-
@class_name = 'Humungous'
|
14
|
-
src = <<EOS
|
15
|
-
class #{@class_name}
|
16
|
-
def me01x()3 end;def me02x()3 end;def me03x()3 end;def me04x()3 end;def me05x()3 end
|
17
|
-
def me11x()3 end;def me12x()3 end;def me13x()3 end;def me14x()3 end;def me15x()3 end
|
18
|
-
def me21x()3 end;def me22x()3 end;def me23x()3 end;def me24x()3 end;def me25x()3 end
|
19
|
-
def me31x()3 end;def me32x()3 end;def me33x()3 end;def me34x()3 end;def me35x()3 end
|
20
|
-
def me41x()3 end;def me42x()3 end;def me43x()3 end;def me44x()3 end;def me45x()3 end
|
21
|
-
def me51x()3 end
|
22
|
-
end
|
23
|
-
EOS
|
24
|
-
@ctx = ClassContext.from_s(src)
|
25
|
-
@config = LargeClass.default_config
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should ignore first excepted name' do
|
29
|
-
@config[LargeClass::EXCLUDE_KEY] = [@class_name]
|
30
|
-
lc = LargeClass.new(@config)
|
31
|
-
lc.examine(@ctx).should == false
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should ignore second excepted name' do
|
35
|
-
@config[LargeClass::EXCLUDE_KEY] = ['Oversized', @class_name]
|
36
|
-
lc = LargeClass.new(@config)
|
37
|
-
lc.examine(@ctx).should == false
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should report non-excepted name' do
|
41
|
-
@config[LargeClass::EXCLUDE_KEY] = ['SmellMe']
|
42
|
-
lc = LargeClass.new(@config)
|
43
|
-
lc.examine(@ctx).should == true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
10
|
describe LargeClass, 'checking source code' do
|
48
11
|
|
49
12
|
context 'counting instance variables' do
|
50
|
-
it 'should not report
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
it 'should count ivars in one method' do
|
55
|
-
ClassContext.from_s('class Empty;def ivars() @aa=@ab=@ac=@ad; end;end').should have(4).variable_names
|
13
|
+
it 'should not report 9 ivars' do
|
14
|
+
'# clean class for testing purposes
|
15
|
+
class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4; end;end'.should_not reek
|
56
16
|
end
|
57
17
|
|
58
|
-
it '
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
it 'should not report 9 ivars' do
|
63
|
-
'class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai; end;end'.should_not reek
|
18
|
+
it 'counts each ivar only once' do
|
19
|
+
'# clean class for testing purposes
|
20
|
+
class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=4;@aa=3; end;end'.should_not reek
|
64
21
|
end
|
65
22
|
|
66
23
|
it 'should report 10 ivars' do
|
67
|
-
'
|
24
|
+
'# smelly class for testing purposes
|
25
|
+
class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4; end;end'.should reek_only_of(:LargeClass)
|
68
26
|
end
|
69
27
|
|
70
28
|
it 'should not report 10 ivars in 2 extensions' do
|
71
29
|
src = <<EOS
|
30
|
+
# clean class for testing purposes
|
72
31
|
class Full;def ivars_a() @aa=@ab=@ac=@ad=@ae; end;end
|
32
|
+
# clean class for testing purposes
|
73
33
|
class Full;def ivars_b() @af=@ag=@ah=@ai=@aj; end;end
|
74
34
|
EOS
|
75
|
-
|
76
35
|
src.should_not reek
|
77
36
|
end
|
78
37
|
end
|
@@ -81,6 +40,7 @@ EOS
|
|
81
40
|
|
82
41
|
it 'should not report 25 methods' do
|
83
42
|
src = <<EOS
|
43
|
+
# smelly class for testing purposes
|
84
44
|
class Full
|
85
45
|
def me01x()3 end;def me02x()3 end;def me03x()3 end;def me04x()3 end;def me05x()3 end
|
86
46
|
def me11x()3 end;def me12x()3 end;def me13x()3 end;def me14x()3 end;def me15x()3 end
|
@@ -123,3 +83,78 @@ EOS
|
|
123
83
|
end
|
124
84
|
end
|
125
85
|
end
|
86
|
+
|
87
|
+
describe LargeClass, 'looking at the YAML' do
|
88
|
+
before(:each) do
|
89
|
+
@source_name = 'elephant'
|
90
|
+
@detector = LargeClass.new(@source_name)
|
91
|
+
end
|
92
|
+
|
93
|
+
it_should_behave_like 'SmellDetector'
|
94
|
+
|
95
|
+
context 'when the class has many methods' do
|
96
|
+
before :each do
|
97
|
+
src = <<EOS
|
98
|
+
class Full
|
99
|
+
def me01x()3 end;def me02x()3 end;def me03x()3 end;def me04x()3 end;def me05x()3 end
|
100
|
+
def me11x()3 end;def me12x()3 end;def me13x()3 end;def me14x()3 end;def me15x()3 end
|
101
|
+
def me21x()3 end;def me22x()3 end;def me23x()3 end;def me24x()3 end;def me25x()3 end
|
102
|
+
def me31x()3 end;def me32x()3 end;def me33x()3 end;def me34x()3 end;def me35x()3 end
|
103
|
+
def me41x()3 end;def me42x()3 end;def me43x()3 end;def me44x()3 end;def me45x()3 end
|
104
|
+
def me51x()3 end
|
105
|
+
end
|
106
|
+
EOS
|
107
|
+
@yaml = Examiner.new(src).all_smells[0].to_yaml
|
108
|
+
end
|
109
|
+
it 'reports the source' do
|
110
|
+
@yaml.should match(/source:\s*string/)
|
111
|
+
end
|
112
|
+
it 'reports the correct class' do
|
113
|
+
@yaml.should match(/\sclass:\s*LargeClass/)
|
114
|
+
end
|
115
|
+
it 'reports the correct subclass' do
|
116
|
+
@yaml.should match(/\ssubclass:\s*#{LargeClass::SUBCLASS_TOO_MANY_METHODS}/)
|
117
|
+
end
|
118
|
+
it 'reports the number of methods' do
|
119
|
+
@yaml.should match(/method_count:[\s]*26/)
|
120
|
+
# SMELL: many tests duplicate the names of the YAML fields
|
121
|
+
end
|
122
|
+
it 'reports the line number of the declaration' do
|
123
|
+
@yaml.should match(/lines:\s*- 1/)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when the class has 30 instance variables' do
|
128
|
+
before :each do
|
129
|
+
src = <<EOS
|
130
|
+
# smelly class for testing purposes
|
131
|
+
class Empty
|
132
|
+
def ivars
|
133
|
+
@aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj=4
|
134
|
+
end
|
135
|
+
end
|
136
|
+
EOS
|
137
|
+
source = src.to_reek_source
|
138
|
+
sniffer = Core::Sniffer.new(source)
|
139
|
+
ctx = Core::CodeParser.new(sniffer).process_class(source.syntax_tree)
|
140
|
+
@detector.examine_context(ctx)
|
141
|
+
@yaml = @detector.smells_found.to_a[0].to_yaml # SMELL: too cumbersome!
|
142
|
+
end
|
143
|
+
it 'reports the source' do
|
144
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
145
|
+
end
|
146
|
+
it 'reports the correct class' do
|
147
|
+
@yaml.should match(/\sclass:\s*LargeClass/)
|
148
|
+
end
|
149
|
+
it 'reports the correct subclass' do
|
150
|
+
@yaml.should match(/\ssubclass:\s*#{LargeClass::SUBCLASS_TOO_MANY_IVARS}/)
|
151
|
+
end
|
152
|
+
it 'reports the number of methods' do
|
153
|
+
@yaml.should match(/ivar_count:\s*10/)
|
154
|
+
# SMELL: many tests duplicate the names of the YAML fields
|
155
|
+
end
|
156
|
+
it 'reports the line number of the declaration' do
|
157
|
+
@yaml.should match(/lines:\s*- 2/)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|