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,161 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/class_context'
|
4
|
-
require 'reek/stop_context'
|
5
|
-
require 'reek/smells/feature_envy'
|
6
|
-
|
7
|
-
include Reek
|
8
|
-
include Reek::Smells
|
9
|
-
|
10
|
-
describe ClassContext do
|
11
|
-
it 'should report Long Parameter List' do
|
12
|
-
ruby = 'class Inner; def simple(arga, argb, argc, argd) f(3);true end end'
|
13
|
-
ruby.should reek_of(:LongParameterList, /Inner/, /simple/, /4 parameters/)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should report two different methods' do
|
17
|
-
src = <<EOEX
|
18
|
-
class Fred
|
19
|
-
def simple(arga, argb, argc, argd) f(3);true end
|
20
|
-
def simply(arga, argb, argc, argd) f(3);false end
|
21
|
-
end
|
22
|
-
EOEX
|
23
|
-
|
24
|
-
src.should reek_of(:LongParameterList, /Fred/, /simple/)
|
25
|
-
src.should reek_of(:LongParameterList, /Fred/, /simply/)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should report many different methods' do
|
29
|
-
src = <<EOEX
|
30
|
-
class Fred
|
31
|
-
def textile_bq(tag, atts, cite, content) f(3);end
|
32
|
-
def textile_p(tag, atts, cite, content) f(3);end
|
33
|
-
def textile_fn_(tag, num, atts, cite, content) f(3);end
|
34
|
-
def textile_popup_help(name, windowW, windowH) f(3);end
|
35
|
-
end
|
36
|
-
EOEX
|
37
|
-
|
38
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_bq/)
|
39
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_fn_/)
|
40
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_p/)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Above
|
45
|
-
def above() end
|
46
|
-
def both() end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Below < Above
|
50
|
-
def both() end
|
51
|
-
def below() end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe ClassContext, 'overridden methods' do
|
55
|
-
describe 'of loaded class' do
|
56
|
-
before :each do
|
57
|
-
@ctx = ClassContext.create(StopContext.new, [0, :Below])
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should recognise non-overridden method' do
|
61
|
-
@ctx.is_overriding_method?('below').should == false
|
62
|
-
@ctx.is_overriding_method?('above').should == false
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should recognise overridden method' do
|
66
|
-
@ctx.is_overriding_method?('both').should == true
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should recognise methods in current codebase' do
|
70
|
-
ctx = ClassContext.create(StopContext.new, [0, :FeatureEnvy])
|
71
|
-
ctx.is_overriding_method?('examine_context').should == true
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'of non-loaded class' do
|
76
|
-
before :each do
|
77
|
-
@ctx = ClassContext.create(StopContext.new, [0, :Missing])
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'should recognise non-overridden method' do
|
81
|
-
@ctx.is_overriding_method?('below').should == false
|
82
|
-
@ctx.is_overriding_method?('above').should == false
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'should recognise overridden method' do
|
86
|
-
@ctx.is_overriding_method?('both').should == false
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe 'Integration defect:' do
|
92
|
-
it 'should not report UtilityFunction for FeatureEnvy#examine_context' do
|
93
|
-
kelement = ClassContext.create(StopContext.new, [0, :FeatureEnvy, s(:const, :SmellDetector)])
|
94
|
-
meth = Name.new(:examine_context)
|
95
|
-
kelement.is_overriding_method?(meth).should == true
|
96
|
-
melement = MethodContext.new(kelement, [0, :examine_context])
|
97
|
-
melement.is_overriding_method?(meth).should == true
|
98
|
-
melement.depends_on_instance?.should == true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
module Mod1
|
103
|
-
class Klass1
|
104
|
-
module Mod2
|
105
|
-
class Klass2
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe CodeContext, 'find class' do
|
112
|
-
before :each do
|
113
|
-
@stop = StopContext.new
|
114
|
-
@mod1 = ModuleContext.create(@stop, [0, :Mod1])
|
115
|
-
@klass1 = ClassContext.create(@mod1, [0, :Klass1])
|
116
|
-
@mod2 = ModuleContext.create(@klass1, [0, :Mod2])
|
117
|
-
@klass2 = ClassContext.create(@mod2, [0, :Klass2])
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ModuleContext do
|
121
|
-
it 'should find local name' do
|
122
|
-
@mod1.find_module('Klass1').name.should == 'Mod1::Klass1'
|
123
|
-
@mod2.find_module('Klass2').name.should == 'Mod1::Klass1::Mod2::Klass2'
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'should not find deeper class' do
|
127
|
-
@mod1.find_module('Klass2').should == nil
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should find own Module' do
|
131
|
-
@mod1.myself.name.should == 'Mod1'
|
132
|
-
@mod2.myself.name.should == 'Mod1::Klass1::Mod2'
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe ClassContext do
|
137
|
-
it 'should find local module' do
|
138
|
-
@klass1.find_module('Mod2').name.should == 'Mod1::Klass1::Mod2'
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'should not find deeper module' do
|
142
|
-
@klass1.find_module('Klass2').should == nil
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should find own Class' do
|
146
|
-
@klass1.myself.name.should == 'Mod1::Klass1'
|
147
|
-
@klass2.myself.name.should == 'Mod1::Klass1::Mod2::Klass2'
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe ClassContext do
|
153
|
-
it 'does not report empty class in another module' do
|
154
|
-
'class Treetop::Runtime::SyntaxNode; end'.should_not reek
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'deals with :: scoped names' do
|
158
|
-
element = ClassContext.create(StopContext.new, [:colon2, [:colon2, [:const, :Treetop], :Runtime], :SyntaxNode])
|
159
|
-
element.num_methods.should == 0
|
160
|
-
end
|
161
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/configuration'
|
4
|
-
|
5
|
-
include Reek
|
6
|
-
|
7
|
-
describe SmellConfiguration do
|
8
|
-
it 'returns the default value when key not found' do
|
9
|
-
cf = SmellConfiguration.new({})
|
10
|
-
cf.value('fred', nil, 27).should == 27
|
11
|
-
end
|
12
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/if_context'
|
4
|
-
|
5
|
-
include Reek
|
6
|
-
|
7
|
-
describe IfContext do
|
8
|
-
it 'finds a class within top-level code' do
|
9
|
-
'unless jim; class Array; end; end'.should_not reek
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'finds class within top-level code' do
|
13
|
-
stopctx = StopContext.new
|
14
|
-
ifctx = IfContext.new(stopctx, [:if, [:vcall, :jim]])
|
15
|
-
ifctx.find_module(Name.new(:Array)).should_not be_nil
|
16
|
-
end
|
17
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
require 'reek/module_context'
|
3
|
-
require 'reek/stop_context'
|
4
|
-
|
5
|
-
include Reek
|
6
|
-
|
7
|
-
describe ModuleContext do
|
8
|
-
it 'should report module name for smell in method' do
|
9
|
-
'module Fred; def simple(x) true; end; end'.should reek_of(:UncommunicativeName, /x/, /simple/, /Fred/)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should not report module with empty class' do
|
13
|
-
'module Fred; class Jim; end; end'.should_not reek
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should handle module with empty class' do
|
17
|
-
stop = StopContext.new
|
18
|
-
modctx = ModuleContext.create(stop, [:module, :Fred, []])
|
19
|
-
modctx.find_module(Name.new(:Jim)).should be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe ModuleContext do
|
24
|
-
it 'should recognise global constant' do
|
25
|
-
'module ::Global class Inside; end; end'.should_not reek
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should not find missing global constant' do
|
29
|
-
element = ModuleContext.create(StopContext.new, [:module, [:colon3, :Global], nil])
|
30
|
-
element.myself.should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should find global constant' do
|
34
|
-
module ::GlobalTestModule; end
|
35
|
-
element = ModuleContext.create(StopContext.new, [:module, [:colon3, :GlobalTestModule], nil])
|
36
|
-
element.myself.name.should == 'GlobalTestModule'
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'full_name' do
|
40
|
-
it "reports full context" do
|
41
|
-
element = StopContext.new
|
42
|
-
element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
|
43
|
-
element.full_name.should == 'mod'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/reek/name_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
require 'reek/name'
|
3
|
-
|
4
|
-
include Reek
|
5
|
-
|
6
|
-
describe Name, 'resolving symbols' do
|
7
|
-
it 'finds fq loaded class' do
|
8
|
-
exp = [:class, :"Reek::Smells::LargeClass", nil]
|
9
|
-
ctx = StopContext.new
|
10
|
-
res = Name.resolve(exp[1], ctx)
|
11
|
-
res[1].should == "LargeClass"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Name do
|
16
|
-
it 'compares correctly' do
|
17
|
-
a1 = [Name.new('conts'), Name.new('p1'), Name.new('p2'), Name.new('p3')]
|
18
|
-
a2 = [Name.new('name'), Name.new('windowH'), Name.new('windowW')]
|
19
|
-
(a1 & a2).should == []
|
20
|
-
end
|
21
|
-
|
22
|
-
it do
|
23
|
-
[Name.new(:fred)].should include(Name.new(:fred))
|
24
|
-
end
|
25
|
-
|
26
|
-
it do
|
27
|
-
set = Set.new
|
28
|
-
set << Name.new(:fred)
|
29
|
-
set.should include(Name.new(:fred))
|
30
|
-
end
|
31
|
-
|
32
|
-
it do
|
33
|
-
fred = Name.new(:fred)
|
34
|
-
fred.should eql(fred)
|
35
|
-
fred.should eql(Name.new(:fred))
|
36
|
-
end
|
37
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
include Reek
|
4
|
-
|
5
|
-
describe Dir do
|
6
|
-
it 'reports correct smells via the Dir matcher' do
|
7
|
-
Dir['spec/samples/two_smelly_files/*.rb'].should reek
|
8
|
-
Dir['spec/samples/two_smelly_files/*.rb'].should reek_of(:UncommunicativeName)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'reports correct smells via Dir' do
|
12
|
-
sniffer = Dir['spec/samples/two_smelly_files/*.rb'].sniff
|
13
|
-
sniffer.has_smell?(:UncommunicativeName).should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'copes with daft file specs' do
|
17
|
-
Dir["spec/samples/two_smelly_files/*/.rb"].should_not reek
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'copes with empty array' do
|
21
|
-
[].should_not reek
|
22
|
-
end
|
23
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/module_context'
|
4
|
-
require 'reek/singleton_method_context'
|
5
|
-
require 'reek/stop_context'
|
6
|
-
|
7
|
-
include Reek
|
8
|
-
|
9
|
-
describe SingletonMethodContext do
|
10
|
-
it "reports full context" do
|
11
|
-
element = StopContext.new
|
12
|
-
element = ModuleContext.new(element, Name.new(:mod), s(:module, :mod, nil))
|
13
|
-
element = SingletonMethodContext.new(element, s(:defs, s(:call, nil, :a, s(:arglist)), :b, s(:args)))
|
14
|
-
element.full_name.should match(/mod#a\.b/)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/configuration'
|
4
|
-
require 'reek/smells/duplication'
|
5
|
-
require 'reek/smells/large_class'
|
6
|
-
require 'reek/smells/long_method'
|
7
|
-
|
8
|
-
include Reek
|
9
|
-
include Reek::Smells
|
10
|
-
|
11
|
-
describe SmellDetector, 'configuration' do
|
12
|
-
before:each do
|
13
|
-
@detector = LongMethod.new
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'adopts new max_statements value' do
|
17
|
-
@detector.configure_with(LongMethod::MAX_ALLOWED_STATEMENTS_KEY => 25)
|
18
|
-
@detector.value(LongMethod::MAX_ALLOWED_STATEMENTS_KEY, nil, 0).should == 25
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe SmellDetector, 'configuration' do
|
23
|
-
# it 'stays enabled when not disabled' do
|
24
|
-
# @detector = LargeClass.new
|
25
|
-
# @detector.should be_enabled
|
26
|
-
# @detector.configure({'LargeClass' => {'max_methods' => 50}})
|
27
|
-
# @detector.should be_enabled
|
28
|
-
# end
|
29
|
-
|
30
|
-
it 'becomes disabled when disabled' do
|
31
|
-
@detector = LargeClass.new
|
32
|
-
@detector.should be_enabled
|
33
|
-
@detector.configure({'LargeClass' => {SmellConfiguration::ENABLED_KEY => false}})
|
34
|
-
@detector.should_not be_enabled
|
35
|
-
end
|
36
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
-
|
3
|
-
require 'reek/method_context'
|
4
|
-
require 'reek/smells/uncommunicative_name'
|
5
|
-
|
6
|
-
include Reek
|
7
|
-
include Reek::Smells
|
8
|
-
|
9
|
-
describe UncommunicativeName, "method name" do
|
10
|
-
it 'should not report one-word method name' do
|
11
|
-
'def help(fred) basics(17) end'.should_not reek
|
12
|
-
end
|
13
|
-
it 'should report one-letter method name' do
|
14
|
-
'def x(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/)
|
15
|
-
end
|
16
|
-
it 'should report name of the form "x2"' do
|
17
|
-
'def x2(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/)
|
18
|
-
end
|
19
|
-
it 'should report long name ending in a number' do
|
20
|
-
'def method2(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /method2/)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe UncommunicativeName, "field name" do
|
25
|
-
it 'should not report one-word field name' do
|
26
|
-
'class Thing; def help(fred) @simple end end'.should_not reek
|
27
|
-
end
|
28
|
-
it 'should report one-letter fieldname' do
|
29
|
-
'class Thing; def simple(fred) @x end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
|
30
|
-
end
|
31
|
-
it 'should report name of the form "x2"' do
|
32
|
-
'class Thing; def simple(fred) @x2 end end'.should reek_only_of(:UncommunicativeName, /@x2/, /Thing/, /variable name/)
|
33
|
-
end
|
34
|
-
it 'should report long name ending in a number' do
|
35
|
-
'class Thing; def simple(fred) @field12 end end'.should reek_only_of(:UncommunicativeName, /@field12/, /Thing/, /variable name/)
|
36
|
-
end
|
37
|
-
it 'should report one-letter fieldname in assignment' do
|
38
|
-
'class Thing; def simple(fred) @x = fred end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe UncommunicativeName, "local variable name" do
|
43
|
-
it 'should not report one-word variable name' do
|
44
|
-
'def help(fred) simple = jim(45) end'.should_not reek
|
45
|
-
end
|
46
|
-
it 'should report one-letter variable name' do
|
47
|
-
'def simple(fred) x = jim(45) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
|
48
|
-
end
|
49
|
-
it 'should report name of the form "x2"' do
|
50
|
-
'def simple(fred) x2 = jim(45) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
|
51
|
-
end
|
52
|
-
it 'should report long name ending in a number' do
|
53
|
-
'def simple(fred) var123 = jim(45) end'.should reek_only_of(:UncommunicativeName, /var123/, /variable name/)
|
54
|
-
end
|
55
|
-
it 'should report variable name only once' do
|
56
|
-
'def simple(fred) x = jim(45); x = y end'.should reek_only_of(:UncommunicativeName, /x/)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should report a bad name inside a block' do
|
60
|
-
src = 'def clean(text) text.each { q2 = 3 } end'
|
61
|
-
src.should reek_of(:UncommunicativeName, /q2/)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe UncommunicativeName, "parameter name" do
|
66
|
-
it 'should not recognise *' do
|
67
|
-
'def help(xray, *) basics(17) end'.should_not reek
|
68
|
-
end
|
69
|
-
it "should report parameter's name" do
|
70
|
-
'def help(x) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
|
71
|
-
end
|
72
|
-
it 'should report name of the form "x2"' do
|
73
|
-
'def help(x2) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
|
74
|
-
end
|
75
|
-
it 'should report long name ending in a number' do
|
76
|
-
'def help(param1) basics(17) end'.should reek_only_of(:UncommunicativeName, /param1/, /variable name/)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe UncommunicativeName, "block parameter name" do
|
81
|
-
it "should report parameter's name" do
|
82
|
-
'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeName, /x/, /block/, /variable name/)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should report method name via if context" do
|
86
|
-
src = <<EOS
|
87
|
-
def bad
|
88
|
-
unless @mod then
|
89
|
-
@sig.each { |x| x.to_s }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
EOS
|
93
|
-
|
94
|
-
src.should reek_only_of(:UncommunicativeName, /'x'/)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe UncommunicativeName, "several names" do
|
99
|
-
|
100
|
-
it 'should report all bad names' do
|
101
|
-
ruby = 'class Oof; def y(x) @z = x end end'.sniff
|
102
|
-
ruby.should reek_of(:UncommunicativeName, /'x'/)
|
103
|
-
ruby.should reek_of(:UncommunicativeName, /'y'/)
|
104
|
-
ruby.should reek_of(:UncommunicativeName, /'@z'/)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should report all bad block parameters' do
|
108
|
-
source =<<EOS
|
109
|
-
class Thing
|
110
|
-
def bad(fred)
|
111
|
-
@fred.each {|x| 4 - x }
|
112
|
-
@jim.each {|y| y - 4 }
|
113
|
-
end
|
114
|
-
end
|
115
|
-
EOS
|
116
|
-
|
117
|
-
source.should reek_of(:UncommunicativeName, /'x'/)
|
118
|
-
source.should reek_of(:UncommunicativeName, /'y'/)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe UncommunicativeName do
|
123
|
-
before :each do
|
124
|
-
@detector = UncommunicativeName.new
|
125
|
-
end
|
126
|
-
|
127
|
-
context '#examine' do
|
128
|
-
it 'should return true when reporting a smell' do
|
129
|
-
mc = MethodContext.new(StopContext.new, s(:defn, :x, s(:args)))
|
130
|
-
@detector.examine(mc).should == true
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should return false when not reporting a smell' do
|
134
|
-
mc = MethodContext.new(StopContext.new, s(:defn, :not_bad, s(:args)))
|
135
|
-
@detector.examine(mc).should == false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'accepting names' do
|
140
|
-
it 'accepts Inline::C' do
|
141
|
-
ctx = mock('context')
|
142
|
-
ctx.should_receive(:full_name).and_return('Inline::C')
|
143
|
-
@detector.accept?(ctx).should == true
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|