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
@@ -0,0 +1,67 @@
|
|
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', 'uncommunicative_module_name')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
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.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'sniffer')
|
6
|
+
|
7
|
+
include Reek
|
8
|
+
include Reek::Smells
|
9
|
+
|
10
|
+
describe UncommunicativeModuleName do
|
11
|
+
before :each do
|
12
|
+
@source_name = 'classy'
|
13
|
+
@detector = UncommunicativeModuleName.new(@source_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like 'SmellDetector'
|
17
|
+
|
18
|
+
['class', 'module'].each do |type|
|
19
|
+
it 'does not report one-word name' do
|
20
|
+
"#{type} Helper; end".should_not reek_of(:UncommunicativeModuleName)
|
21
|
+
end
|
22
|
+
it 'reports one-letter name' do
|
23
|
+
"#{type} X; end".should reek_of(:UncommunicativeModuleName, /X/)
|
24
|
+
end
|
25
|
+
it 'reports name of the form "x2"' do
|
26
|
+
"#{type} X2; end".should reek_of(:UncommunicativeModuleName, /X2/)
|
27
|
+
end
|
28
|
+
it 'reports long name ending in a number' do
|
29
|
+
"#{type} Printer2; end".should reek_of(:UncommunicativeModuleName, /Printer2/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'accepting names' do
|
34
|
+
it 'accepts Inline::C' do
|
35
|
+
ctx = mock('context')
|
36
|
+
ctx.should_receive(:full_name).and_return('Inline::C')
|
37
|
+
@detector.accept?(ctx).should == true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'looking at the YAML' do
|
42
|
+
before :each do
|
43
|
+
src = 'module Printer2; end'
|
44
|
+
source = src.to_reek_source
|
45
|
+
sniffer = Core::Sniffer.new(source)
|
46
|
+
@mctx = Core::CodeParser.new(sniffer).process_module(source.syntax_tree)
|
47
|
+
@detector.examine(@mctx)
|
48
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
49
|
+
@yaml = warning.to_yaml
|
50
|
+
end
|
51
|
+
it 'reports the source' do
|
52
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
53
|
+
end
|
54
|
+
it 'reports the class' do
|
55
|
+
@yaml.should match(/class:\s*UncommunicativeName/)
|
56
|
+
end
|
57
|
+
it 'reports the subclass' do
|
58
|
+
@yaml.should match(/subclass:\s*UncommunicativeModuleName/)
|
59
|
+
end
|
60
|
+
it 'reports the variable name' do
|
61
|
+
@yaml.should match(/module_name:\s*Printer2/)
|
62
|
+
end
|
63
|
+
it 'reports the line number of the declaration' do
|
64
|
+
@yaml.should match(/lines:\s*- 1/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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', 'uncommunicative_parameter_name')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
4
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'method_context')
|
5
|
+
|
6
|
+
include Reek::Core
|
7
|
+
include Reek::Smells
|
8
|
+
|
9
|
+
describe UncommunicativeParameterName do
|
10
|
+
before :each do
|
11
|
+
@source_name = 'wallamalloo'
|
12
|
+
@detector = UncommunicativeParameterName.new(@source_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like 'SmellDetector'
|
16
|
+
|
17
|
+
context "parameter name" do
|
18
|
+
['obj.', ''].each do |host|
|
19
|
+
it 'does not recognise *' do
|
20
|
+
"def #{host}help(xray, *) basics(17) end".should_not reek
|
21
|
+
end
|
22
|
+
it "reports parameter's name" do
|
23
|
+
"def #{host}help(x) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /x/, /parameter name/)
|
24
|
+
end
|
25
|
+
it 'reports name of the form "x2"' do
|
26
|
+
"def #{host}help(x2) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /x2/, /parameter name/)
|
27
|
+
#SMELL: should match either the class or the subclass!
|
28
|
+
end
|
29
|
+
it 'reports long name ending in a number' do
|
30
|
+
"def #{host}help(param1) basics(17) end".should reek_only_of(:UncommunicativeParameterName, /param1/, /parameter name/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'looking at the YAML' do
|
36
|
+
before :each do
|
37
|
+
src = 'def bad(good, bad2, good_again) end'
|
38
|
+
source = src.to_reek_source
|
39
|
+
sniffer = Sniffer.new(source)
|
40
|
+
@mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
|
41
|
+
@detector.examine(@mctx)
|
42
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
43
|
+
@yaml = warning.to_yaml
|
44
|
+
end
|
45
|
+
it 'reports the source' do
|
46
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
47
|
+
end
|
48
|
+
it 'reports the class' do
|
49
|
+
@yaml.should match(/class:\s*UncommunicativeName/)
|
50
|
+
end
|
51
|
+
it 'reports the subclass' do
|
52
|
+
@yaml.should match(/subclass:\s*UncommunicativeParameterName/)
|
53
|
+
end
|
54
|
+
it 'reports the variable name' do
|
55
|
+
@yaml.should match(/parameter_name:\s*bad2/)
|
56
|
+
end
|
57
|
+
it 'reports the line number of the declaration' do
|
58
|
+
@yaml.should match(/lines:\s*- 1/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,124 @@
|
|
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', 'uncommunicative_variable_name')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
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.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'sniffer')
|
6
|
+
|
7
|
+
include Reek
|
8
|
+
include Reek::Smells
|
9
|
+
|
10
|
+
describe UncommunicativeVariableName do
|
11
|
+
before :each do
|
12
|
+
@source_name = 'wallamalloo'
|
13
|
+
@detector = UncommunicativeVariableName.new(@source_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like 'SmellDetector'
|
17
|
+
|
18
|
+
context "field name" do
|
19
|
+
it 'does not report use of one-letter fieldname' do
|
20
|
+
'class Thing; def simple(fred) @x end end'.should_not reek_of(:UncommunicativeVariableName, /@x/, /Thing/, /variable name/)
|
21
|
+
end
|
22
|
+
it 'reports one-letter fieldname in assignment' do
|
23
|
+
'class Thing; def simple(fred) @x = fred end end'.should reek_of(:UncommunicativeVariableName, /@x/, /Thing/, /variable name/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "local variable name" do
|
28
|
+
it 'does not report one-word variable name' do
|
29
|
+
'def help(fred) simple = jim(45) end'.should_not reek
|
30
|
+
end
|
31
|
+
it 'reports one-letter variable name' do
|
32
|
+
'def simple(fred) x = jim(45) end'.should reek_only_of(:UncommunicativeVariableName, /x/, /variable name/)
|
33
|
+
end
|
34
|
+
it 'reports name of the form "x2"' do
|
35
|
+
'def simple(fred) x2 = jim(45) end'.should reek_only_of(:UncommunicativeVariableName, /x2/, /variable name/)
|
36
|
+
end
|
37
|
+
it 'reports long name ending in a number' do
|
38
|
+
'def simple(fred) var123 = jim(45) end'.should reek_only_of(:UncommunicativeVariableName, /var123/, /variable name/)
|
39
|
+
end
|
40
|
+
it 'reports variable name only once' do
|
41
|
+
'def simple(fred) x = jim(45); x = y end'.should reek_only_of(:UncommunicativeVariableName, /x/)
|
42
|
+
end
|
43
|
+
it 'reports a bad name inside a block' do
|
44
|
+
src = 'def clean(text) text.each { q2 = 3 } end'
|
45
|
+
src.should reek_of(:UncommunicativeVariableName, /q2/)
|
46
|
+
end
|
47
|
+
it 'reports variable name outside any method' do
|
48
|
+
'class Simple; x = jim(45); end'.should reek_of(:UncommunicativeVariableName, /x/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "block parameter name" do
|
53
|
+
it "reports parameter's name" do
|
54
|
+
'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeVariableName, /x/, /variable name/)
|
55
|
+
end
|
56
|
+
it "reports deep block parameter" do
|
57
|
+
src = <<EOS
|
58
|
+
def bad
|
59
|
+
unless @mod then
|
60
|
+
@sig.each { |x| x.to_s }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
EOS
|
64
|
+
src.should reek_only_of(:UncommunicativeVariableName, /'x'/)
|
65
|
+
end
|
66
|
+
it 'reports all bad block parameters' do
|
67
|
+
source =<<EOS
|
68
|
+
class Thing
|
69
|
+
def bad(fred)
|
70
|
+
@fred.each {|x| 4 - x }
|
71
|
+
@jim.each {|y| y - 4 }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
EOS
|
75
|
+
|
76
|
+
source.should reek_of(:UncommunicativeVariableName, /'x'/)
|
77
|
+
source.should reek_of(:UncommunicativeVariableName, /'y'/)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'looking at the YAML' do
|
82
|
+
before :each do
|
83
|
+
src = <<EOS
|
84
|
+
def bad
|
85
|
+
unless @mod then
|
86
|
+
x2 = xy.to_s
|
87
|
+
x2
|
88
|
+
x2 = 56
|
89
|
+
end
|
90
|
+
end
|
91
|
+
EOS
|
92
|
+
source = src.to_reek_source
|
93
|
+
sniffer = Core::Sniffer.new(source)
|
94
|
+
@mctx = Core::CodeParser.new(sniffer).process_defn(source.syntax_tree)
|
95
|
+
@detector.examine(@mctx)
|
96
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
97
|
+
@yaml = warning.to_yaml
|
98
|
+
end
|
99
|
+
it 'reports the source' do
|
100
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
101
|
+
end
|
102
|
+
it 'reports the class' do
|
103
|
+
@yaml.should match(/class:\s*UncommunicativeName/)
|
104
|
+
end
|
105
|
+
it 'reports the subclass' do
|
106
|
+
@yaml.should match(/subclass:\s*UncommunicativeVariableName/)
|
107
|
+
end
|
108
|
+
it 'reports the variable name' do
|
109
|
+
@yaml.should match(/variable_name:\s*x2/)
|
110
|
+
end
|
111
|
+
it 'reports all line numbers' do
|
112
|
+
@yaml.should match(/lines:\s*- 3\s*- 5/)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "several names" do
|
117
|
+
it 'should report all bad names' do
|
118
|
+
ruby = 'class Oof; def y(x) @z = x end end'
|
119
|
+
ruby.should reek_of(:UncommunicativeParameterName, /'x'/)
|
120
|
+
ruby.should reek_of(:UncommunicativeMethodName, /'y'/)
|
121
|
+
ruby.should reek_of(:UncommunicativeVariableName, /'@z'/)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -1,6 +1,6 @@
|
|
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', 'utility_function')
|
3
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
4
4
|
|
5
5
|
include Reek
|
6
6
|
include Reek::Smells
|
@@ -25,6 +25,10 @@ describe UtilityFunction do
|
|
25
25
|
it 'recognises an ivar reference within a block' do
|
26
26
|
'def clean(text) text.each { @fred = 3} end'.should_not reek
|
27
27
|
end
|
28
|
+
it 'copes with nil superclass' do
|
29
|
+
'# clean class for testing purposes
|
30
|
+
class Object; def is_maybe?() false end end'.should_not reek
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
context 'with only one call' do
|
@@ -59,6 +63,7 @@ describe UtilityFunction do
|
|
59
63
|
|
60
64
|
it 'should recognise a deep call' do
|
61
65
|
src = <<EOS
|
66
|
+
# clean class for testing purposes
|
62
67
|
class Red
|
63
68
|
def deep(text)
|
64
69
|
text.each { |mod| atts = shelve(mod) }
|
@@ -73,3 +78,40 @@ EOS
|
|
73
78
|
end
|
74
79
|
end
|
75
80
|
end
|
81
|
+
|
82
|
+
describe UtilityFunction do
|
83
|
+
before(:each) do
|
84
|
+
@source_name = 'loser'
|
85
|
+
@detector = UtilityFunction.new(@source_name)
|
86
|
+
end
|
87
|
+
|
88
|
+
it_should_behave_like 'SmellDetector'
|
89
|
+
|
90
|
+
context 'looking at the YAML' do
|
91
|
+
before :each do
|
92
|
+
src = <<EOS
|
93
|
+
def simple(arga)
|
94
|
+
arga.b.c
|
95
|
+
end
|
96
|
+
EOS
|
97
|
+
source = src.to_reek_source
|
98
|
+
sniffer = Sniffer.new(source)
|
99
|
+
@mctx = CodeParser.new(sniffer).process_defn(source.syntax_tree)
|
100
|
+
@detector.examine_context(@mctx)
|
101
|
+
warning = @detector.smells_found.to_a[0] # SMELL: too cumbersome!
|
102
|
+
@yaml = warning.to_yaml
|
103
|
+
end
|
104
|
+
it 'reports the source' do
|
105
|
+
@yaml.should match(/source:\s*#{@source_name}/)
|
106
|
+
end
|
107
|
+
it 'reports the class' do
|
108
|
+
@yaml.should match(/\sclass:\s*LowCohesion/)
|
109
|
+
end
|
110
|
+
it 'reports the subclass' do
|
111
|
+
@yaml.should match(/subclass:\s*UtilityFunction/)
|
112
|
+
end
|
113
|
+
it 'reports the line number of the method' do
|
114
|
+
@yaml.should match(/lines:\s*- 1/)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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', 'source', 'code_comment')
|
3
|
+
|
4
|
+
include Reek::Source
|
5
|
+
|
6
|
+
describe CodeComment do
|
7
|
+
context 'comment checks' do
|
8
|
+
it 'rejects no comment' do
|
9
|
+
CodeComment.new('').is_descriptive?.should be_false
|
10
|
+
end
|
11
|
+
it 'rejects an empty comment' do
|
12
|
+
CodeComment.new('#').is_descriptive?.should be_false
|
13
|
+
end
|
14
|
+
it 'rejects a 1-word comment' do
|
15
|
+
CodeComment.new("# fred\n# ").is_descriptive?.should be_false
|
16
|
+
end
|
17
|
+
it 'accepts a 2-word comment' do
|
18
|
+
CodeComment.new('# fred here ').is_descriptive?.should be_true
|
19
|
+
end
|
20
|
+
it 'accepts a multi-word comment' do
|
21
|
+
CodeComment.new("# fred here \n# with \n # biscuits ").is_descriptive?.should be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
+
|
3
|
+
include Reek
|
4
|
+
|
5
|
+
describe Dir do
|
6
|
+
it 'reports correct smells via the Dir matcher' do
|
7
|
+
files = Dir['spec/samples/two_smelly_files/*.rb']
|
8
|
+
files.should reek
|
9
|
+
files.should reek_of(:UncommunicativeVariableName)
|
10
|
+
files.should_not reek_of(:LargeClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'copes with daft file specs' do
|
14
|
+
Dir["spec/samples/two_smelly_files/*/.rb"].should_not reek
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'copes with empty array' do
|
18
|
+
[].should_not reek
|
19
|
+
end
|
20
|
+
end
|
@@ -1,20 +1,19 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek/adapters/source'
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
4
2
|
require 'stringio'
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'source', 'source_code')
|
5
4
|
|
6
|
-
include Reek
|
5
|
+
include Reek::Source
|
7
6
|
|
8
|
-
describe
|
7
|
+
describe SourceCode do
|
9
8
|
context 'when the parser fails' do
|
10
9
|
before :each do
|
11
10
|
@catcher = StringIO.new
|
12
|
-
@old_err_io = (
|
11
|
+
@old_err_io = (SourceCode.err_io = @catcher)
|
13
12
|
parser = mock('parser')
|
14
13
|
@error_message = 'Error message'
|
15
14
|
parser.should_receive(:parse).and_raise(SyntaxError.new(@error_message))
|
16
15
|
@source_name = 'Test source'
|
17
|
-
@src =
|
16
|
+
@src = SourceCode.new('', @source_name, parser)
|
18
17
|
end
|
19
18
|
it 'raises a SyntaxError' do
|
20
19
|
@src.syntax_tree
|
@@ -35,7 +34,7 @@ describe Source do
|
|
35
34
|
@catcher.string.should match(@error_message)
|
36
35
|
end
|
37
36
|
after :each do
|
38
|
-
|
37
|
+
SourceCode.err_io = @old_err_io
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
@@ -0,0 +1,165 @@
|
|
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', 'source', 'tree_dresser')
|
3
|
+
|
4
|
+
include Reek::Source
|
5
|
+
|
6
|
+
describe TreeDresser do
|
7
|
+
before(:each) do
|
8
|
+
@dresser = TreeDresser.new
|
9
|
+
end
|
10
|
+
it 'maps :if to IfNode' do
|
11
|
+
@dresser.extensions_for(:if).should == 'IfNode'
|
12
|
+
end
|
13
|
+
it 'maps :call to CallNode' do
|
14
|
+
@dresser.extensions_for(:call).should == 'CallNode'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe SexpExtensions::DefnNode do
|
19
|
+
context 'with no parameters' do
|
20
|
+
before :each do
|
21
|
+
@node = s(:defn, :hello, s(:args))
|
22
|
+
@node.extend(SexpExtensions::DefnNode)
|
23
|
+
end
|
24
|
+
it 'has no parameters' do
|
25
|
+
@node.parameters.should == s(:args)
|
26
|
+
end
|
27
|
+
it 'has no parameter names' do
|
28
|
+
@node.parameter_names.should == s()
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with 1 parameter' do
|
33
|
+
before :each do
|
34
|
+
@node = s(:defn, :hello, s(:args, :param))
|
35
|
+
@node.extend(SexpExtensions::DefnNode)
|
36
|
+
end
|
37
|
+
it 'has 1 parameter' do
|
38
|
+
@node.parameters.should == s(:args, :param)
|
39
|
+
end
|
40
|
+
it 'has 1 parameter name' do
|
41
|
+
@node.parameter_names.should == s(:param)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with a block' do
|
46
|
+
before :each do
|
47
|
+
@node = s(:defn, :hello, s(:args, :param, :"&blk"))
|
48
|
+
@node.extend(SexpExtensions::DefnNode)
|
49
|
+
end
|
50
|
+
it 'has 1 parameter' do
|
51
|
+
@node.parameters.should == s(:args, :param, :"&blk")
|
52
|
+
end
|
53
|
+
it 'has 1 parameter name' do
|
54
|
+
@node.parameter_names.should == s(:param, :"&blk")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with 1 defaulted parameter' do
|
59
|
+
before :each do
|
60
|
+
@node = s(:defn, :hello, s(:args, :param, s(:block, s(:lasgn, :param, s(:array)))))
|
61
|
+
@node.extend(SexpExtensions::DefnNode)
|
62
|
+
end
|
63
|
+
it 'has 1 parameter' do
|
64
|
+
@node.parameters.should == s(:args, :param)
|
65
|
+
end
|
66
|
+
it 'has 1 parameter name' do
|
67
|
+
@node.parameter_names.should == s(:param)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe SexpExtensions::DefsNode do
|
73
|
+
context 'with no parameters' do
|
74
|
+
before :each do
|
75
|
+
@node = s(:defs, :obj, :hello, s(:args))
|
76
|
+
@node.extend(SexpExtensions::DefsNode)
|
77
|
+
end
|
78
|
+
it 'has no parameters' do
|
79
|
+
@node.parameters.should == s(:args)
|
80
|
+
end
|
81
|
+
it 'has no parameter names' do
|
82
|
+
@node.parameter_names.should == s()
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with 1 parameter' do
|
87
|
+
before :each do
|
88
|
+
@node = s(:defs, :obj, :hello, s(:args, :param))
|
89
|
+
@node.extend(SexpExtensions::DefsNode)
|
90
|
+
end
|
91
|
+
it 'has 1 parameter' do
|
92
|
+
@node.parameters.should == s(:args, :param)
|
93
|
+
end
|
94
|
+
it 'has 1 parameter name' do
|
95
|
+
@node.parameter_names.should == s(:param)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with a block' do
|
100
|
+
before :each do
|
101
|
+
@node = s(:defs, :obj, :hello, s(:args, :param, :"&blk"))
|
102
|
+
@node.extend(SexpExtensions::DefsNode)
|
103
|
+
end
|
104
|
+
it 'has 1 parameter' do
|
105
|
+
@node.parameters.should == s(:args, :param, :"&blk")
|
106
|
+
end
|
107
|
+
it 'has 1 parameter name' do
|
108
|
+
@node.parameter_names.should == s(:param, :"&blk")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with 1 defaulted parameter' do
|
113
|
+
before :each do
|
114
|
+
@node = s(:defs, :obj, :hello, s(:args, :param, s(:block, s(:lasgn, :param, s(:array)))))
|
115
|
+
@node.extend(SexpExtensions::DefsNode)
|
116
|
+
end
|
117
|
+
it 'has 1 parameter' do
|
118
|
+
@node.parameters.should == s(:args, :param)
|
119
|
+
end
|
120
|
+
it 'has 1 parameter name' do
|
121
|
+
@node.parameter_names.should == s(:param)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe SexpExtensions::IterNode do
|
127
|
+
context 'with no parameters' do
|
128
|
+
before :each do
|
129
|
+
@node = s(:iter, s(), nil, s())
|
130
|
+
@node.extend(SexpExtensions::IterNode)
|
131
|
+
end
|
132
|
+
it 'has no parameters' do
|
133
|
+
@node.parameters.should == []
|
134
|
+
end
|
135
|
+
it 'has no parameter names' do
|
136
|
+
@node.parameter_names.should == []
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with 1 parameter' do
|
141
|
+
before :each do
|
142
|
+
@node = s(:iter, s(), s(:lasgn, :param), s())
|
143
|
+
@node.extend(SexpExtensions::IterNode)
|
144
|
+
end
|
145
|
+
it 'has 1 parameter' do
|
146
|
+
@node.parameters.should == s(:lasgn, :param)
|
147
|
+
end
|
148
|
+
it 'has 1 parameter name' do
|
149
|
+
@node.parameter_names.should == s(:param)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'with 2 parameters' do
|
154
|
+
before :each do
|
155
|
+
@node = s(:iter, s(), s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))), s())
|
156
|
+
@node.extend(SexpExtensions::IterNode)
|
157
|
+
end
|
158
|
+
it 'has 1 parameter' do
|
159
|
+
@node.parameters.should == s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y)))
|
160
|
+
end
|
161
|
+
it 'has 1 parameter name' do
|
162
|
+
@node.parameter_names.should == [:x, :y]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|