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,76 @@
|
|
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', 'spec')
|
3
|
+
|
4
|
+
include Reek
|
5
|
+
include Reek::Spec
|
6
|
+
|
7
|
+
describe ShouldReekOf do
|
8
|
+
context 'rdoc demo example' do
|
9
|
+
before :each do
|
10
|
+
@ruby = 'def double_thing() @other.thing.foo + @other.thing.foo end'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'reports duplicate calls to @other.thing' do
|
14
|
+
@ruby.should reek_of(:Duplication, /@other.thing[^\.]/)
|
15
|
+
end
|
16
|
+
it 'reports duplicate calls to @other.thing.foo' do
|
17
|
+
@ruby.should reek_of(:Duplication, /@other.thing.foo/)
|
18
|
+
end
|
19
|
+
it 'does not report any feature envy' do
|
20
|
+
@ruby.should_not reek_of(:FeatureEnvy)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'checking code in a string' do
|
25
|
+
before :each do
|
26
|
+
@clean_code = 'def good() true; end'
|
27
|
+
@smelly_code = 'def x() y = 4; end'
|
28
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, [/x/, /y/])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'matches a smelly String' do
|
32
|
+
@matcher.matches?(@smelly_code).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'doesnt match a fragrant String' do
|
36
|
+
@matcher.matches?(@clean_code).should be_false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'reports the smells when should_not fails' do
|
40
|
+
@matcher.matches?(@smelly_code).should be_true
|
41
|
+
@matcher.failure_message_for_should_not.should match('UncommunicativeVariableName')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'checking code in a Dir' do
|
46
|
+
before :each do
|
47
|
+
@clean_dir = Dir['spec/samples/three_clean_files/*.rb']
|
48
|
+
@smelly_dir = Dir['spec/samples/two_smelly_files/*.rb']
|
49
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, [/Dirty/, /@s/])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'matches a smelly String' do
|
53
|
+
@matcher.matches?(@smelly_dir).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'doesnt match a fragrant String' do
|
57
|
+
@matcher.matches?(@clean_dir).should be_false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'checking code in a File' do
|
62
|
+
before :each do
|
63
|
+
@clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
|
64
|
+
@smelly_file = File.new(Dir['spec/samples/two_smelly_files/*.rb'][0])
|
65
|
+
@matcher = ShouldReekOf.new(:UncommunicativeVariableName, [/Dirty/, /@s/])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'matches a smelly String' do
|
69
|
+
@matcher.matches?(@smelly_file).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'doesnt match a fragrant String' do
|
73
|
+
@matcher.matches?(@clean_file).should be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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', 'spec')
|
3
|
+
|
4
|
+
include Reek
|
5
|
+
include Reek::Spec
|
6
|
+
|
7
|
+
describe ShouldReekOnlyOf do
|
8
|
+
before :each do
|
9
|
+
@expected_smell_class = :NestedIterators
|
10
|
+
@expected_context_name = 'SmellyClass#big_method'
|
11
|
+
@matcher = ShouldReekOnlyOf.new(@expected_smell_class, [/#{@expected_context_name}/])
|
12
|
+
@examiner = mock('examiner', :null_object => true)
|
13
|
+
@examiner.should_receive(:all_active_smells).and_return {smells}
|
14
|
+
@match = @matcher.matches_examiner?(@examiner)
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples_for 'no match' do
|
18
|
+
it 'does not match' do
|
19
|
+
@match.should be_false
|
20
|
+
end
|
21
|
+
context 'when a match was expected' do
|
22
|
+
before :each do
|
23
|
+
@source = 'the_path/to_a/source_file.rb'
|
24
|
+
@examiner.should_receive(:description).and_return(@source)
|
25
|
+
end
|
26
|
+
it 'reports the source' do
|
27
|
+
@matcher.failure_message_for_should.should match(@source)
|
28
|
+
end
|
29
|
+
it 'reports the expected smell class' do
|
30
|
+
@matcher.failure_message_for_should.should match(@expected_smell_class.to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with no smells' do
|
36
|
+
def smells
|
37
|
+
[]
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_behave_like 'no match'
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with 1 non-matching smell' do
|
44
|
+
def smells
|
45
|
+
[SmellWarning.new('ControlCouple', 'context', [1], 'any old message', false)]
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like 'no match'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with 2 non-matching smells' do
|
52
|
+
def smells
|
53
|
+
[
|
54
|
+
SmellWarning.new('ControlCouple', 'context', [1], 'any old message', false),
|
55
|
+
SmellWarning.new('FeatureEnvy', 'context', [1], 'any old message', false)
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
it_should_behave_like 'no match'
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with 1 non-matching and 1 matching smell' do
|
63
|
+
def smells
|
64
|
+
[
|
65
|
+
SmellWarning.new('ControlCouple', 'context', [1], 'any old message', false),
|
66
|
+
SmellWarning.new(@expected_smell_class.to_s, 'context', [1], "message mentioning #{@expected_context_name}", false)
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
70
|
+
it_should_behave_like 'no match'
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with 1 matching smell' do
|
74
|
+
def smells
|
75
|
+
[SmellWarning.new(@expected_smell_class.to_s, nil, [1], "message mentioning #{@expected_context_name}", false)]
|
76
|
+
end
|
77
|
+
it 'matches' do
|
78
|
+
@match.should be_true
|
79
|
+
end
|
80
|
+
it 'reports the expected smell when no match was expected' do
|
81
|
+
@matcher.failure_message_for_should_not.should match(@expected_smell_class.to_s)
|
82
|
+
end
|
83
|
+
it 'reports the source when no match was expected' do
|
84
|
+
source = 'the_path/to_a/source_file.rb'
|
85
|
+
@examiner.should_receive(:description).and_return(source)
|
86
|
+
@matcher.failure_message_for_should_not.should match(source)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'reek/adapters/report'
|
4
|
-
require 'reek/adapters/spec'
|
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', 'spec')
|
5
3
|
|
6
4
|
include Reek
|
7
5
|
include Reek::Spec
|
@@ -22,8 +20,8 @@ describe ShouldReek, 'checking code in a string' do
|
|
22
20
|
end
|
23
21
|
|
24
22
|
it 'reports the smells when should_not fails' do
|
25
|
-
@matcher.matches?(@smelly_code)
|
26
|
-
@matcher.failure_message_for_should_not.should
|
23
|
+
@matcher.matches?(@smelly_code)
|
24
|
+
@matcher.failure_message_for_should_not.should match('Uncommunicative Name')
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
@@ -43,8 +41,8 @@ describe ShouldReek, 'checking code in a Dir' do
|
|
43
41
|
end
|
44
42
|
|
45
43
|
it 'reports the smells when should_not fails' do
|
46
|
-
@matcher.matches?(@smelly_dir)
|
47
|
-
@matcher.failure_message_for_should_not.should
|
44
|
+
@matcher.matches?(@smelly_dir)
|
45
|
+
@matcher.failure_message_for_should_not.should match('Uncommunicative Name')
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
@@ -64,29 +62,7 @@ describe ShouldReek, 'checking code in a File' do
|
|
64
62
|
end
|
65
63
|
|
66
64
|
it 'reports the smells when should_not fails' do
|
67
|
-
@matcher.matches?(@smelly_file)
|
68
|
-
@matcher.failure_message_for_should_not.should
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe ShouldReek, 'report formatting' do
|
73
|
-
before :each do
|
74
|
-
sn_clean = 'def clean() @thing = 4; end'.sniff
|
75
|
-
sn_dirty = 'def dirty() thing.cool + thing.cool; end'.sniff
|
76
|
-
sniffers = SnifferSet.new([sn_clean, sn_dirty], '')
|
77
|
-
@matcher = ShouldReek.new
|
78
|
-
@matcher.matches?(sniffers)
|
79
|
-
@lines = @matcher.failure_message_for_should_not.split("\n").map {|str| str.chomp}
|
80
|
-
@error_message = @lines.shift
|
81
|
-
@smells = @lines.grep(/^ /)
|
82
|
-
@headers = (@lines - @smells)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'mentions every smell in the report' do
|
86
|
-
@smells.should have(2).warnings
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'doesnt mention the clean files' do
|
90
|
-
@headers.should have(1).headers
|
65
|
+
@matcher.matches?(@smelly_file)
|
66
|
+
@matcher.failure_message_for_should_not.should match('Uncommunicative Name')
|
91
67
|
end
|
92
68
|
end
|